redis报错

    网站登录异常,redis数据不能写!解决方法汇总!

redis---flushdb  ###提示如下错误    ###flushall              清空说有数据,所有库

(error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk.

Commands that may modify the data set are disabled. Please check Redis logs for details about the error.

###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!在低内存环境下,后台保存可能失败。为了修正这个问题,

01、低内存解决

sysctl vm.overcommit_memory=1    ###立即生效  

vim /etc/sysctl.conf                       

vm.overcommit_memory = 1           ###重启生效或者sysctl   -a  内存重新读取/etc/sysctl.conf

 02、异常信息磁盘写停止

# However if you have setup your proper monitoring of the Redis server
# and persistence, you may want to disable this feature so that Redis will
# continue to work as usual even if there are problems with disk,
# permissions, and so forth.
stop-writes-on-bgsave-error yes    ###默认,遇到异常停止写数据

root@ubuntu:/usr/local/redis/bin# ./redis-cli

127.0.0.1:6379> config set stop-writes-on-bgsave-error no   ###临时修改,永久解决修改redis.conf

OK

127.0.0.1:6379> lpush myColour "red"                                       ###测试是否可以写数据

(integer) 1    

set test  "hello,OK" 

get test

vim  redis.conf                   

stop-writes-on-bgsave-error no                                                  ###永久性生效


低内存解决方案

free    -m    ###可用内存很小 300MB

  • If you get this error  
  •   
  • Can't save in background: fork: Cannot allocate memory  
  •   
  • it means that your current database is bigger than memory you have. To fix the issue enable vm.overcommit_memory:  
  •   
  • sysctl vm.overcommit_memory=1  
  •   
  • To have if after reboot add this line to /etc/sysctl.conf:  
  •   
  • vm.overcommit_memory=

借鉴:

http://www.cnblogs.com/anny-1980/p/4582674.html

http://www.cnblogs.com/qq78292959/p/3994349.html

原文地址:https://www.cnblogs.com/xiaochina/p/6236327.html