docker启动elasticsearch时内存不足怎么解决

发布时间:2022-04-19 16:38:23 作者:iii
来源:亿速云 阅读:759

本文小编为大家详细介绍“docker启动elasticsearch时内存不足怎么解决”,内容详细,步骤清晰,细节处理妥当,希望这篇“docker启动elasticsearch时内存不足怎么解决”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

问题

docker安装并启动elasticsearch时内存不足

系统centos8(阿里云ecs服务器

[root@iz2zeczvvb79boy368xppwz ~]# cat /etc/redhat-release
centos linux release 8.1.1911 (core)

安装过程

docker pull elasticsearch:6.4.0

修改虚拟机内存(貌似没有效果)

sysctl -w vm.max_map_count=262144

使用docker run命令跑容器

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查看容器并没有启动

[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 查看容器确实创建了

[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

查看日志docker logs -f elasticsearch命令查看日志发现jvm内存不足

[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

解决方法

修改jvm.options文件配置
首先查找jvm.options文件位置(每个服务器的位置可能不同)

[root@iz2zeczvvb79boy368xppwz ~]# find / -name jvm.options
/var/lib/docker/overlay2/d399872a3517b4d4acb0d2f70d0625c0f38251ffe5819a1cea00f8213de3e7f5/diff/usr/share/elasticsearch/config/jvm.options

vim进入文件修改虚拟机最小内存

[root@iz2zeczvvb79boy368xppwz ~]# vim /var/lib/docker/overlay2/d399872a3517b4d4acb0d2f70d0625c0f38251ffe5819a1cea00f8213de3e7f5/diff/usr/share/elasticsearch/config/jvm.options

找到-xms属性,修改成512m(我的elasticsearch:6.4.0默认为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

保存并退出

vim中按i进入编辑模式,按esc退出编辑模式,按:进入命令模式,然后在底部命令行输入w为保存,q为退出,q!为强制退出。
再次启动容器,docker ps查看容器启动成功

[root@iz2zeczvvb79boy368xppwz ~]# docker ps
container id  image     command     created    status    ports                              names
f5c4ed61196b  elasticsearch:6.4.0 "/usr/local/bin/dock…" 15 minutes ago  up 15 minutes  0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp                    elasticsearch
edfc400862eb  rabbitmq:3.7.15  "docker-entrypoint.s…" 15 hours ago  up 15 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启动elasticsearch时内存不足怎么解决”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. elasticsearch启动时警告无法锁定JVM内存如何解决
  2. elasticsearch启动时警告无法锁定JVM内存怎么解决

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

docker elasticsearch

上一篇:Elasticsearch使用常见问题怎么解决

下一篇:docker怎么安装Elasticsearch集群并设置密码

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》