docker安装elasticsearch报错AccessDeniedException: /tmp/elasticsearch

按照elasticsearch的官方文档用docker安装7.7.1版本的es,报错
(顺带说以下,如果我把镜像的版本换成最新的7.12.1,不会报错。用7.7.1的就会报错)

[root@webapi4-app-22-151 workspace]# docker run -p 9200:9200 -p 9300:9300 -e “discovery.type=single-node” docker.elastic.co/elasticsearch/elasticsearch:7.7.1
Exception in thread “main” java.nio.file.AccessDeniedException: /tmp/elasticsearch-8523317643108022907
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.createDirectory(UnixFileSystemProvider.java:389)
at java.base/java.nio.file.Files.createDirectory(Files.java:694)
at java.base/java.nio.file.TempFileHelper.create(TempFileHelper.java:135)
at java.base/java.nio.file.TempFileHelper.createTempDirectory(TempFileHelper.java:172)
at java.base/java.nio.file.Files.createTempDirectory(Files.java:1011)
at org.elasticsearch.tools.launchers.Launchers.createTempDirectory(Launchers.java:66)
at org.elasticsearch.tools.launchers.TempDirectory.main(TempDirectory.java:54)

大概搜了下这个问题,别人的报错都是/usr/share/elasticsearch目录,而我的是/tmp目录,不太一样.
我用别人的解决办法:

  • 设置环境变量TAKE_FILE_OWNERSHIP=true
  • 容器内chown -R 1000:0 /usr/share/elasticsearch/{data,logs}
  • 把宿主机的挂载目录权限设置成777

这三种办法不管用,还是报错,所以,使出绝招,进入容器里面排错.
启动一个临时容器,默认执行命令/bin/bash
默认执行命令变成了/bin/bash,而不是docker-entrypoint.sh,容器主进程是/bin/bash所以容器不会遇到错误导致退出

[root@webapi4-app-22-151 workspace]# docker run -itd -e “discovery.type=single-node” docker.elastic.co/elasticsearch/elasticsearch:7.7.1 /bin/bash
5f733625a5808d15c8895cb12ddf94845f5f1b57960edd1d224544cf8da08bab
[root@webapi4-app-22-151 workspace]# docker exec -it 5f7 bash
[root@5f733625a580 elasticsearch]#
#执行es容器的启动脚本,报错
[root@5f733625a580 elasticsearch]# sh /usr/local/bin/docker-entrypoint.sh

就是出现的这个错误,/tmp目录
docker安装elasticsearch报错AccessDeniedException: /tmp/elasticsearch_第1张图片
然后在容器里给/tmp目录授权777,重新执行脚本

[root@5f733625a580 elasticsearch]# chmod 777 /tmp
[root@5f733625a580 elasticsearch]# sh /usr/local/bin/docker-entrypoint.sh

报了新的错误
Error opening log file ‘logs/gc.log’: Permission denied
docker安装elasticsearch报错AccessDeniedException: /tmp/elasticsearch_第2张图片
给容器内的/usr/share/elasticsearch目录设置权限

[root@5f733625a580 elasticsearch]# chown -R 1000:0 /usr/share/elasticsearch/
[root@5f733625a580 elasticsearch]# sh /usr/local/bin/docker-entrypoint.sh

最后elasticsearch服务启动成功

总结: 先配置
chmod 777 /tmp
chown -R 1000:0 /usr/share/elasticsearch/
这两条命令再执行脚本docker-entrypoint.sh

解决问题后,使用docker-compose安装,docker-compose.yml:

version: '2'
services:
  es:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
    container_name: es
    ports:
    - 9200:9200
    environment:
    - discovery.type=single-node
    - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
    - /data/elk/es/data:/usr/share/elasticsearch/data
    command:
    - /bin/bash 
    - -c 
    - |  
        chmod 777 /tmp
        chown -R 1000:0 /usr/share/elasticsearch/
        sh /usr/local/bin/docker-entrypoint.sh

启动成功

[root@webapi4-app-22-151 workspace]# docker-compose up -d
Creating es … done
[root@webapi4-app-22-151 workspace]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
062266bf95cd docker.elastic.co/elasticsearch/elasticsearch:7.7.1 “/tini – /usr/local…” 2 seconds ago Up 2 seconds 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 9300/tcp es
[root@webapi4-app-22-151 workspace]# curl localhost:9200
{
“name” : “062266bf95cd”,
“cluster_name” : “docker-cluster”,
“cluster_uuid” : “ndgcRUCJTb6pNWUeJRCMLw”,
“version” : {
“number” : “7.7.1”,
“build_flavor” : “default”,
“build_type” : “docker”,
“build_hash” : “ad56dce891c901a492bb1ee393f12dfff473a423”,
“build_date” : “2020-05-28T16:30:01.040088Z”,
“build_snapshot” : false,
“lucene_version” : “8.5.1”,
“minimum_wire_compatibility_version” : “6.8.0”,
“minimum_index_compatibility_version” : “6.0.0-beta1”
},
“tagline” : “You Know, for Search”
}

目前暂时解决了这个问题,但是应该有更优的解决方法

你可能感兴趣的:(杂七杂八,docker,elasticsearch,es)