我正在尝试使用 nfs mount 作为我的 elasticsearch 数据目录,之前我使用的是主机存储。 但是当我尝试抬起我的容器时,我遇到了下面提到的错误:
ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes/0];
es02 | Likely root cause: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes/0
es02 | at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
es02 | at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
es02 | at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
es02 | at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:388)
es02 | at java.base/java.nio.file.Files.createDirectory(Files.java:694)
es02 | at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:801)
es02 | at java.base/java.nio.file.Files.createDirectories(Files.java:787)
es02 | at org.elasticsearch.env.NodeEnvironment.lambda$new$0(NodeEnvironment.java:275)
es02 | at org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:212)
es02 | at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:272)
es02 | at org.elasticsearch.node.Node.<init>(Node.java:362)
es02 | at org.elasticsearch.node.Node.<init>(Node.java:289)
我之前使用 docker-compose 时,我的集群工作正常,当我使用主机存储时,但当我尝试切换到 NFS 存储时,我遇到了上述错误。 下面是我的 docker-compose 文件:
version: '3.3'
volumes:
data:
driver: local
driver_opts:
type: nfs
device: ":/data1/elasticsearch_data"
o: addr=10.10.15.46,rw
#volumes:
# repo:
# driver: local
# driver_opts:
# type: none
# device: /apm_backup
# o: bind
#
services:
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
container_name: es02
volumes:
- data:/usr/share/elasticsearch/data
# - ./unicast_hosts.txt:/usr/share/elasticsearch/config/unicast_hosts.txt
environment:
- node.name=es02
- node.master=true
- node.data=true
- cluster.name=apm-docker-cluster
- discovery.seed_hosts=es01
# - discovery.seed_providers=file
- cluster.initial_master_nodes=es01,es02
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms10g -Xmx10g"
- XPACK_SECURITY_ENABLED=false
# - path.repo=/apm_backup
# command: ["elasticsearch", "-Elogger.level=DEBUG"]
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
restart: "unless-stopped"
logging:
driver: 'json-file'
options:
max-size: '2m'
max-file: '5'
ports:
- 9200:9200
- 9300:9300
extra_hosts:
- "es01:10.10.26.27"
- "es02:10.10.26.111"
- "es03:10.10.26.111"
network_mode: "host"
labels:
org.label-schema.group: "APM-monitoring"
healthcheck:
test: ["CMD", "curl", "--write-out", "'HTTP %{http_code}'", "--silent", "--output", "/dev/null", "http://es02:9200/"]
retries: 10
interval: 10s
到目前为止我已经尝试过:
chown 1000:1000 elasticsearch_data(照片中提到的 vimzy 用户的 1000 个 uid)。
我在 docker-compose 中尝试过 priviliged=true 。 除此之外,还尝试了多种方法来解决权限被拒绝的问题。
任何帮助...
此错误是由于指定路径的权限问题而发生的。
将路径从
/usr/share/elasticsearch/data
更改为 /var/lib/elasticsearch/data
它会起作用的!
这解决了我的问题
sudo chown -R 1000:root docker_data
可能与 NFSv3 不兼容,请尝试切换到 NFSv4,详细信息请参阅本博客:
https://www.frakkingsweet.com/elasticsearch-nfs-and-locking-issues/
以下解决方案对我有用:
我格式化了 NFS 磁盘,然后将 nfs 磁盘作为设备安装在 docker-compose.yml 中
version: '3.3'
volumes:
data:
driver: local
driver_opts:
type: nfs
device: ":/data1/elasticsearch_data"
o: addr=10.10.15.46,rw
这是由于绑定安装而发生的。例如,如果您的 docker compose 文件类似于下面的内容
version: '3'
services:
elasticsearch:
image: elasticsearch:8.9.2
volumes:
- ./esdata:/usr/share/elasticsearch/data
ports:
- 9200:9200
- 9300:9300
environment:
- discovery.type=single-node
- xpack.security.enabled=false
volumes:
esdata:
它将抛出权限错误,因为
esdata
没有允许 docker 写入/读取的正确权限
要解决此问题,您需要运行此命令
sudo chown -R 1000:root esdata
说明: Linux 中的每个用户都与一个 id 相关联
#This will give the id of the current user, in most cases it will be 1000
id -u
在容器内,用户是
elastic
,其 id 为 1000
因此我们需要给id为
1000
的用户授予读写绑定挂载数据目录的权限,本例中为esdata
。因此命令 sudo chown -R 1000:root esdata
有 1000