1.报错显示
[root@iZ7xv2ya5ap2bnetr231koZ ~]# docker logs es
Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
output:
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid170.log
error:
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000a0000000, 1073741824, 0) failed; error='Not enough space' (errno=12)
at org.elasticsearch.tools.launchers.JvmOption.flagsFinal(JvmOption.java:119)
at org.elasticsearch.tools.launchers.JvmOption.findFinalOptions(JvmOption.java:81)
at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:38)
at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:135)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:86)
Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
2.错误原因分析
2-1 启动ES容器命令
docker run -d \
--name es \
-e "ES_JAVA_OPTS=-Xms1024m -Xmx1024m" \
-e "discovery.type=single-node" \
-v es-data:/usr/share/elasticsearch/data \
-v es-plugins:/usr/share/elasticsearch/plugins \
--privileged \
--network es-net \
-p 9200:9200 \
-p 9300:9300 \
elasticsearch:7.16.1
2-2 错误分析(使用gpt3.5查询分析的,如果错误,恳请指正)
1.errno=12:错误码为12,表示内存不足(OOM)
2."ES_JAVA_OPTS=-Xms1024m -Xmx1024m"分析该命令:
ES_JAVA_OPTS环境变量可以用来设置JVM的参数,以便控制JVM在容器中使用的内存量。该命令中 -Xms1024m指定JVM堆的最小内存量为1024MB, -Xmx1024m指定JVM堆的最大内存量为1024MB。
这样设置JVM堆内存可以避免Elasticsearch使用太多内存导致OOM(Out of Memory)错误。如果Elasticsearch需要更多的内存来执行操作,JVM内存将会自动增长到最大值,但是如果超过最大值,将会抛出OOM错误
3.也就是说JVM占用内存过多,减少JVM占用内存即可,-Xms1024m指定JVM堆的最小内存量为1024MB,通过将设置的JVM最小内存量调整为512M来减少JVM占用的内存,将问题得以解决
3.解决
docker run -d \
--name es \
-e "ES_JAVA_OPTS=-Xms512m -Xmx1024m" \
-e "discovery.type=single-node" \
-v es-data:/usr/share/elasticsearch/data \
-v es-plugins:/usr/share/elasticsearch/plugins \
--privileged \
--network es-net \
-p 9200:9200 \
-p 9300:9300 \
elasticsearch:7.16.1
运行容器成功: