Problem and Solution of Memory Insufficient When docker Starts elasticsearch
- 2021-08-28 21:28:54
- OfStack
Problem
Out of memory when docker installs and starts elasticsearch
System centos8 (Alibaba Cloud ecs Server)
[root@iZ2zeczvvb79boy368xppwZ ~]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
Installation process
docker pull elasticsearch:6.4.0
Modify virtual machine memory (seemingly ineffective)
sysctl -w vm.max_map_count=262144
Run the container using the docker run command
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \
-e "discovery.type=single-node" \
-e "cluster.name=elasticsearch" \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-d elasticsearch:6.4.0
docker ps the view container is not started
[root@iZ2zeczvvb79boy368xppwZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
edfc400862eb rabbitmq:3.7.15 "docker-entrypoint.s … " 14 hours ago Up 14 hours 0.0.0.0:4369->4369/tcp, 0.0.0.0:5671-5672->5671-5672/tcp, 0.0.0.0:15671-15672->15671-15672/tcp, 0.0.0.0:25672->25672/tcp rabbitmq
2ae2f3f8dc1f nginx:1.10 "nginx -g 'daemon of … " 2 weeks ago Up 2 weeks 0.0.0.0:80->80/tcp, 443/tcp nginx
164e4e7561df redis:3.2 "docker-entrypoint.s … " 2 weeks ago Up 2 weeks 0.0.0.0:6379->6379/tcp redis
eeabe57f1f21 mysql:5.7 "docker-entrypoint.s … " 2 weeks ago Up 2 weeks 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
docker ps-a the view container is indeed created
[root@iZ2zeczvvb79boy368xppwZ ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
767829ae1d7c elasticsearch:6.4.0 "/usr/local/bin/dock … " About a minute ago Exited (1) About a minute ago elasticsearch
edfc400862eb rabbitmq:3.7.15 "docker-entrypoint.s … " 14 hours ago Up 14 hours 0.0.0.0:4369->4369/tcp, 0.0.0.0:5671-5672->5671-5672/tcp, 0.0.0.0:15671-15672->15671-15672/tcp, 0.0.0.0:25672->25672/tcp rabbitmq
2ae2f3f8dc1f nginx:1.10 "nginx -g 'daemon of … " 2 weeks ago Up 2 weeks 0.0.0.0:80->80/tcp, 443/tcp nginx
164e4e7561df redis:3.2 "docker-entrypoint.s … " 2 weeks ago Up 2 weeks 0.0.0.0:6379->6379/tcp redis
eeabe57f1f21 mysql:5.7 "docker-entrypoint.s … " 2 weeks ago Up 2 weeks 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
View Log docker logs-f elasticsearch Command View Log Discovers jvm Out of Memory
[root@iZ2zeczvvb79boy368xppwZ ~]# docker logs -f elasticsearch
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00007ebf15330000, 549668585472, 0) failed; error='Not enough space' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 549668585472 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid1.log
Solution
Modify jvm. options file configuration
First look for the jvm. options file location (the location may vary from server to server)
[root@iZ2zeczvvb79boy368xppwZ ~]# find / -name jvm.options
/var/lib/docker/overlay2/d399872a3517b4d4acb0d2f70d0625c0f38251ffe5819a1cea00f8213de3e7f5/diff/usr/share/elasticsearch/config/jvm.options
vim Enter File Modify Virtual Machine Minimum Memory
[root@iZ2zeczvvb79boy368xppwZ ~]# vim /var/lib/docker/overlay2/d399872a3517b4d4acb0d2f70d0625c0f38251ffe5819a1cea00f8213de3e7f5/diff/usr/share/elasticsearch/config/jvm.options
Find the-Xms attribute and modify it to 512m (my elasticsearch: 6.4. 0 defaults to 1g)
## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms512m
-Xmx512m
Save and Exit
In vim, press i to enter editing mode, press ESC to exit editing mode, press: to enter command mode, and then enter w to save, q to exit, q at the bottom command line! For forced exit.
Start the container again, docker ps to see that the container started successfully
docker pull elasticsearch:6.4.0
0
Summarize