在CentOS 7下安裝ELK——Elasticsearch

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(推薦),對于大的集群來說,可以設(shè)置大一點(diǎn)的值(2-4),對于三五臺(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è)置對外服務(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é)議對外提供服務(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秒,對于比較差的網(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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容