1眶掌、單機(jī)安裝
首先創(chuàng)建安裝路徑朴爬,并解壓安裝包到該路徑下:
[root@myhost usr]# mkdir elasticsearch
[root@myhost elasticsearch]# tar -zxvf /soft/elasticsearch-5.0.0.tar.gz
由于elasticsearch不能從root用戶啟動(dòng)召噩,因此首先需要?jiǎng)?chuàng)建一個(gè)用戶用于elasticsearch具滴。
[root@myhost /]# groupadd elk
[root@myhost /]# useradd es -g elk -p elasticsearch
[root@myhost /]# passwd es
然后為該路徑賦予可普通用戶的讀寫權(quán)限:
[root@myhost usr]# chmod -R 777 elasticsearch/
修改config/elasticsearch.yml 用于配置綁定的主機(jī)地址和端口號(hào)构韵,以便其他機(jī)器可以訪問贞绳。
# ---------------------------------- Network -----------------------------------
network.host: 192.168.9.33
http.port: 9200
然后開放端口號(hào)9200:
# firewall-cmd --permanent --zone=public --add-port=9200/tcp
問題解決:
1冈闭、解決“max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]”錯(cuò)誤
修改打開文件/etc/secuity/limits.conf并在文件末尾添加:
es hard nofile 65536
es soft nofile 65536
其中es是用戶名萎攒。
2、解決“max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]”錯(cuò)誤
需要修改系統(tǒng)內(nèi)核參數(shù)刃永,在“/etc/sysctl.conf”文件中追加如下內(nèi)容:
vm.max_map_count=262144
然后執(zhí)行如下命令使內(nèi)核修改馬上生效:
[root@myhost usr]# sysctl -p
vm.max_map_count=262144
然后切換到es用戶下直接啟動(dòng):
[es@myhost bin]$ ./elasticsearch
當(dāng)出現(xiàn)如下內(nèi)容囚玫,代表成功啟動(dòng):
[2016-11-05T15:32:52,063][INFO ][o.e.n.Node? ? ? ? ? ? ? ] [] initializing ...
[2016-11-05T15:32:52,165][INFO ][o.e.e.NodeEnvironment? ? ] [Ss79CYj] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [190.3gb], net total_space [191.7gb], spins? [unknown], types [rootfs]
[2016-11-05T15:32:52,165][INFO ][o.e.e.NodeEnvironment? ? ] [Ss79CYj] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-11-05T15:32:52,167][INFO ][o.e.n.Node? ? ? ? ? ? ? ] [Ss79CYj] node name [Ss79CYj] derived from node ID; set [node.name] to override
[2016-11-05T15:32:52,169][INFO ][o.e.n.Node? ? ? ? ? ? ? ] [Ss79CYj] version[5.0.0], pid[18145], build[253032b/2016-10-26T04:37:51.531Z], OS[Linux/3.10.0-327.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_102/25.102-b14]
[2016-11-05T15:32:53,560][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] loaded module [aggs-matrix-stats]
[2016-11-05T15:32:53,560][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] loaded module [ingest-common]
[2016-11-05T15:32:53,560][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] loaded module [lang-expression]
[2016-11-05T15:32:53,560][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] loaded module [lang-groovy]
[2016-11-05T15:32:53,560][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] loaded module [lang-mustache]
[2016-11-05T15:32:53,560][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] loaded module [lang-painless]
[2016-11-05T15:32:53,561][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] loaded module [percolator]
[2016-11-05T15:32:53,561][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] loaded module [reindex]
[2016-11-05T15:32:53,561][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] loaded module [transport-netty3]
[2016-11-05T15:32:53,561][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] loaded module [transport-netty4]
[2016-11-05T15:32:53,562][INFO ][o.e.p.PluginsService? ? ] [Ss79CYj] no plugins loaded
[2016-11-05T15:32:55,810][INFO ][o.e.n.Node? ? ? ? ? ? ? ] [Ss79CYj] initialized
[2016-11-05T15:32:55,811][INFO ][o.e.n.Node? ? ? ? ? ? ? ] [Ss79CYj] starting ...
[2016-11-05T15:32:56,252][INFO ][o.e.t.TransportService? ] [Ss79CYj] publish_address {192.168.8.33:9300}, bound_addresses {192.168.8.33:9300}
[2016-11-05T15:32:56,258][INFO ][o.e.b.BootstrapCheck? ? ] [Ss79CYj] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2016-11-05T15:32:59,549][INFO ][o.e.c.s.ClusterService? ] [Ss79CYj] new_master {Ss79CYj}{Ss79CYjUSveOkQMYseQn2Q}{rb_l_uyySHK0wNHoF7tYSw}{192.168.8.33}{192.168.8.33:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2016-11-05T15:32:59,621][INFO ][o.e.h.HttpServer? ? ? ? ] [Ss79CYj] publish_address {192.168.8.33:9200}, bound_addresses {192.168.8.33:9200}
[2016-11-05T15:32:59,621][INFO ][o.e.n.Node? ? ? ? ? ? ? ] [Ss79CYj] started
[2016-11-05T15:32:59,658][INFO ][o.e.g.GatewayService? ? ] [Ss79CYj] recovered [0] indices into cluster_state
可以從瀏覽器中訪問:http://hostname:9200/
特別說明:ES5.0版本還不支持plugin安裝束亏。
2碍遍、集群配置
通過如下配置,將可以實(shí)現(xiàn)最基本的集群功能揣炕,集群的性能提升還需要參考性能調(diào)優(yōu)一節(jié)祝沸。
Elasticsearch組成集群時(shí)罩锐,需要的節(jié)點(diǎn)數(shù)應(yīng)該是奇數(shù)涩惑。
首先需要開放每一臺(tái)安裝Elasticsearch節(jié)點(diǎn)的端口號(hào)9300:
# firewall-cmd --permanent --zone=public --add-port=9300/tcp
然后配置每一個(gè)終端節(jié)點(diǎn)的配置文件“/config/elasticsearch.yml”竭恬,如下所示
cluster.name: elkCluster
node.name: node-33
bootstrap.memory_lock: false
discovery.zen.ping.unicast.hosts: ["192.168.9.32", "192.168.9.33","192.168.9.34"]
discovery.zen.minimum_master_nodes: 1
參數(shù)說明:
1痊硕、cluster.name
當(dāng)前es的集群名稱岔绸,es會(huì)自動(dòng)發(fā)現(xiàn)在同一網(wǎng)段下的es盒揉,如果在同一網(wǎng)段下有多個(gè)集群,就可以用這個(gè)屬性來區(qū)分不同的集群刚盈。
2欲侮、node.name
當(dāng)前節(jié)點(diǎn)名稱谴分,默認(rèn)會(huì)隨機(jī)自動(dòng)指定一個(gè)名稱牺蹄,可以修改此名稱作為當(dāng)前節(jié)點(diǎn)的名稱
3沙兰、bootstrap.memory_lock
組建集群時(shí)鼎天,需要將鎖定內(nèi)存功能關(guān)閉斋射。
此參數(shù)設(shè)置為true時(shí)罗岖,用于鎖住內(nèi)存桑包。因?yàn)楫?dāng)jvm開始swapping時(shí)es的效率會(huì)降低哑了,所以要保證它不swap弱左,可以把ES_MIN_MEM和ES_MAX_MEM兩個(gè)環(huán)境變量設(shè)置成同一個(gè)值拆火,并且保證機(jī)器有足夠的內(nèi)存分配給es优妙。
同時(shí)也要允許elasticsearch的進(jìn)程可以鎖住內(nèi)存套硼,linux下可以通過`ulimit -l unlimited`命令胞皱。
4雾鬼、discovery.zen.ping.unicast.hosts
設(shè)置集群中master節(jié)點(diǎn)的初始列表宴树,可以通過這些節(jié)點(diǎn)來自動(dòng)發(fā)現(xiàn)新加入集群的節(jié)點(diǎn)格式為:
discovery.zen.ping.unicast.hosts: ["host1", "host2:port", "host3[portX-portY]"]
5酒贬、discovery.zen.minimum_master_nodes
設(shè)置這個(gè)參數(shù)來保證集群中的節(jié)點(diǎn)可以知道其它N個(gè)有master資格的節(jié)點(diǎn)锭吨。默認(rèn)為1(推薦)零如,對(duì)于大的集群來說考蕾,可以設(shè)置大一點(diǎn)的值(2-4)夺衍,對(duì)于三五臺(tái)節(jié)點(diǎn)的集群喜命,必須設(shè)為1 矛紫。
3颊咬、性能調(diào)優(yōu)
通過配置每一個(gè)終端節(jié)點(diǎn)的配置文件“/config/elasticsearch.yml”喳篇,可以實(shí)現(xiàn)ES環(huán)境的性能提升。
3.1麸澜、路徑配置
1挺尿、path.data
path.data:/path/to/data
設(shè)置索引數(shù)據(jù)的存儲(chǔ)路徑,默認(rèn)是es根目錄下的data文件夾炊邦,可以設(shè)置多個(gè)存儲(chǔ)路徑编矾,用逗號(hào)隔開,例:path.data:/path/to/data1,/path/to/data2
2馁害、path.logs
path.logs:/path/to/logs
設(shè)置日志文件的存儲(chǔ)路徑窄俏,默認(rèn)是es根目錄下的logs文件夾
3、path.conf
path.conf: /path/to/conf
設(shè)置配置文件的存儲(chǔ)路徑碘菜,默認(rèn)是es根目錄下的config文件夾凹蜈。
4、path.work
path.work: /path/to/work
設(shè)置臨時(shí)文件的存儲(chǔ)路徑踪区,默認(rèn)是es根目錄下的work文件夾。
5、path.plugins
path.plugins: /path/to/plugins
設(shè)置插件的存放路徑鹃祖,默認(rèn)是es根目錄下的plugins文件夾
3.2、節(jié)點(diǎn)配置
1养铸、node.master
node.master: true
指定該節(jié)點(diǎn)是否有資格被選舉成為node鳞滨,默認(rèn)是true提岔,es是默認(rèn)集群中的第一臺(tái)機(jī)器為master赛惩,如果這臺(tái)機(jī)掛了就會(huì)重新選舉master季惯。
2、node.data
node.data: true
指定該節(jié)點(diǎn)是否存儲(chǔ)索引數(shù)據(jù),默認(rèn)為true。
3.3、分片配置
1瘩例、index.number_of_shards
index.number_of_shards: 5
設(shè)置默認(rèn)索引分片個(gè)數(shù)某饰,默認(rèn)為5片炬守。
2鳍置、index.number_of_replicas
index.number_of_replicas: 1
設(shè)置默認(rèn)索引副本個(gè)數(shù),默認(rèn)為1個(gè)副本放吩。
3.4莉测、網(wǎng)絡(luò)配置
1、network.bind_host
network.bind_host: 192.168.0.1
設(shè)置綁定的ip地址子姜,可以是ipv4或ipv6的扬舒,默認(rèn)為0.0.0.0衣赶。
2丰榴、network.publish_host
network.publish_host: 192.168.0.1
設(shè)置其它節(jié)點(diǎn)和該節(jié)點(diǎn)交互的ip地址喳资,如果不設(shè)置它會(huì)自動(dòng)判斷,值必須是個(gè)真實(shí)的ip地址休吠。
3赡盘、network.host
network.host: 192.168.0.1
這個(gè)參數(shù)是用來同時(shí)設(shè)置bind_host和publish_host上面兩個(gè)參數(shù)毫目。
4诺核、transport.tcp.port
transport.tcp.port: 9300
設(shè)置節(jié)點(diǎn)間交互的tcp端口夭咬,默認(rèn)是9300膀钠。
5砚嘴、transport.tcp.compress
transport.tcp.compress: true
設(shè)置是否壓縮tcp傳輸時(shí)的數(shù)據(jù),默認(rèn)為false如绸,不壓縮扼脐。
6坞生、http.port
http.port: 9200
設(shè)置對(duì)外服務(wù)的http端口,默認(rèn)為9200摔认。
7逆皮、http.max_content_length
http.max_content_length: 100mb
設(shè)置內(nèi)容的最大容量,默認(rèn)100mb
8参袱、http.enabled
http.enabled: false
是否使用http協(xié)議對(duì)外提供服務(wù)电谣,默認(rèn)為true,開啟抹蚀。
3.5剿牺、網(wǎng)關(guān)配置
1、gateway.type
gateway.type: local
gateway的類型环壤,默認(rèn)為local即為本地文件系統(tǒng)晒来,可以設(shè)置為本地文件系統(tǒng),分布式文件系統(tǒng)郑现,hadoop的HDFS湃崩,和amazon的s3服務(wù)器,其它文件系統(tǒng)的設(shè)置方法下次再詳細(xì)說接箫。
2攒读、gateway.recover_after_nodes
gateway.recover_after_nodes: 1
設(shè)置集群中N個(gè)節(jié)點(diǎn)啟動(dòng)時(shí)進(jìn)行數(shù)據(jù)恢復(fù),默認(rèn)為1辛友。
3整陌、gateway.recover_after_time
gateway.recover_after_time: 5m
設(shè)置初始化數(shù)據(jù)恢復(fù)進(jìn)程的超時(shí)時(shí)間,默認(rèn)是5分鐘。
4泌辫、gateway.expected_nodes
gateway.expected_nodes: 2
設(shè)置這個(gè)集群中節(jié)點(diǎn)的數(shù)量,默認(rèn)為2九默,一旦這N個(gè)節(jié)點(diǎn)啟動(dòng)震放,就會(huì)立即進(jìn)行數(shù)據(jù)恢復(fù)。
3.6驼修、數(shù)據(jù)恢復(fù)配置
1殿遂、cluster.routing.allocation.node_initial_primaries_recoveries
cluster.routing.allocation.node_initial_primaries_recoveries: 4
初始化數(shù)據(jù)恢復(fù)時(shí),并發(fā)恢復(fù)線程的個(gè)數(shù)乙各,默認(rèn)為4墨礁。
2、cluster.routing.allocation.node_concurrent_recoveries
cluster.routing.allocation.node_concurrent_recoveries: 2
添加刪除節(jié)點(diǎn)或負(fù)載均衡時(shí)并發(fā)恢復(fù)線程的個(gè)數(shù)耳峦,默認(rèn)為4恩静。
3、indices.recovery.max_size_per_sec
indices.recovery.max_size_per_sec: 0
設(shè)置數(shù)據(jù)恢復(fù)時(shí)限制的帶寬蹲坷,如入100mb驶乾,默認(rèn)為0,即無限制循签。
4级乐、indices.recovery.concurrent_streams
indices.recovery.concurrent_streams: 5
設(shè)置這個(gè)參數(shù)來限制從其它分片恢復(fù)數(shù)據(jù)時(shí)最大同時(shí)打開并發(fā)流的個(gè)數(shù),默認(rèn)為5县匠。
3.7风科、節(jié)點(diǎn)發(fā)現(xiàn)配置
1、discovery.zen.ping.timeout
discovery.zen.ping.timeout: 3s
設(shè)置集群中自動(dòng)發(fā)現(xiàn)其它節(jié)點(diǎn)時(shí)ping連接超時(shí)時(shí)間乞旦,默認(rèn)為3秒贼穆,對(duì)于比較差的網(wǎng)絡(luò)環(huán)境可以高點(diǎn)的值來防止自動(dòng)發(fā)現(xiàn)時(shí)出錯(cuò)。
2杆查、discovery.zen.ping.multicast.enabled
discovery.zen.ping.multicast.enabled: false
設(shè)置是否打開多播發(fā)現(xiàn)節(jié)點(diǎn)扮惦,默認(rèn)是true。
3.8亲桦、慢查詢配置
下面是一些查詢時(shí)的慢日志參數(shù)設(shè)置:
index.search.slowlog.level: TRACE
index.search.slowlog.threshold.query.warn: 10s
index.search.slowlog.threshold.query.info: 5s
index.search.slowlog.threshold.query.debug: 2s
index.search.slowlog.threshold.query.trace: 500ms
index.search.slowlog.threshold.fetch.warn: 1s
index.search.slowlog.threshold.fetch.info: 800ms
index.search.slowlog.threshold.fetch.debug:500ms
index.search.slowlog.threshold.fetch.trace: 200ms