今天将服务器上Redis的监听从公网0.0.0.0,改为本地127.0.0.1后,发现启动时会出现警告:
“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!在低内存环境下,后台保存可能失败。为了修正这个问题,请在/etc/sysctl.conf 添加一项 'vm.overcommit_memory = 1' ,然后重启(或者运行命令'sysctl vm.overcommit_memory=1' )使其生效。)
没有注意这个WARNINIG,之后启动Redis测试,发现报错:“MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk”,这个提示很明显是“Fork进程时内存不够用了”。
解决办法:按照WARNING中提示,1.在/etc/sysctl.conf中添加 vm.overcommit_memory=1,之后reboot或者执行sysctl vm.overcommit_memory=1指令使其生效即可。