reprinted from: Http://www.redicecn.com/html/Linux/20131125/468.htmlRedis "Misconf Redis is configured to save RDB snapshots, but was currently not able to persist on disk" solution
Today's second encounter with Redis "Misconf Redis is configured to save the RDB snapshots, but was currently not able to persist on disk" issue. This error message is the exception information that the Redis client tool throws when it saves data.
Online check, many people are recommended "config set Stop-writes-on-bgsave-error no". This is not good, this is simply to let the program ignore the exception, so that the program can continue to run, but in fact the data will be stored to the hard disk failure.
The last time you encounter this problem is because a bug in the program caused the system memory to be exhausted, and then fixed the bug solved. Look at the system memory at the time of the problem today and about 2GB, "it feels like it's not Memory" (later discovered or because of memory).
Because Redis is running in daemon mode, you can't see the detailed logs. Modify the profile settings logfile parameter to the file (the default is stdout, it is recommended to modify this parameter after installation, otherwise you will lose a lot of important information), restart Redis, view the log, see the program starts with a line of warning:
"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.overcom Mit_memory=1 ' for the take effect. " (Warning: Excessive use of memory is set to 0.) In a low-memory environment, background saving may fail. To fix this problem, add a ' vm.overcommit_memory = 1 ' in/etc/sysctl.conf and then restart (or run the command ' Sysctl Vm.overcommit_memory=1 ') to take effect. )
When I didn't understand the meaning, I ignored it. After starting the Redis client, the program continues to report "Misconf Redis is configured to save RDB snapshots, and is currently not able to persist on disk" exception, Then look at the Redis logs and see the error "Can ' t save in Background:fork:Cannot allocate memory", the hint is obvious "the fork process is not enough." "(Still a memory problem).
Through Google query "Can ' t save in Background:fork:Cannot allocate memory" this hint, found the solution: View plain Copy to clipboard print? Original: Http://pydelion.com/2013/05/27/redis-cant-save-in-background-fork-cannot-allocate-memory/If Get this Error Can ' t save in Background:fork:Cannot allocate memory it means, your current database is bigger than Memory you have. To fix the issue enable Vm.overcommit_memory:sysctl Vm.overcommit_memory=1 to has if after reboot add this Lin E To/etc/sysctl.cnf:vm.overcommit_memory=1
The problem is solved after modifying Vm.overcommit_memory=1.
Why does the system still have 2GB of memory left, Redis will say that memory is not enough.
Check on the Internet, some people have encountered similar problems, and gave a very good analysis (see: http://www.linuxidc.com/Linux/2012-07/66079.htm), Simply put: Redis when saving data to the hard disk in order to avoid the main process of animation, need to fork a master process, and then in the fork process to complete the operation of the data to the hard disk, if the main process uses 4GB of memory, fork sub-process requires an additional 4GB, when the memory is not enough, Fork failed, and the data saved the hard drive also failed.