docker搭建ElasticSearch集群(目录映射报错可能是setenforce开启了)

参考了这篇文章  https://blog.csdn.net/belonghuang157405/article/details/83301937

 

我个人使用的版本是 docker.io/elasticsearch:6.8.8

 

docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -v /home/soft/ES/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /home/soft/ES/config/jvm.options:/usr/share/elasticsearch/config/jvm.options  -v /home/soft/ES/config/log4j2.properties:/usr/share/elasticsearch/config/log4j2.properties -v /home/soft/ES/data1:/usr/share/elasticsearch/data --name ES01 docker.io/elasticsearch:6.8.8
 
 docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301 -v /home/soft/ES/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /home/soft/ES/config/jvm.options:/usr/share/elasticsearch/config/jvm.options  -v /home/soft/ES/config/log4j2.properties:/usr/share/elasticsearch/config/log4j2.properties -v /home/soft/ES/data2:/usr/share/elasticsearch/data --name ES02 docker.io/elasticsearch:6.8.8

 docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9202:9202 -p 9302:9302 -v /home/soft/ES/config/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /home/soft/ES/config/jvm.options:/usr/share/elasticsearch/config/jvm.options  -v /home/soft/ES/config/log4j2.properties:/usr/share/elasticsearch/config/log4j2.properties -v /home/soft/ES/data3:/usr/share/elasticsearch/data --name ES03 docker.io/elasticsearch:6.8.8

容器报错1:

OpenJDK 64-Bit Server VM warning: UseAVX=2 is not supported on this CPU, setting it to UseAVX=1
2020-04-28 08:23:02,985 main ERROR No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
Exception in thread "main" SettingsException[Failed to load settings from /usr/share/elasticsearch/config/elasticsearch.yml]; nested: AccessDeniedException[/usr/share/elasticsearch/config/elasticsearch.yml];
    at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:102)
    at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:95)
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
    at org.elasticsearch.cli.Command.main(Command.java:90)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93)
Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/config/elasticsearch.yml
    at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
    at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219)
    at java.base/java.nio.file.Files.newByteChannel(Files.java:375)
    at java.base/java.nio.file.Files.newByteChannel(Files.java:426)
    at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
    at java.base/java.nio.file.Files.newInputStream(Files.java:160)
    at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1112)
    at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:100)
    ... 6 more

解决方法:在config目录下创建jvm.options和log4j2.properties两个文件,这两个文件可以先启动一个ES容器(不要指定目录映射,可以正常启动),从里面拷贝。注意修改UseAVX=2 至 UseAVX=1

所有容器启动命令中加入   -v /home/soft/ES/config/jvm.options:/usr/share/elasticsearch/config/jvm.options  -v /home/soft/ES/config/log4j2.properties:/usr/share/elasticsearch/config/log4j2.properties

 

容器报错2:

Exception in thread "main" java.nio.file.AccessDeniedException: /usr/share/elasticsearch/config/jvm.options
    at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
    at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219)
    at java.base/java.nio.file.Files.newByteChannel(Files.java:375)
    at java.base/java.nio.file.Files.newByteChannel(Files.java:426)
    at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
    at java.base/java.nio.file.Files.newInputStream(Files.java:160)
    at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:60)

 

开始崩溃,换非root账号,改各种目录权限,就是死活不行。耽误至少3-4个小时,都准备放弃映射目录了。

 

最后经运维同事提醒,是不是 setenforce 没有关闭。

执行 setenforce 0  ,整个世界都美丽了。

你可能感兴趣的:(ES)