1. 程式人生 > 其它 >ElasticSearch 安裝報錯整理

ElasticSearch 安裝報錯整理

ElasticSearch 安裝報錯整理

單機安裝報錯

初次啟動服務

/opt/elasticsearch-5.5.2/bin/elasticsearch

當使用root賬戶呼叫啟動命令出現錯誤資訊,錯誤提示資訊如下:

[2017-08-30T13:32:17,003][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [ELK-node1] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:127) ~[elasticsearch-5.5.2.jar:5.5.2]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.2.jar:5.5.2]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.2.jar:5.5.2]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.2.jar:5.5.2]
	at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.2.jar:5.5.2]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.2.jar:5.5.2]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.2.jar:5.5.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.5.2.jar:5.5.2]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.5.2.jar:5.5.2]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.2.jar:5.5.2]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.2.jar:5.5.2]
	... 6 more

建立新使用者

由於Elasticsearch可以接收使用者輸入的指令碼並且執行,為了系統安全考慮,不允許root賬號啟動,所以建議給Elasticsearch單獨建立一個使用者來執行Elasticsearch

命令格式 useradd ymq(使用者名稱) -g ymq(所屬組名) -p ymq(密碼)

groupadd ymq
useradd  ymq -g ymq -p ymq

授權訪問組許可權

命令格式: chown -R ymq(所屬使用者) : ymq(所屬使用者組名) /opt/elasticsearch-5.5.2 (要更改的檔案路徑)

chown -R ymq:ymq /opt/elasticsearch-5.5.2
chmod -R 777 /opt/elasticsearch-5.5.2

授權 root 許可權

命令格式: ymq 使用者 root 許可權 ` NOPASSWD `意思是 不用輸密碼

chmod 777 /etc/sudoers
vi /etc/sudoers
root    ALL=(ALL)       ALL

#新增ymq 使用者 root 許可權
ymq     ALL=(ALL)       NOPASSWD:ALL 
pkexec chmod 0440 /etc/sudoers

su ymq
/opt/elasticsearch-5.5.2/bin/elasticsearch

如果報如下錯誤

[2017-08-30T13:41:13,631][INFO ][o.e.n.Node               ] [ELK-node1] starting ...
[2017-08-30T13:41:14,093][INFO ][o.e.t.TransportService   ] [ELK-node1] publish_address {192.168.252.121:9300}, bound_addresses {[::]:9300}
[2017-08-30T13:41:14,121][INFO ][o.e.b.BootstrapChecks    ] [ELK-node1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2017-08-30T13:41:14,127][ERROR][o.e.b.Bootstrap          ] [ELK-node1] node validation exception
[2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2017-08-30T13:41:14,142][INFO ][o.e.n.Node               ] [ELK-node1] stopping ...
[2017-08-30T13:41:14,186][INFO ][o.e.n.Node               ] [ELK-node1] stopped
[2017-08-30T13:41:14,186][INFO ][o.e.n.Node               ] [ELK-node1] closing ...
[2017-08-30T13:41:14,204][INFO ][o.e.n.Node               ] [ELK-node1] closed

以下錯誤都切換到 root 使用者進項修改

su root

錯誤

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536

編輯 limits.conf 在第一行加上如下內容

cat /etc/security/limits.conf 

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

錯誤

[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

編輯 limits.conf 在第一行加上如下內容

cat /etc/sysctl.conf 

vm.max_map_count = 655360

執行 sysctl -p

sysctl -p

刪除data目錄下的資料(如果是新解壓的安裝包就不必了)

異常 IllegalStateException

Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[/opt/elasticsearch-5.5.2/data/ymq]] with lock id [0]; maybe thes

刪除 安裝目錄下/data

cd /opt/elasticsearch-5.5.2/data
rm -rf nodes

異常 RemoteTransportException

[2017-09-01T11:40:42,115][INFO ][o.e.d.z.ZenDiscovery     ] [ELK-node2] failed to send join request to master [{ELK-node1}{DKCwxkubTFufsBaOSXj9Nw}{UIMSNeuIT6m8SFGGTi4wSg}{192.168.252.121}{192.168.252.121:9300}], reason [RemoteTransportException[[ELK-node1][192.168.252.121:9300][internal:discovery/zen/join]]; nested: NotMasterException[Node [{ELK-node1}{DKCwxkubTFufsBaOSXj9Nw}{UIMSNeuIT6m8SFGGTi4wSg}{192.168.252.121}{192.168.252.121:9300}] not master for join request]; ], tried [3] times

