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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章