版權聲明:本博客爲學習、筆記之用,以筆記形式記錄學習的知識與感悟。學習過程當中可能參考各類資料,如覺文中表述過度引用,請務必告知,以便迅速處理。若有錯漏,不吝賜教。 https://blog.csdn.net/qq_34021712/article/details/79330028
環境介紹
服務器 |
是否能夠成爲主節點 |
是否爲數據節點 |
192.168.8.101 |
true |
true |
192.168.8.103 |
true |
true |
192.168.8.104 |
true |
true |
搭建過程
前提是安裝java環境,ELK6.2版本須要jdk爲1.8,官方推薦安裝OracleJDK 最好不要安裝OpenJDK.安裝jdk參考:
linux安裝jdk 只須要將安裝包換成1.8的就行。
Elasticsearch安裝
①解壓文件
tar -zxvf elasticsearch-6.2.1.tar.gz
②重命名
mv elasticsearch-6.2.1 /usr/local/elk/elasticsearch
③建立數據存放路徑(應將設置配置爲在Elasticsearch主目錄以外定位數據目錄,以便在不刪除數據的狀況下刪除主目錄!)
mkdir /usr/local/elk/elasticsearch/data
④建立日誌存放路徑(已存在不用建立)
mkdir /usr/local/elk/elasticsearch/logs
⑤創建用戶並受權(es不能用root運行)
-
-
-
-
chown -R es:es /usr/local/elk/elasticsearch
⑥修改elasticsearch配置文件
vim /usr/local/elk/elasticsearch/config/elasticsearch.yml 將配置文件如下內容進行修改:
-
-
-
-
-
-
-
-
-
-
path.data: /usr/local/elk/elasticsearch/data
-
-
path.logs: /usr/local/elk/elasticsearch/logs
-
-
bootstrap.memory_lock: true
-
-
-
-
-
-
-
-
-
-
-
discovery.zen.ping.unicast.hosts: [
"192.168.8.101:9300", "192.168.8.103:9300", "192.168.8.104:9300"]
-
-
discovery.zen.minimum_master_nodes:
3
修改完以後使用命令查看具體修改了哪些值
grep '^[a-z]' /usr/local/elk/elasticsearch/config/elasticsearch.yml
⑦調整jvm內存
-
vim /usr/local/elk/elasticsearch/config/jvm.options
-
-
-
分別啓動三臺Elasticsearch
注意:請使用es用戶啓動 su - es
/usr/local/elk/elasticsearch/bin/elasticsearch -d
使用ps -ef|grep elasticsearc查看進程是否啓動,發現並無啓動,什麼緣由呢?查看一下日誌在咱們配置的日誌路徑下:
第一個坑:日誌文件會以集羣名稱命名,查看es6.2.log文件,日誌報如下異常:
-
[
2018-02-14T23:40:16,908][ERROR][o.e.b.Bootstrap ] [node-1] node validation exception
-
[
3] bootstrap checks failed
-
[
1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
-
[
2]: memory locking requested for elasticsearch process but memory is not locked
-
[
3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
-
[
2018-02-14T23:40:16,910][INFO ][o.e.n.Node ] [node-1] stopping ...
-
[
2018-02-14T23:40:17,016][INFO ][o.e.n.Node ] [node-1] stopped
-
[
2018-02-14T23:40:17,016][INFO ][o.e.n.Node ] [node-1] closing ...
-
[
2018-02-14T23:40:17,032][INFO ][o.e.n.Node ] [node-1] closed
解決方法:
切回root用戶su - root,修改配置
① vim /etc/security/limits.conf
使用ps -ef|grep elasticsearch進程查看命令已啓動,使用netstat -ntlp查看9200端口也被佔用了。
可是咱們發現,3個節點都正常started了,可是就是沒法造成集羣,使用Elasticsearch Head插件缺發現沒有鏈接上集羣,
Head插件安裝參考:
Elasticsearch-head插件安裝
第二個坑:查看日誌報如下錯誤:
-
[
2018-02-15T21:15:06,352][INFO ][rest.suppressed ] /_cat/health Params: {h=node.total}
-
MasterNotDiscoveredException[waited
for [30s]]
-
at org.elasticsearch.action.support.master.TransportMasterNodeAction$
4.onTimeout(TransportMasterNodeAction.java:160)
-
at org.elasticsearch.cluster.ClusterStateObserver$ObserverClusterStateListener.onTimeout(ClusterStateObserver.java:
239)
-
at org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(InternalClusterService.java:
630)
-
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:
1142)
-
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:
617)
-
at java.lang.Thread.run(Thread.java:
745)
緣由:將discovery.zen.minimum_master_nodes的值設置爲了3,總共3個節點,都充當主節點是不行的,將discovery.zen.minimum_master_nodes將這個配置改成2。
關於discovery.zen.minimum_master_nodes參數介紹,參考:
再次啓動
第三個坑:使用Head插件查看,發現只有192.168.8.101爲主節點,其餘兩個節點並無鏈接上來,查看日誌發現報如下異常
[2018-02-15T21:53:58,084][INFO ][o.e.d.z.ZenDiscovery ] [node-3] failed to send join request to master [{node-1}{SVrW6URqRsi3SShc1PBJkQ}{y2eFQNQ_TRenpAPyv-EnVg}{192.168.8.101}{192.168.8.101:9300}], reason [RemoteTransportException[[node-1][192.168.8.101:9300][internal:discovery/zen/join]]; nested: IllegalArgumentException[can't add node {node-3}{SVrW6URqRsi3SShc1PBJkQ}{uqoktM6XTgOnhh5r27L5Xg}{192.168.8.104}{192.168.8.104:9300}, found existing node {node-1}{SVrW6URqRsi3SShc1PBJkQ}{y2eFQNQ_TRenpAPyv-EnVg}{192.168.8.101}{192.168.8.101:9300} with the same id but is a different node instance]; ]
緣由:多是以前啓動的時候報錯,並無啓動成功,可是data文件中生成了其餘節點的數據。將三個節點的data目錄清空
再次從新啓動,成功!