刪除 個叢集安裝目錄下/data

cd /opt/elasticsearch-5.5.2/data
rm -rf nodes

異常 ElasticsearchUncaughtExceptionHandler

上次啟動失敗,佔用了埠

[2017-08-30T22:02:14,463][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [ELK-node2] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: BindHttpException[Failed to bind to [9200]]; nested: BindException[Address already in use];
jps 

2824 Elasticsearch
3165 Jps
kill -9 2824

再次啟動服務

切到 ymq 使用者嘗試啟動服務 加 -d 後臺啟動

su ymq
/opt/elasticsearch-5.5.2/bin/elasticsearch  -d

jvm 記憶體記憶體修改

vi /opt/elasticsearch-5.5.2/config/jvm.options

-Xms2g  --》修改為512m
-Xmx2g  --》修改為512m

檢視日誌

ymq 及時叢集名稱

less /opt/elasticsearch-5.5.2/logs/ymq.log

檢視埠

netstat -nltp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::9200                 :::*                    LISTEN      2944/java           
tcp6       0      0 :::9300                 :::*                    LISTEN      2944/java           
tcp6       0      0 :::22                   :::*                    LISTEN      -                   
tcp6       0      0 ::1:25                  :::*                    LISTEN      - 

測試訪問

curl -X GET http://localhost:9200/
{
  "name" : "ELK-node1",
  "cluster_name" : "ymq",
  "cluster_uuid" : "jxWzvSFNTCWtToD6wrVIpA",
  "version" : {
    "number" : "5.5.2",
    "build_hash" : "b2f0c09",
    "build_date" : "2017-08-14T12:33:14.154Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"

瀏覽器如果訪問不成功,關閉防火牆,開放指定端9200,9300埠,為了方便,生產不要禁用防火牆

systemctl stop firewalld.service

更多異常:請參考

Elasticsearch 複製叢集配置

不推薦按照以下步驟,可以按照上面介紹的單機配置依次安裝

node1 ROOT 使用者下操作

su root

把本機配置的檔案複製到 node2,node3叢集

for a in {2..3} ; do scp -r /opt/elasticsearch-5.5.2/ node$a:/opt/elasticsearch-5.5.2/ ; done

ssh 登入 node2,node3叢集,建立新使用者,授權訪問組許可權,並且授權訪問/etc/sudoers 給root許可權

for a in {2..3} ; do ssh node$a "source /etc/profile; groupadd ymq; useradd ymq -g ymq -p ymq; chown -R ymq:ymq /opt/elasticsearch-5.5.2; chmod 777 /etc/sudoers;" ; done
for a in {2..3} ; do scp -r /etc/sudoers node$a:/etc/sudoers ; done

複製 limits.confnode2,node3叢集

for a in {2..3} ; do scp -r /etc/security/limits.conf node$a:/etc/security/limits.conf ; done

複製 sysctl.confnode2,node3叢集

for a in {2..3} ; do scp -r /etc/sysctl.conf  node$a:/etc/sysctl.conf ; done

複製 jvm.optionsnode2,node3叢集

for a in {2..3} ; do scp -r /opt/elasticsearch-5.5.2/config/jvm.options  node$a:/opt/elasticsearch-5.5.2/config/jvm.options ; done

執行 sysctl -p操作

for a in {2..3} ; do ssh node$a "source /etc/profile; sysctl -p ; " ; done
vi /opt/elasticsearch-5.5.2/config/elasticsearch.yml

node.name: 換個名字,可以ELK-node2,ELK-node3

node.name: ELK-node1

後臺啟動

後臺啟動node1,node2,node3 服務

su ymq
/opt/elasticsearch-5.5.2/bin/elasticsearch -d

檢視node1,node2,node3埠使用情況

 netstat -nltp

Contact

  • 作者:鵬磊
  • 出處:http://www.ymq.io
  • Email:[email protected]
  • 版權歸作者所有,轉載請註明出處
  • Wechat:關注公眾號,搜雲庫,專注於開發技術的研究與知識分享