1. 程式人生 > >在啟動ElasticSearch的時候出現報錯資訊Permission denied

在啟動ElasticSearch的時候出現報錯資訊Permission denied

當把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"

參考:https://www.cnblogs.com/krockey/p/5850141.html