安装Redis报“To fix this issue add 'vm.overcommit_memory = 1' .........”错

返回主页

一、问题描述

在执行redis-server redis.conf命令, 以试图启动redis服务的时候,报错了, 错误信息如下:

[root@converts ~]# redis-server redisConfig.conf 
1221975:C 23 May 2024 10:25:31.362 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

安装Redis报“WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.”错

二、错误原因

发生这个错误的原因是Redis服务器在启动时检测到操作系统未启用内存过量承诺(memory overcommit)。Redis建议启用此功能以避免在后台保存数据或执行复制操作时,因内存不足而导致失败。即使在非低内存情况下,如果不启用内存过量承诺,也有可能引发故障。

三、解决方案

  1. 编辑/etc/sysctl.conf文件

    [root@converts ~]# vim /etc/sysctl.conf
    
  2. 添加或修改配置项:在文件末尾添加以下行,如果已有该行并设置为0,则修改为1:

    vm.overcommit_memory = 1
    

    安装Redis报“To fix this issue add 'vm.overcommit_memory = 1' .........”错

    这个设置允许操作系统分配超过实际物理内存和交换空间总和的内存给进程,这对于Redis这类需要大量内存分配的应用是有益的。

  3. 应用更改:无需重启系统,可以直接运行以下命令让改动立即生效:

    [root@converts ~]# sysctl vm.overcommit_memory=1
    
  4. 重新启动Redis服务器:应用了上述修改后,重启Redis服务以确保更改生效:

    [root@converts ~]# systemctl restart redis.service
    
展开/折叠菜单
71 预览数量 2024-05-23 10:35:25 发布 时间
目录
赞数量
评论数量
返回顶部
暂无评论

暂无评论