failed to obtain node locks, tried with lock id [0]; maybe these locations are not writable or multi

Posted 衣舞晨风

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了failed to obtain node locks, tried with lock id [0]; maybe these locations are not writable or multi相关的知识,希望对你有一定的参考价值。

具体错误信息

{"log":"{\\"type\\": \\"server\\", \\"timestamp\\": \\"2021-08-24T05:23:00,545Z\\", \\"level\\": \\"ERROR\\", \\"component\\": \\"o.e.b.ElasticsearchUncaughtExceptionHandler\\", \\"cluster.name\\": \\"business-log\\", \\"node.name\\": \\"es-b-191\\", \\"message\\": \\"uncaught exception in thread [main]\\", \\n","stream":"stdout","time":"2021-08-24T05:23:00.558718935Z"}
{"log":"\\"stacktrace\\": [\\"org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/share/elasticsearch/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.558785261Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:174) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.558803309Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.558814912Z"}
{"log":"\\"at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.558826168Z"}
{"log":"\\"at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) ~[elasticsearch-cli-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559230596Z"}
{"log":"\\"at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559256356Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559267422Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559278431Z"}
{"log":"\\"Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/share/elasticsearch/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559289734Z"}
{"log":"\\"at org.elasticsearch.env.NodeEnvironment.\\u003cinit\\u003e(NodeEnvironment.java:301) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559302663Z"}
{"log":"\\"at org.elasticsearch.node.Node.\\u003cinit\\u003e(Node.java:277) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559336004Z"}
{"log":"\\"at org.elasticsearch.node.Node.\\u003cinit\\u003e(Node.java:257) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559348168Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap$5.\\u003cinit\\u003e(Bootstrap.java:221) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559359128Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559374545Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559385515Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.5593961Z"}
{"log":"\\"... 6 more\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.55940772Z"}
{"log":"\\"Caused by: java.io.IOException: failed to obtain lock on /usr/share/elasticsearch/data/nodes/0\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559417862Z"}
{"log":"uncaught exception in thread [main]\\n","stream":"stderr","time":"2021-08-24T05:23:00.558740201Z"}
{"log":"\\"at org.elasticsearch.env.NodeEnvironment$NodeLock.\\u003cinit\\u003e(NodeEnvironment.java:223) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559428404Z"}
{"log":"\\"at org.elasticsearch.env.NodeEnvironment.\\u003cinit\\u003e(NodeEnvironment.java:271) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559463501Z"}
{"log":"\\"at org.elasticsearch.node.Node.\\u003cinit\\u003e(Node.java:277) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559467938Z"}
{"log":"\\"at org.elasticsearch.node.Node.\\u003cinit\\u003e(Node.java:257) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559471859Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap$5.\\u003cinit\\u003e(Bootstrap.java:221) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559475883Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559479628Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559483295Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559486968Z"}
{"log":"\\"... 6 more\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559490736Z"}
{"log":"\\"Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes/0/node.lock\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.55949414Z"}
{"log":"\\"at sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[?:?]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559497771Z"}
{"log":"\\"at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559501266Z"}
{"log":"\\"at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[?:?]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.55950495Z"}
{"log":"\\"at sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:182) ~[?:?]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559508429Z"}
{"log":"\\"at java.nio.channels.FileChannel.open(FileChannel.java:292) ~[?:?]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559511949Z"}
{"log":"\\"at java.nio.channels.FileChannel.open(FileChannel.java:345) ~[?:?]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559515402Z"}
{"log":"\\"at org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:125) ~[lucene-core-8.4.0.jar:8.4.0 bc02ab906445fcf4e297f4ef00ab4a54fdd72ca2 - jpountz - 2019-12-19 20:16:14]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559528023Z"}
{"log":"\\"at org.apache.lucene.store.FSLockFactory.obtainLock(FSLockFactory.java:41) ~[lucene-core-8.4.0.jar:8.4.0 bc02ab906445fcf4e297f4ef00ab4a54fdd72ca2 - jpountz - 2019-12-19 20:16:14]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559533637Z"}
{"log":"\\"at org.apache.lucene.store.BaseDirectory.obtainLock(BaseDirectory.java:45) ~[lucene-core-8.4.0.jar:8.4.0 bc02ab906445fcf4e297f4ef00ab4a54fdd72ca2 - jpountz - 2019-12-19 20:16:14]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559537605Z"}
{"log":"\\"at org.elasticsearch.env.NodeEnvironment$NodeLock.\\u003cinit\\u003e(NodeEnvironment.java:216) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.55954144Z"}
{"log":"\\"at org.elasticsearch.env.NodeEnvironment.\\u003cinit\\u003e(NodeEnvironment.java:271) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559546203Z"}
{"log":"\\"at org.elasticsearch.node.Node.\\u003cinit\\u003e(Node.java:277) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559549892Z"}
{"log":"\\"at org.elasticsearch.node.Node.\\u003cinit\\u003e(Node.java:257) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559553587Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap$5.\\u003cinit\\u003e(Bootstrap.java:221) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559557237Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559561144Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559564718Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:00.559568294Z"}
{"log":"\\"... 6 more\\"] }\\n","stream":"stdout","time":"2021-08-24T05:23:00.559571879Z"}
{"log":"java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/share/elasticsearch/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?\\n","stream":"stderr","time":"2021-08-24T05:23:00.560074837Z"}
{"log":"Likely root cause: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes/0/node.lock\\n","stream":"stderr","time":"2021-08-24T05:23:00.560104457Z"}
{"log":"\\u0009at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)\\n","stream":"stderr","time":"2021-08-24T05:23:00.56011387Z"}
{"log":"\\u0009at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560121497Z"}
{"log":"\\u0009at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560128834Z"}
{"log":"\\u0009at java.base/sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:182)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560136502Z"}
{"log":"\\u0009at java.base/java.nio.channels.FileChannel.open(FileChannel.java:292)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560145593Z"}
{"log":"\\u0009at java.base/java.nio.channels.FileChannel.open(FileChannel.java:345)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560153588Z"}
{"log":"\\u0009at org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:125)\\n","stream":"stderr","time":"2021-08-24T05:23:00.56016791Z"}
{"log":"\\u0009at org.apache.lucene.store.FSLockFactory.obtainLock(FSLockFactory.java:41)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560176314Z"}
{"log":"\\u0009at org.apache.lucene.store.BaseDirectory.obtainLock(BaseDirectory.java:45)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560196495Z"}
{"log":"\\u0009at org.elasticsearch.env.NodeEnvironment$NodeLock.\\u003cinit\\u003e(NodeEnvironment.java:216)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560205049Z"}
{"log":"\\u0009at org.elasticsearch.env.NodeEnvironment.\\u003cinit\\u003e(NodeEnvironment.java:271)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560213134Z"}
{"log":"\\u0009at org.elasticsearch.node.Node.\\u003cinit\\u003e(Node.java:277)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560220927Z"}
{"log":"\\u0009at org.elasticsearch.node.Node.\\u003cinit\\u003e(Node.java:257)\\n","stream":"stderr","time":"2021-08-24T05:23:00.56022872Z"}
{"log":"\\u0009at org.elasticsearch.bootstrap.Bootstrap$5.\\u003cinit\\u003e(Bootstrap.java:221)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560236341Z"}
{"log":"\\u0009at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560244081Z"}
{"log":"\\u0009at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560250865Z"}
{"log":"\\u0009at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560257451Z"}
{"log":"\\u0009at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560264119Z"}
{"log":"\\u0009at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560270564Z"}
{"log":"\\u0009at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125)\\n","stream":"stderr","time":"2021-08-24T05:23:00.56027737Z"}
{"log":"\\u0009at org.elasticsearch.cli.Command.main(Command.java:90)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560284288Z"}
{"log":"\\u0009at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)\\n","stream":"stderr","time":"2021-08-24T05:23:00.56029096Z"}
{"log":"\\u0009at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)\\n","stream":"stderr","time":"2021-08-24T05:23:00.560299139Z"}
{"log":"For complete error details, refer to the log at /usr/share/elasticsearch/logs/business-log.log\\n","stream":"stderr","time":"2021-08-24T05:23:00.560306183Z"}
{"log":"{\\"type\\": \\"deprecation\\", \\"timestamp\\": \\"2021-08-24T05:23:49,900Z\\", \\"level\\": \\"WARN\\", \\"component\\": \\"o.e.d.c.s.Settings\\", \\"cluster.name\\": \\"business-log\\", \\"node.name\\": \\"es-b-191\\", \\"message\\": \\"[transport.tcp.port] setting was deprecated in Elasticsearch and will be removed in a future release! See the breaking changes documentation for the next major version.\\" }\\n","stream":"stdout","time":"2021-08-24T05:23:49.903982757Z"}
{"log":"{\\"type\\": \\"server\\", \\"timestamp\\": \\"2021-08-24T05:23:50,009Z\\", \\"level\\": \\"ERROR\\", \\"component\\": \\"o.e.b.ElasticsearchUncaughtExceptionHandler\\", \\"cluster.name\\": \\"business-log\\", \\"node.name\\": \\"es-b-191\\", \\"message\\": \\"uncaught exception in thread [main]\\", \\n","stream":"stdout","time":"2021-08-24T05:23:50.021017682Z"}
{"log":"\\"stacktrace\\": [\\"org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/share/elasticsearch/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021060114Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:174) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021070576Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021079349Z"}
{"log":"\\"at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021086955Z"}
{"log":"\\"at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) ~[elasticsearch-cli-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021108066Z"}
{"log":"uncaught exception in thread [main]\\n","stream":"stderr","time":"2021-08-24T05:23:50.021071594Z"}
{"log":"\\"at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021116051Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021173017Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021180535Z"}
{"log":"\\"Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/share/elasticsearch/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021187827Z"}
{"log":"\\"at org.elasticsearch.env.NodeEnvironment.\\u003cinit\\u003e(NodeEnvironment.java:301) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021195967Z"}
{"log":"\\"at org.elasticsearch.node.Node.\\u003cinit\\u003e(Node.java:277) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021203739Z"}
{"log":"\\"at org.elasticsearch.node.Node.\\u003cinit\\u003e(Node.java:257) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.02121041Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap$5.\\u003cinit\\u003e(Bootstrap.java:221) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021217324Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021228617Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021235502Z"}
{"log":"\\"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.6.2.jar:7.6.2]\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021241839Z"}
{"log":"\\"... 6 more\\",\\n","stream":"stdout","time":"2021-08-24T05:23:50.021248657Z"}

背景

docker compose文件

version: '2.2'
services:
  elasticsearch:
    image: elasticsearch:7.6.2
    restart: always
    container_name: es-b-191
    network_mode: host
    volumes:
      - /data/es/data-b:/usr/share/elasticsearch/data
      - /home/es/elasticsearch-7.6.2/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /home/es/elasticsearch-7.6.2/config/jvm.options:/usr/share/elasticsearch/config/jvm.options
    environment:
      - bootstrap.memory_lock=true
    ulimits:
      memlock:
        soft: -1
        hard: -1

服务启动后,看一下inspect信息:

[
    {
        "Id": "cc7904e54b1a33a233306a4656ee2b05c52c29b0e7b13b2262e0ce23b1e97d5e",
        "Created": "2020-05-07T05:38:59.897150949Z",
        "Path": "/usr/local/bin/docker-entrypoint.sh",
        "Args": [
            "eswrapper"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 19848,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-08-24T05:32:41.819618775Z",
            "FinishedAt": "2021-08-24T05:32:41.389193344Z"
        },
        "Image": "sha256:f29a1ee41030e3963026369105f3bee76d75fdecbeca07932ac054126be7bff9",
        "ResolvConfPath": "/var/lib/docker/containers/cc7904e54b1a33a233306a4656ee2b05c52c29b0e7b13b2262e0ce23b1e97d5e/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/cc7904e54b1a33a233306a4656ee2b05c52c29b0e7b13b2262e0ce23b1e97d5e/hostname",
        "HostsPath": "/var/lib/docker/containers/cc7904e54b1a33a233306a4656ee2b05c52c29b0e7b13b2262e0ce23b1e97d5e/hosts",
        "LogPath": "/var/lib/docker/containers/cc7904e54b1a33a233306a4656ee2b05c52c29b0e7b13b2262e0ce23b1e97d5e/cc7904e54b1a33a233306a4656ee2b05c52c29b0e7b13b2262e0ce23b1e97d5e-json.log",
        "Name": "/es-b-191",
        "RestartCount": 14,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/home/es/elasticsearch-7.6.2/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:rw",
                "/data/es/data-b:/usr/share/elasticsearch/data:rw",
                "/home/es/elasticsearch-7.6.2/config/jvm.options:/usr/share/elasticsearch/config/jvm.options:rw"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "host",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "always",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": [],
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "shareable",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": [
                {
                    "Name": "memlock",
                    "Hard": -1,
                    "Soft": -1
                }
            ],
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/98c13a3e7ad12200ac446d88f413735042773034f1c14d9829680a4ad3e62aef-init/diff:/var/lib/docker/overlay2/cd1b4fb403299fa8043710e9b05acdd0fae296e732b1284611815ab6d917b265/diff:/var/lib/docker/overlay2/7a9fbb111038bea02cdbcb94e322f67e3a7d57c27fedb9c6607a562503d13e54/diff:/var/lib/docker/overlay2/763f677946b60440496d29c6bd6d2856ffcedf979230a94d8df364ec5f99bb24/diff:/var/lib/docker/overlay2/5fc3f0d2548920b666a15f9de9641e8a9cdd0e26fd8905ec63969326bf67b9c2/diff:/var/lib/docker/overlay2/7dc779c5479c9eb86333cbcd90ceaaf6c1fb20a79310fa51713117577dec445b/diff:/var/lib/docker/overlay2/8e291588ffc7ec43f1e48afbbd6f2be58ed13c94a81d51761cff684f2ad20d0a/diff:/var/lib/docker/overlay2/1e3159995c5559fb51dce21e84d52559dd9bd1cb9375de18b7c61d855dd5aac2/diff",
                "MergedDir": "/var/lib/docker/overlay2/98c13a3e7ad12200ac446d88f413735042773034f1c14d9829680a4ad3e62aef/merged",
                "UpperDir": "/var/lib/docker/overlay2/98c13a3e7ad12200ac446d88f413735042773034f1c14d9829680a4ad3e62aef/diff",
                "WorkDir": "/var/lib/docker/overlay2/98c13a3e7ad12200ac446d88f413735042773034f1c14d9829680a4ad3e62aef/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/home/es/elasticsearch-7.6.2/config/elasticsearch.yml",
                "Destination": "/usr/share/elasticsearch/config/elasticsearch.yml",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/home/es/elasticsearch-7.6.2/config/jvm.options",
                "Destination": "/usr/share/elasticsearch/config/jvm.options",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/data/es/data-b",
                "Destination": "/usr/share/elasticsearch/data",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "hlhtapp28",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "9200/tcp": {},
                "9300/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "bootstrap.memory_lock=true",
                "PATH=/usr/share/elasticsearch/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "ELASTIC_CONTAINER=true"
            ],
            "Cmd": [
                "eswrapper"
            ],
            "Image": "elasticsearch:7.6.2",
            "Volumes": {
                "/usr/share/elasticsearch/config/elasticsearch.yml": {},
                "/usr/share/elasticsearch/config/jvm.options": {},
                "/usr/share/elasticsearch/data": {}
            },
            "WorkingDir": "/usr/share/elasticsearch",
            "Entrypoint": [
                "/usr/local/bin/docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.config-hash": "d51bf5c1bee8716544296f53f20816a337673f56464f1e5ef22c089847d10b0f",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "elasticsearch-762",
                "com.docker.compose.service": "elasticsearch",
                "com.docker.compose.version": "1.24.1",
                "org.label-schema.build-date": "2020-03-26T06:34:37.794943Z",
                "org.label-schema.license": "Elastic-License",
                "org.label-schema.name": "Elasticsearch",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.url": "https://www.elastic.co/products/elasticsearch",
                "org.label-schema.usage": "https://www.elastic.co/guide/en/elasticsearch/reference/index.html",
                "org.label-schema.vcs-ref": "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
                "org.label-schema.vcs-url": "https://github.com/elastic/elasticsearch",
                "org.label-schema.vendor": "Elastic",
                "org.label-schema.version": "7.6.2",
                "org.opencontainers.image.created": "2020-03-26T06:34:37.794943Z",
                "org.opencontainers.image.documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/index.html",
                "org.opencontainers.image.licenses": "Elastic-License",
                "org.opencontainers.image.revision": "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
                "org.opencontainers.image.source": "https://github.com/elastic/elasticsearch",
                "org.opencontainers.image.title": "Elasticsearch",
                "org.opencontainers.image.url": "https://www.elastic.co/products/elasticsearch",
                "org.opencontainers.image.vendor": "Elastic",
                "org.opencontainers.image.version": "7.6.2"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "4587153515def1ad234fad7574677e184c3136f989d069db8abb0820fa760e8c",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/default",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "host": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "bf45bcd9185588529ed03d6576fb4c458087868ef873fa660e5004c770c8c252",
                    "EndpointID": "7d3d8dfc12ff86f94891c1ff245cf6f56554ced389388fd3cc3b5f1a0668412a",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]

注意一下Entrypoint部分,进入docker容器后看一下,该脚本:

#!/bin/bash
set -e

# Files created by Elasticsearch should always be group writable too
umask 0002

run_as_other_user_if_needed() {
  if [[ "$(id -u)" == "0" ]]; then
    # If running as root, drop to specified UID and run command
    exec chroot --userspec=1000 / "${@}"
  else
    # Either we are running in Openshift with random uid and are a member of the root group
    # or with a custom --user
    exec "${@}"
  fi
}

# Allow user specify custom CMD, maybe bin/elasticsearch itself
# for example to directly specify `-E` style parameters for elasticsearch on k8s
# or simply to run /bin/bash to check the image
if [[ "$1" != "eswrapper" ]]; then
  if [[ "$(id -u)" == "0" && $(basename "$1") == "elasticsearch" ]]; then
    # centos:7 chroot doesn't have the `--skip-chdir` option and
    # changes our CWD.
    # Rewrite CMD args to replace $1 with `elasticsearch` explicitly,
    # so that we are backwards compatible with the docs
    # from the previous Elasticsearch versions<6
    # and configuration option D:
    # https://www.elastic.co/guide/en/elasticsearch/reference/5.6/docker.html#_d_override_the_image_8217_s_default_ulink_url_https_docs_docker_com_engine_reference_run_cmd_default_command_or_options_cmd_ulink
    # Without this, user could specify `elasticsearch -E x.y=z` but
    # `bin/elasticsearch -E x.y=z` would not work.
    set -- "elasticsearch" "${@:2}"
    # Use chroot to switch to UID 1000
    exec chroot --userspec=1000 / "$@"
  else
    # User probably wants to run something else, like /bin/bash, with another uid forced (Openshift?)
    exec "$@"
  fi
fi

# Allow environment variables to be set by creating a file with the
# contents, and setting an environment variable with the suffix _FILE to
# point to it. This can be used to provide secrets to a container, without
# the values being specified explicitly when running the container.
#
# This is also sourced in elasticsearch-env, and is only needed here
# as well because we use ELASTIC_PASSWORD below. Sourcing this script
# is idempotent.
source /usr/share/elasticsearch/bin/elasticsearch-env-from-file

if [[ -f bin/elasticsearch-users ]]; then
  # Check for the ELASTIC_PASSWORD environment variable to set the
  # bootstrap password for Security.
  #
  # This is only required for the first node in a cluster with Security
  # enabled, but we have no way of knowing which node we are yet. We'll just
  # honor the variable if it's present.
  if [[ -n "$ELASTIC_PASSWORD" ]]; then
    [[ -f /usr/share/elasticsearch/config/elasticsearch.keystore ]] || (run_as_other_user_if_needed elasticsearch-keystore create)
    if ! (run_as_other_user_if_needed elasticsearch-keystore list | grep -q '^bootstrap.password$'); then
      (run_as_other_user_if_needed echo "$ELASTIC_PASSWORD" | elasticsearch-keystore add -x 'bootstrap.password')
    fi
  fi
fi

if [[ "$(id -u)" == "0" ]]; then
  # If requested and running as root, mutate the ownership of bind-mounts
  if [[ -n "$TAKE_FILE_OWNERSHIP" ]]; then
    chown -R 1000:0 /usr/share/elasticsearch/{data,logs}
  fi
fi

run_as_other_user_if_needed /usr/share/elasticsearch/bin/elasticsearch

解决方案

从Entrypoint脚本中可以看到es镜像是的用户是1000,所以在宿主机给改用户赋权

chown -R 1000:1000 /data/es/data-b/
chmod -R 777 /data/es/data-b/

如果还是不行可以考虑删除docker.lock文件或者data目录

以上是关于failed to obtain node locks, tried with lock id [0]; maybe these locations are not writable or multi的主要内容,如果未能解决你的问题,请参考以下文章

failed to obtain node locks, tried with lock id [0]; maybe these locations are not writable or multi

failed to obtain in-memory shard lock

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection

failed to obtain in-memory shard lock

failed to obtain in-memory shard lock

error obtaining controller instance: failed to create NAT chain