【Redis】解决WARNING overcommit_memory is set to 0 Background save may fail under low memory condition.

当在Linux或Docker环境下启动Redis时,如果遇到内存不足导致后台保存失败的警告,可以按照以下步骤解决:修改主机的/etc/sysctl.conf文件,添加或更新配置`vm.overcommit_memory=1`,然后重启Redis服务。这将确保内存分配策略有效,防止因内存不足而影响Redis的正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题说明

不管是linux直装,还是在docker环境中,启动redis时,报如下错误 

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. 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.

翻译:

警告内存设置为0!在内存不足的情况下,后台保存可能会失败。若要解决此问题,请将“vm.overcommit_memory = 1”添加到/etc/sysctl.conf,然后重新启动或运行命令“sysctl vm.overcommit_memory=1”使其生效。 

解决方法

编辑主机的/etc/sysctl.conf文件,添加或者配置,保存

vm.overcommit_memory = 1

重启Redis服务即可

oot@tdj-VMware-Virtual-Platform:/myredis# redis-server /myredis/redis.conf 12152:C 09 Jul 2025 18:23:57.910 # 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. root@tdj-VMware-Virtual-Platform:/myredis# redis-server /myredis/redis.conf 12156:C 09 Jul 2025 18:24:41.269 # 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. root@tdj-VMware-Virtual-Platform:/myredis# ps -ef|grep redis|grep -v 用法:grep [选项]... 模式 [文件]... 请尝试执行 "grep --help" 来获取更多信息。 root@tdj-VMware-Virtual-Platform:/myredis# ps -ef|grep redis|grep -v grep root 12145 2540 0 18:23 ? 00:00:00 redis-server *:6379 root@tdj-VMware-Virtual-Platform:/myredis# 有警告但有进程运行,这个警告可以忽略吗
最新发布
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值