Elasticsearch can't write to log files

2019-02-01 16:46发布

I would like to activate logs of elasticsearch .

When I run elasticsearch binaries, I realize that I have problems with logging : the configuration cannot be loaded !

Here is the output :

~ $ sudo /usr/share/elasticsearch/bin/elasticsearch
Failed to configure logging...
org.elasticsearch.ElasticsearchException: Failed to load logging configuration
    at org.elasticsearch.common.logging.log4j.LogConfigurator.resolveConfig(LogConfigurator.java:117)
    at org.elasticsearch.common.logging.log4j.LogConfigurator.configure(LogConfigurator.java:81)
    at org.elasticsearch.bootstrap.Bootstrap.setupLogging(Bootstrap.java:94)
    at org.elasticsearch.bootstrap.Bootstrap.main(Bootstrap.java:178)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:32)
Caused by: java.nio.file.NoSuchFileException: /usr/share/elasticsearch/config
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
    at sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
    at sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:144)
    at sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:97)
    at java.nio.file.Files.readAttributes(Files.java:1686)
    at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:109)
    at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:69)
    at java.nio.file.Files.walkFileTree(Files.java:2602)
    at org.elasticsearch.common.logging.log4j.LogConfigurator.resolveConfig(LogConfigurator.java:107)
    ... 4 more
log4j:WARN No appenders could be found for logger (node).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Java HotSpot(TM) Server VM warning: You have loaded library /usr/share/elasticsearch/lib/sigar/libsigar-x86-linux.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.

I am running under linuxmint 17 and using latest ES.

11条回答
欢心
2楼-- · 2019-02-01 17:44

I'm running elasicsearch with the user elasticsearch, so I used this command:

sudo su elasticsearch -c './bin/elasticsearch -d --default.path.conf=/etc/elasticsearch'

from the dir where elasticsearch is installed. Had to do:

sudo chown -R elasticsearch:elasticsearch .

in there though because otherwise it won't have write access to the log files. I don't know how this would work via the debian startup scripts, but this seems to work fine like this.

查看更多
够拽才男人
3楼-- · 2019-02-01 17:45

Your elasticsearch.yml file as well as logging.yml file will be in the /etc/elasticsearch folder.

Create a config folder in your elasticsearch folder in /usr/share and move the .yml files to the config folder

Now run /bin/elasticsearch start and it will work.

查看更多
成全新的幸福
4楼-- · 2019-02-01 17:45

If you need to run it in foreground, but not as service just specify configuration directory explicitly.

$ /usr/share/elasticsearch/bin/elasticsearch -Des.path.conf=/etc/elasticsearch

In this case elasticsearch will be able to find all your config files.

查看更多
Root(大扎)
5楼-- · 2019-02-01 17:48

I got into the same issue and was wondering how they could miss it in the installation script of elastic search. So, after some digging here is what I found:

  1. It looks like you installed elastic search using yum or apt-get or else you would have had the 'config' directory under ES_HOME.

  2. Checking the init.d/elasticsearch shows the following:

    DAEMON_OPTS="-d -p $PID_FILE --default.path.home=$ES_HOME --default.path.logs=$LOG_DIR --default.path.data=$DATA_DIR --default.path.conf=$CONF_DIR"

    :

    # Start Daemon

    start-stop-daemon -d $ES_HOME --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS

  3. So, all the variables are properly initialized and then passed as command line parameters.

  4. So, the best way for you to start is using the service:

    >sudo service elasticsearch start

  5. It will make sure that all the config and log parameters are passed to the main command.

  6. Check logs under /var/log/$NAME that would be '/var/log/elasticsearch`

查看更多
The star\"
6楼-- · 2019-02-01 17:51

If you have installed a .deb and want to start sudo /usr/share/elasticsearch/bin/elasticsearch

You have to do :

cd /usr/share/elasticsearch

sudo ln -s /etc/elasticsearch config
查看更多
登录 后发表回答