elastic search 日誌不打印問題(root用戶惹的禍)

案發現場

之前測試同學啓動es,用了root 沒起來報錯如下,

java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:350) [elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) [elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) [elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) [elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) [elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.cli.Command.main(Command.java:88) [elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) [elasticsearch-5.4.1.jar:5.4.1]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) [elasticsearch-5.4.1.jar:5.4.1]

後來日誌一直沒有打印,排查問題成了問題。
通過觀察發現如下
在這裏插入圖片描述
在這裏插入圖片描述

elasticsearch不能以root運行

當我們在使用elasticsearch的時候,如果是以root權限來執行elasticsearch

這是出於系統安全考慮設置的條件。由於ElasticSearch可以接收用戶輸入的腳本並且執行,爲了系統安全考慮,
建議創建一個單獨的用戶用來運行ElasticSearch

創建elsearch用戶組及elsearch用戶
group add elsearch
user add elsearch -g elsearch -p elasticsearch

更改elasticsearch文件夾及內部文件的所屬用戶及組爲elsearch:elsearch

chown -R elsearch:elsearch  elasticsearch

elasticsearch爲你elasticsearch的目錄名稱

改後重新用elsearch用戶啓動

在這裏插入圖片描述

[elastic@bin]$ sh elasticsearch
[2020-05-19T20:00:01,716][INFO ][o.e.n.Node               ] [node-8] initializing ...
[2020-05-19T20:00:02,323][INFO ][o.e.e.NodeEnvironment    ] [node-8] using [1] data paths, mounts [[/data (/dev/vdb1)]], net usable_space [128.4gb], net total_space [196.7gb], spins? [possibly], types [ext4]
[2020-05-19T20:00:02,324][INFO ][o.e.e.NodeEnvironment    ] [node-8] heap size [1.9gb], compressed ordinary object pointers [true]
[2020-05-19T20:00:02,472][INFO ][o.e.n.Node               ] [node-8] node name [node-8], node ID [Oy0B1GOwT8CoPLQOq8JrBQ]
[2020-05-19T20:00:02,473][INFO ][o.e.n.Node               ] [node-8] version[5.4.1], pid[10493], build[2cfe0df/2017-05-29T16:05:51.443Z], OS[Linux/2.6.32-642.el6.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_45/25.45-b02]
[2020-05-19T20:00:02,473][INFO ][o.e.n.Node               ] [node-8] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+DisableExplicitGC, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/data/local/elasticsearch-5.4.1]
[2020-05-19T20:00:03,841][INFO ][o.e.p.PluginsService     ] [node-8] loaded module [aggs-matrix-stats]
[2020-05-19T20:00:03,841][INFO ][o.e.p.PluginsService     ] [node-8] loaded module [ingest-common]
[2020-05-19T20:00:03,841][INFO ][o.e.p.PluginsService     ] [node-8] loaded module [lang-expression]
[2020-05-19T20:00:03,842][INFO ][o.e.p.PluginsService     ] [node-8] loaded module [lang-groovy]
[2020-05-19T20:00:03,842][INFO ][o.e.p.PluginsService     ] [node-8] loaded module [lang-mustache]
[2020-05-19T20:00:03,842][INFO ][o.e.p.PluginsService     ] [node-8] loaded module [lang-painless]
[2020-05-19T20:00:03,846][INFO ][o.e.p.PluginsService     ] [node-8] loaded module [percolator]
[2020-05-19T20:00:03,846][INFO ][o.e.p.PluginsService     ] [node-8] loaded module [reindex]
[2020-05-19T20:00:03,846][INFO ][o.e.p.PluginsService     ] [node-8] loaded module [transport-netty3]
[2020-05-19T20:00:03,846][INFO ][o.e.p.PluginsService     ] [node-8] loaded module [transport-netty4]
[2020-05-19T20:00:03,847][INFO ][o.e.p.PluginsService     ] [node-8] loaded plugin [analysis-ik]
[2020-05-19T20:00:03,847][INFO ][o.e.p.PluginsService     ] [node-8] loaded plugin [analysis-pinyin]
[2020-05-19T20:00:06,351][INFO ][o.e.d.DiscoveryModule    ] [node-8] using discovery type [zen]
[2020-05-19T20:00:07,537][INFO ][o.e.n.Node               ] [node-8] initialized
[2020-05-19T20:00:07,537][INFO ][o.e.n.Node               ] [node-8] starting ...
[2020-05-19T20:00:07,739][INFO ][o.e.t.TransportService   ] [node-8] publish_address {10.20.30.40:9300}, bound_addresses {10.20.30.40:9300}
[2020-05-19T20:00:07,747][INFO ][o.e.b.BootstrapChecks    ] [node-8] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2020-05-19T20:00:10,840][INFO ][o.e.c.s.ClusterService   ] [node-8] new_master {node-8}{Oy0B1GOwT8CoPLQOq8JrBQ}{R3UnviE0TVOTkXcq2TKRmw}{10.20.30.40}{10.20.30.40:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2020-05-19T20:00:10,865][INFO ][o.e.h.n.Netty4HttpServerTransport] [node-8] publish_address {10.20.30.40:9200}, bound_addresses {10.20.30.40:9200}
[2020-05-19T20:00:10,874][INFO ][o.e.n.Node               ] [node-8] started
[2020-05-19T20:00:10,972][INFO ][o.w.a.d.Monitor          ] try load config from /data/local/elasticsearch-5.4.1/config/analysis-ik/IKAnalyzer.cfg.xml
[2020-05-19T20:00:10,973][INFO ][o.w.a.d.Monitor          ] try load config from /data/local/elasticsearch-5.4.1/plugins/ik/config/IKAnalyzer.cfg.xml
[2020-05-19T20:00:11,668][INFO ][o.e.m.j.JvmGcMonitorService] [node-8] [gc][4] overhead, spent [440ms] collecting in the last [1s]
[2020-05-19T20:00:11,725][INFO ][o.w.a.d.Monitor          ] [Dict Loading] custom/mydict.dic
[2020-05-19T20:00:11,726][INFO ][o.w.a.d.Monitor          ] [Dict Loading] custom/single_word_low_freq.dic
[2020-05-19T20:00:11,729][INFO ][o.w.a.d.Monitor          ] [Dict Loading] custom/ext_stopword.dic
[2020-05-19T20:00:21,659][INFO ][o.e.g.GatewayService     ] [node-8] recovered [30] indices into cluster_state

之後如果再啓動的話(如果是以root權限登錄服務器),只需要執行切換賬戶,然後運行elasticsearch就可以了

su elsearch #切換賬戶
cd elasticsearch/bin #進入你的elasticsearch目錄下的bin目錄
sh elasticsearch

查看後臺命令是否啓動成功

ps -ef |grep elasticsearch
/usr/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/data/local/elasticsearch-5.4.1 -cp /data/local/elasticsearch-5.4.1/lib/* org.elasticsearch.bootstrap.Elasticsearch
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章