当前位置: 首页 > 工具软件 > c_count > 使用案例 >

vm.max_map_count [65530] is too low 问题解决(Windows 10、WSL 2、Docker Desktop)

乔俊才
2023-12-01

环境

  • Windows 10 20H2
  • Docker Desktop for Windows 2.4.0.0
  • WSL 2
  • Distro: Ubuntu 20
  • Image:sebp/elk latest

背景

基于Spring Cloud 和 Spring Cloud Alibaba 构建微服务架构,想要整体稳定运行,提升易用性和管控性。所需要集成和整合的内容就非常多,例如:Nacos、ELK等等。

特殊情况下,需要自己在本机搭建环境,并且运行,其复杂度可想而知。为了降低复杂度,在自己电脑上,通过安装Docker Desktop,并采用WSL 2的方式,运行相关组件的Docker Container。

如何安装使用,请看我的文章:

(1) Windows 10 2004 (20H1) 安装 Docker Desktop for Windows (2.3.0.2) 以 WSL 2 方式运行容器
(2) Windows 10 将 Docker Desktop for Windows(WSL 2 方式)文件存储移出C盘放置到其它目录

问题

微服务架构,离不开日志中心,常规的日志中心,均采用ELK来进行数据的存储、查询和展现。为了图方便,直接PULL sebp/elk(ELK的集成镜像)来运行ELK环境。

在Window 10 的 WSL 2 环境中运行sebp/elk,在控制台中会出现以下错误:

waiting for Elasticsearch to be up (1/30)
waiting for Elasticsearch to be up (2/30)
waiting for Elasticsearch to be up (3/30)
waiting for Elasticsearch to be up (4/30)
waiting for Elasticsearch to be up (5/30)
waiting for Elasticsearch to be up (6/30)
waiting for Elasticsearch to be up (7/30)
waiting for Elasticsearch to be up (8/30)
waiting for Elasticsearch to be up (9/30)
waiting for Elasticsearch to be up (10/30)
waiting for Elasticsearch to be up (11/30)
waiting for Elasticsearch to be up (12/30)
waiting for Elasticsearch to be up (13/30)
waiting for Elasticsearch to be up (14/30)
waiting for Elasticsearch to be up (15/30)
waiting for Elasticsearch to be up (16/30)
waiting for Elasticsearch to be up (17/30)
wating for Elasticsearch to be up (18/30)
waiting for Elasticsearch to be up (19/30)
waiting for Elasticsearch to be up (20/30)
waiting for Elasticsearch to be up (21/30)
waiting for Elasticsearch to be up (22/30)
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
ERROR: Elasticsearch did not exit normally - check the logs at /var/log/elasticsearch/elasticsearch.log
waiting for Elasticsearch to be up (23/30)
waiting for Elasticsearch to be up (24/30)
waiting for Elasticsearch to be up (25/30)
waiting for Elasticsearch to be up (26/30)
waiting for Elasticsearch to be up (27/30)
waiting for Elasticsearch to be up (28/30)
waiting for Elasticsearch to be up (29/30)
waiting for Elasticsearch to be up (30/30)
Couldn't start Elasticsearch. Exiting.

错误堆栈中会出现以下关键信息:

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决

主要问题就是:Linux Distro Virtual Memory Areas 默认的vm.max_map_count值是65530,太小不足以支撑ELK的运行。需要将该值增大到至少262144。

方法一

进入到你所使用的WSL 2 distro中(本人使用的是Ubuntu 20)

  1. 以管理员身份进入
~$ sudo -i
  1. 编辑sysctl.conf,增加参数
~$ vim /etc/sysctl.conf (需要是root账户)

~$ vm.max_map_count=262144 (文件最后添加一行)
  1. 重启
~$ sysctl -p (重启生效)

该方法有一个问题,一旦系统重启或者Docker Desktop重启。就需要重新手动执行以上命令,比较麻烦。

方法二

  1. 打开Window 10 的CMD
  2. 执行以下命令:
wsl -d docker-desktop
echo 262144 >> /proc/sys/vm/max_map_count

通过这个方法,即使操作系统重启,参数仍然有效。

对于Linux只停留在使用阶段,如果有更好的方式也请告诉我。

参考资料:

(1):https://github.com/docker/for-win/issues/5202

 类似资料: