即使是不成熟的尝试,也胜于胎死腹中的策略。

can not run elasticsearch as root

Elasticsearch | 作者 zhushaolong | 发布于2018年03月27日 | 阅读数:9827

大家好,问个问题!
使用docker Elasticsearch镜像启动时遇见如下问题
es_pc_soft            | [2018-03-27T03:08:50,763][INFO ][o.e.n.Node               ] [] initializing ...
es_pc_soft | [2018-03-27T03:08:50,772][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
es_pc_soft | org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: Failed to create node environment
es_pc_soft | at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | Caused by: java.lang.IllegalStateException: Failed to create node environment
es_pc_soft | at org.elasticsearch.node.Node.<init>(Node.java:267) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.node.Node.<init>(Node.java:246) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | ... 6 more
es_pc_soft | Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
es_pc_soft | at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84) ~[?:?]
es_pc_soft | at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) ~[?:?]
es_pc_soft | at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) ~[?:?]
es_pc_soft | at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384) ~[?:?]
es_pc_soft | at java.nio.file.Files.createDirectory(Files.java:674) ~[?:1.8.0_161]
es_pc_soft | at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781) ~[?:1.8.0_161]
es_pc_soft | at java.nio.file.Files.createDirectories(Files.java:767) ~[?:1.8.0_161]
es_pc_soft | at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:204) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.node.Node.<init>(Node.java:264) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.node.Node.<init>(Node.java:246) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:213) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:213) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.3.jar:6.2.3]
es_pc_soft | ... 6 more
查询百度google后,知道是因为不能使用root去启动服务。但是docker-compose.yml 中如何设置呢?
compopse文件内容如下:
version: "3"
services:
php_pc:
image: php:7.2-cli
container_name: pcsoft_php
ports :
- "9000:9000"
volumes:
- ./phpcli:/var/www/html/
db_pc:
image: mysql:5.7
container_name: pcsoft_db
volumes:
- ./dbdata:/var/lib/mysql/
ports:
- "3306:3306"
environment:
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
elasticsearch_soft:
image: registry.cn-hangzhou.aliyuncs.com/amor/elastic:6.2.3
container_name: es_pc_soft
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms2g -Xmx2g"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./docke_es/esdata_soft:/usr/share/elasticsearch/data
ports:
- 9200:9200
已邀请:

zhushaolong - 90后IT男

赞同来自:

哈哈哈,问题解决了
首先我没有将本地用户加入docker用户组,所以,我需要通过 sudo 去运行docker 命令,大家看我的docker-compose.yml 就知道我挂在的目录是docke_es/esdata_soft,而我没有通过普通用户去创建这个目录(我其实创建的目录是 docker_es  compose 文件中少写了个r),所以docker会自动创建,以root用户去创建。所以造成了报错。
具体的情况我也不是很清楚。
但是有一点:


简言之,所讨论的目录必须可以通过运行Elasticsearch进程的UID UID 1000进行写入


使用docker 镜像官方文档

psc0606

赞同来自:

elaticsearch源码中会检测用户,不允许以root用户启动。

要回复问题请先登录注册