当把ElasticSearch部署好之后,然后进入到elasticsearch/bin目录下运行

./elasticsearch

出现了报错信息,

log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: /usr/local/elasticsearch/logs/elasticsearch.log
at java.io.FileOutputStream.open(Native Method)

at java.io.FileOutputStream.<init>(FileOutputStream.java:221)

at java.io.FileOutputStream.<init>(FileOutputStream.java:142)

at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)

at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)

at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:223)

at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)

at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172)

at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104)

at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:842)

at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:768)

at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:648)

at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:514)

at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:440)

at org.elasticsearch.common.logging.log4j.LogConfigurator.configure(LogConfigurator.java:128)

at org.elasticsearch.bootstrap.Bootstrap.setupLogging(Bootstrap.java:204)

at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:258)

at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

一开始以为是目前权限不够,在前面加上sudo 之后运行,还是报错:

Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)

at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)

at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:285)

at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

Refer to the log for complete error details.

后来发现,我原来是在root用户下启动ES,所以不行,这个时候应该将elasticsearch的部署文档的所有者改为一个非root用户,

sudo chown -R hadoop:hadoop elasticsearch-5.5.0
sudo chgrp -R hadoop:hadoop elasticsearch-5.5.0

而且还要切换到hadoop用户下之后,才可以去执行ES的启动文件。

原因说明:由于ElasticSearch可以接收用户的脚本并执行,处于安全性考虑,建议创建一个单独的用户来运行ElasticSearch。当然,可以通过配置来实现root用户启动。

修改bin目录elasticsearch.in.sh文件中追加(不过不建议):

JAVA_OPTS="$JAVA_OPTS -Des.insecure.allow.root=true"