docker run --name elasticsearch -p 9200:9200 -p 9300:9300
-e “discovery.type=single-node”
-e ES_JAVA_OPTS="-Xms64m -Xmx128m"
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins
-d elasticsearch:7.6.2
运行这个docker的时候报错如下:
Exception in thread “main” SettingsException[Failed to load settings from /usr/share/elasticsearch/config/elasticsearch.yml]; nested: AccessDeniedException[/usr/share/elasticsearch/config/elasticsearch.yml];
at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:85)
at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:100)
at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:91)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/config/elasticsearch.yml
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.newByteChannel(UnixFileSystemProvider.java:219)
at java.base/java.nio.file.Files.newByteChannel(Files.java:374)
at java.base/java.nio.file.Files.newByteChannel(Files.java:425)
at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
at java.base/java.nio.file.Files.newInputStream(Files.java:159)
at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1070)
at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:83)
原因是没有给相应的目录加权限,加挂载路径和d自己的/mydata/elasticsearch/执行可执行可读写的权限,命令如下:
chmod -R 777 /mydata/elasticsearch/
然后在启动脚本命令添加–privileged=true,重新执行如下命令:
docker run --name elasticsearch -p 9200:9200 -p 9300:9300
-e “discovery.type=single-node”
-e ES_JAVA_OPTS="-Xms64m -Xmx128m"
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins
–privileged=true
-d elasticsearch:7.6.2
运行之后容器还是没有启动起来,看docker日志,使用命令:
docker logs elasticsearch(容器名称)
发现报错如下:
Exception in thread “main” SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: ParsingException[Failed to parse object: expecting token of type [START_OBJECT] but found [VALUE_STRING]];
at org.elasticsearch.common.settings.Settings
B
u
i
l
d
e
r
.
l
o
a
d
F
r
o
m
S
t
r
e
a
m
(
S
e
t
t
i
n
g
s
.
j
a
v
a
:
1097
)
a
t
o
r
g
.
e
l
a
s
t
i
c
s
e
a
r
c
h
.
c
o
m
m
o
n
.
s
e
t
t
i
n
g
s
.
S
e
t
t
i
n
g
s
Builder.loadFromStream(Settings.java:1097) at org.elasticsearch.common.settings.Settings
Builder.loadFromStream(Settings.java:1097)atorg.elasticsearch.common.settings.SettingsBuilder.loadFromPath(Settings.java:1070)
at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:83)
at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:100)
at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:91)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
Caused by: ParsingException[Failed to parse object: expecting token of type [START_OBJECT] but found [VALUE_STRING]]
at org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken(XContentParserUtils.java:78)
at org.elasticsearch.common.settings.Settings.fromXContent(Settings.java:617)
at org.elasticsearch.common.settings.Settings.access
400
(
S
e
t
t
i
n
g
s
.
j
a
v
a
:
82
)
a
t
o
r
g
.
e
l
a
s
t
i
c
s
e
a
r
c
h
.
c
o
m
m
o
n
.
s
e
t
t
i
n
g
s
.
S
e
t
t
i
n
g
s
400(Settings.java:82) at org.elasticsearch.common.settings.Settings
400(Settings.java:82)atorg.elasticsearch.common.settings.SettingsBuilder.loadFromStream(Settings.java:1093)
… 9 more
通过日志可以看出,大概应该是elasticsearch.yml这个文件出现问题,打开文件,发现在设置文件属性的时候,开头没有加空格,这个跟yml语法不符,所以需要在前面加空格,示例如下:
cluster.name: (空格)my-application
然后重新运行启动docker命令,es即可重新启动
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)