root 用户启动elasticsearch 报如下错误
[[email protected] elasticsearch-5.6.1]# bin/elasticsearch
[2019-10-20T09:42:09,918][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-121] 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:136) ~[elasticsearch-5.6.1.jar:5.6.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) ~[elasticsearch-5.6.1.jar:5.6.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.6.1.jar:5.6.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) ~[elasticsearch-5.6.1.jar:5.6.1]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-5.6.1.jar:5.6.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.6.1.jar:5.6.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.6.1.jar:5.6.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.6.1.jar:5.6.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:195) ~[elasticsearch-5.6.1.jar:5.6.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) ~[elasticsearch-5.6.1.jar:5.6.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) ~[elasticsearch-5.6.1.jar:5.6.1]
... 6 more
原因:elasticsearch自5版本之后,处于安全考虑,不允许使用root用户运行。
解决:创建一个普通用户,将elasticsearch 安装目录权限修改一下,切换至普通用户运行elasticsearch就可以了
[[email protected] elasticsearch-5.6.1]# useradd elk
[[email protected] elasticsearch-5.6.1]# chown -R elasticsearch-5.6.1.elk /opt/module/elasticsearch-5.6.1/
[[email protected] elasticsearch-5.6.1]# su - elk
[[email protected] elasticsearch-5.6.1]$ ./bin/elasticsearch
[2019-10-20T10:42:53,955][INFO ][o.e.n.Node ] [node-121] initializing ...
[2019-10-20T10:42:54,044][INFO ][o.e.e.NodeEnvironment ] [node-121] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [30.7gb], net total_space [37.4gb], spins? [unknown], types [rootfs]
[2019-10-20T10:42:54,044][INFO ][o.e.e.NodeEnvironment ] [node-121] heap size [1.9gb], compressed ordinary object pointers [true]
[2019-10-20T10:42:54,046][INFO ][o.e.n.Node ] [node-121] node name [node-121], node ID [LVBIbWgzT_KFivApkBq2Ig]
[2019-10-20T10:42:54,046][INFO ][o.e.n.Node ] [node-121] version[5.6.1], pid[2774], build[667b497/2017-09-14T19:22:05.189Z], OS[Linux/3.10.0-327.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_144/25.144-b01]
[2019-10-20T10:42:54,046][INFO ][o.e.n.Node ] [node-121] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -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=/opt/module/elasticsearch-5.6.1]
[2019-10-20T10:42:54,788][INFO ][o.e.p.PluginsService ] [node-121] loaded module [aggs-matrix-stats]
[2019-10-20T10:42:54,788][INFO ][o.e.p.PluginsService ] [node-121] loaded module [ingest-common]
[2019-10-20T10:42:54,788][INFO ][o.e.p.PluginsService ] [node-121] loaded module [lang-expression]
[2019-10-20T10:42:54,788][INFO ][o.e.p.PluginsService ] [node-121] loaded module [lang-groovy]
[2019-10-20T10:42:54,788][INFO ][o.e.p.PluginsService ] [node-121] loaded module [lang-mustache]
[2019-10-20T10:42:54,788][INFO ][o.e.p.PluginsService ] [node-121] loaded module [lang-painless]
[2019-10-20T10:42:54,789][INFO ][o.e.p.PluginsService ] [node-121] loaded module [parent-join]
[2019-10-20T10:42:54,789][INFO ][o.e.p.PluginsService ] [node-121] loaded module [percolator]
[2019-10-20T10:42:54,789][INFO ][o.e.p.PluginsService ] [node-121] loaded module [reindex]
[2019-10-20T10:42:54,789][INFO ][o.e.p.PluginsService ] [node-121] loaded module [transport-netty3]
[2019-10-20T10:42:54,789][INFO ][o.e.p.PluginsService ] [node-121] loaded module [transport-netty4]
[2019-10-20T10:42:54,789][INFO ][o.e.p.PluginsService ] [node-121] no plugins loaded
[2019-10-20T10:42:56,262][INFO ][o.e.d.DiscoveryModule ] [node-121] using discovery type [zen]
[2019-10-20T10:42:56,585][INFO ][o.e.n.Node ] [node-121] initialized
[2019-10-20T10:42:56,585][INFO ][o.e.n.Node ] [node-121] starting ...
[2019-10-20T10:42:56,682][INFO ][o.e.t.TransportService ] [node-121] publish_address {192.168.1.121:9300}, bound_addresses {192.168.1.121:9300}
[2019-10-20T10:42:56,687][INFO ][o.e.b.BootstrapChecks ] [node-121] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2019-10-20T10:42:59,716][INFO ][o.e.c.s.ClusterService ] [node-121] new_master {node-121}{LVBIbWgzT_KFivApkBq2Ig}{I73rNrZPRR6ZrptqL33y3Q}{192.168.1.121}{192.168.1.121:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2019-10-20T10:42:59,737][INFO ][o.e.h.n.Netty4HttpServerTransport] [node-121] publish_address {192.168.1.121:9200}, bound_addresses {192.168.1.121:9200}
[2019-10-20T10:42:59,737][INFO ][o.e.n.Node ] [node-121] started
[2019-10-20T10:42:59,739][INFO ][o.e.g.GatewayService ] [node-121] recovered [0] indices into cluster_state
最后检测是否正常启动: