仅在 EC2 Ubuntu 上,docker 的 elasticsearch 不起作用

问题描述 投票:0回答:1

错误日志

{
"@timestamp":"2024-03-19T14:25:08.633Z", 
"log.level":"ERROR", 
"message":"fatal exception while booting Elasticsearch", 
"ecs.version":"1.2.0", 
"service.name":"ES_ECS",
"event.dataset":"elasticsearch.server",
"process.thread.name":"main",
"log.logger":"org.elasticsearch.bootstrap.Elasticsearch",
"elasticsearch.node.name":"ella",
"elasticsearch.cluster.name":"es",
"error.type":"java.lang.IllegalStateException",
"error.message":"failed to obtain node locks, tried [/usr/share/elasticsearch/data]; maybe these locations are not writable or multiple nodes were started on the same data path?",
"error.stack_trace":"java.lang.IllegalStateException: failed to obtain node locks, tried [/usr/share/elasticsearch/data]; maybe these locations are not writable or multiple nodes were started on the same data path?\n\tat [email protected]/org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:296)\n\tat [email protected]/org.elasticsearch.node.NodeConstruction.validateSettings(NodeConstruction.java:484)\n\tat [email protected]/org.elasticsearch.node.NodeConstruction.prepareConstruction(NodeConstruction.java:246)\n\tat [email protected]/org.elasticsearch.node.Node.<init>(Node.java:181)\n\tat [email protected]/org.elasticsearch.bootstrap.Elasticsearch$2.<init>(Elasticsearch.java:236)\n\tat [email protected]/org.elasticsearch.bootstrap.Elasticsearch.initPhase3(Elasticsearch.java:236)\n\tat [email protected]/org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:73)\nCaused by: java.io.IOException: failed to obtain lock on /usr/share/elasticsearch/data\n\tat [email protected]/org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:241)\n\tat [email protected]/org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:209)\n\tat [email protected]/org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:288)\n\t... 6 more\n Caused by: java.nio.file.NoSuchFileException: /usr/share/elasticsearch/data/node.lock\n\tat java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)\n\tat java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)\n\tat java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)\n\tat java.base/sun.nio.fs.UnixPath.toRealPath(UnixPath.java:834)\n\tat [email protected]/org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:94)\n\tat [email protected]/org.apache.lucene.store.FSLockFactory.obtainLock(FSLockFactory.java:43)\n\tat [email protected]/org.apache.lucene.store.BaseDirectory.obtainLock(BaseDirectory.java:44)\n\tat [email protected]/org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:234)\n\t... 8 more\n\t Suppressed: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/node.lock\n\t\tat java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)\n\t\tat java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)\n\t\tat java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)\n\t\tat java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:261)\n\t\tat java.base/java.nio.file.Files.newByteChannel(Files.java:379)\n\t\tat java.base/java.nio.file.Files.createFile(Files.java:657)\n\t\tat [email protected]/org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:84)\n\t\t... 11 more\n"
}

注意

我使用docker compose,在yaml文件下面。

Docker-compose.yml

version: "3.8"

networks:
  netwrk:
    driver: bridge

services:
  elastic:
      container_name: elastic_db
      build: ./elastic
      environment:
        LC_ALL: C.UTF-8
        node.name: ella
        discovery.type: single-node
        cluster.name: es
        ES_JAVA_OPTS: -Xms512m -Xmx512m
        ELASITC_USERNAME: elastic
        ELASTIC_PASSWORD: ${ELASTIC_PASSWORD}
        bootstrap.memory_lock: true
        xpack.security.enabled: false
      ulimits:
        memlock:
          soft: -1
          hard: -1
      volumes:
        - ~/Docker/volume/elastic:/usr/share/elasticsearch/data
      healthcheck:
        test: curl -u elastic:${ELASTIC_PASSWORD} http://localhost:9200/_cluster/health
        interval: 5s
        timeout: 5s
        retries: 30
        start_period: 30s
      expose:
        - 9200
        - 9300
      networks:
        - netwrk
  (and other containers)
  • Docker compose 在我的本地桌面上运行良好。
  • 我在 EC2 ubuntu 上运行命令
    sudo docker compose up --build -d
    ,但调用了错误。

Docker,docker-compose 版本

  • 本地:
    • Docker:25.0.3
    • docker-compose:2.24.6
  • EC2 Ubuntu:
    • Docker:26.0.0
    • docker-compose:2.25.0

PS

卷文件

~/Docker/volume/...
未打开
/home/ubuntu/Docker/volume...
它们是在
/root/Docker/volume/...

创建的

为什么会发生这种情况? (我猜是因为 docker-compose 由 sudo 运行...) 是否有任何解决方案可以在

/home/ubuntu/
(主机的
~
)目录上制作卷文件?

祝 Elastic 运转良好

docker ubuntu elasticsearch amazon-ec2 docker-compose
1个回答
0
投票

sudo chmod -R 777 /root/Docker/
有效。

但是这可能太不安全了。

还有其他解决办法吗?

© www.soinside.com 2019 - 2024. All rights reserved.