今天在redis中执行setrange name 1 chun 命令时报了如下错误提示:

(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.

大意为:(错误)misconf redis被配置以保存数据库快照,但misconf redis目前不能在硬盘上持久化。用来修改数据集合的命令不能用,请使用日志的错误详细信息。

 

这是由于强制停止redis快照,不能持久化引起的,运行info命令查看redis快照的状态,如下:

 

解决方案如下:

连接redis后运行 config set stop-writes-on-bgsave-error no 命令

关闭配置项stop-writes-on-bgsave-error解决该问题。


今天第二次遇到Redis “MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk”的问题。这个错误信息是Redis客户端工具在保存数据时候抛出的异常信息。

网上查了一下,很多人都是建议“config set stop-writes-on-bgsave-error no”。这样做其实是不好的,这仅仅是让程序忽略了这个异常,使得程序能够继续往下运行,但实际上数据还是会存储到硬盘失败!

上一次遇到这个问题是因为一个程序的Bug造成系统内存被耗尽了,后来修复了那个Bug问题就解决了。今天出现问题时查看系统内存还有2GB左右,“感觉好像不是内存的缘故”(后面发现还是因为内存的缘故)。

由于Redis是daemon模式运行的,没法看到详细的日志。修改配置文件设置logfile参数为文件(默认是stdout,建议以后安装完毕就修改这个参数为文件,不然会丢掉很多重要信息),重启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!在低内存环境下,后台保存可能失败。为了修正这个问题,请在/etc/sysctl.conf 添加一项 'vm.overcommit_memory = 1' ,然后重启(或者运行命令'sysctl vm.overcommit_memory=1' )使其生效。)

当时没明白意思,就忽略了。再启动Redis客户端,程序保存数据时继续报“MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk”异常,再查看Redis日志,看到有这样的错误提示“Can’t save in background: fork: Cannot allocate memory”,这个提示很明显"Fork进程时内存不够用了!"(还是内存的问题)。

通过谷歌查询“Can’t save in background: fork: Cannot allocate memory”这个提示,找到了解决方法:

// 原文:http://pydelion.com/2013/05/27/redis-cant-save-in-background-fork-cannot-allocate-memory/
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.cnf:  

vm.overcommit_memory=1 

修改vm.overcommit_memory=1后问题果然解决了。

为什么系统明明还剩2GB的内存,Redis会说内存不够呢?

网上查了一下,有人也遇到类似的问题,并且给出了很好的分析(详见:http://www.linuxidc.com/Linux/2012-07/66079.htm),简单地说:Redis在保存数据到硬盘时为了避免主进程假死,需要Fork一份主进程,然后在Fork进程内完成数据保存到硬盘的操作,如果主进程使用了4GB的内存,Fork子进程的时候需要额外的4GB,此时内存就不够了,Fork失败,进而数据保存硬盘也失败了。

连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots的更多相关文章

  1. 解决redis连接错误:MISCONF Redis is configured to save RDB snapshots, but it is currently not able to...

    今天Redis服务器在连接redis数据库时突然报错:MISCONF Redis is configured to save RDB snapshots, but it is currently no ...

  2. laravel 项目表单中有csrf_token,但一直报错419错误 解决redis连接错误:MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persi

    laravel 项目表单中有csrf_token,但一直报错419错误,因为项目中使用到Redis缓存,在强制关闭Redis后出现的问题,查询laravel.log文件查找相关问题 安装redis后在 ...

  3. redis连接错误3种解决方案System Error MISCONF Redis is configured to save RDB snapshots

    redis连接错误System Error MISCONF Redis is configured to save RDB snapshots, but XX   情况1解决办法: 由于强制停止red ...

  4. Redis错误解决:(error) MISCONF Redis is configured to save RDB snapshots

    刚开始学习使用redis数据库,在执行删除命令时,提示了我这么一个错误: 错误提示 (error) MISCONF Redis is configured to save RDB snapshots, ...

  5. redis出现MISCONF Redis is configured to save RDB snapshots...的错误

    今天重启服务器在连接redis数据库时突然报错: MISCONF Redis is configured to save RDB snapshots, but it is currently not ...

  6. edis.clients.jedis.exceptions.JedisDataException: MISCONF Redis is configured to save RDB snapshots,

    edis.clients.jedis.exceptions.JedisDataException: MISCONF Redis is configured to save RDB snapshots ...

  7. redis.clients.jedis.exceptions.JedisDataException: MISCONF Redis is configured to save RDB snapshots

    最近在学习Redis ,在写test测试的时候碰到这个报错: redis.clients.jedis.exceptions.JedisDataException: MISCONF Redis is c ...

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

    出现redis错误: (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to p ...

  9. 【redis】redis异常-MISCONF Redis is configured to save RDB snapshots

    使用redis报错: MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persis ...

随机推荐

  1. ruby如何查找一个方法属于哪个类

    这是一个看似简单,实际不那么直接的问题.一种方法是先直接看当前对象的类是神马东东: puts self.class 或者 self.class.name 不过在某些情况下上述代码返回不了具体的名称,前 ...

  2. Docker 单主机网络

    PS:欢迎大家关注我的公众号:aCloudDeveloper,专注技术分享,努力打造干货分享平台,二维码在文末可以扫,谢谢大家. 当容器逐步向容器集群,容器云技术演进的时候,一个不得不面对的问题就是各 ...

  3. oracle的for和i++

    很长时间没用oracle的储存了,这次用到一次i++i++的sql语句:declarei_1 number(30) :=0;begin i_1 :=i_1+1;//i_1=1 insert into ...

  4. linux命令TOP参数load average详解[转]

    我们知道判断一个系统的负载可以使用top,uptime等命令去查看,它分别记录了一分钟.五分钟.以及十五分钟的系统平均负载……我们知道判断一个系统的负载可以使用top,uptime等命令去查看,它分别 ...

  5. Mysql安装和登录相关操作

    一.mysql的下载和安装 1.下载链接地址 http://dev.mysql.com/downloads/mysql/ 安装如下操作进行下载. 2.mysql数据库安装(Windows环境) 1.解 ...

  6. C++各个存储区

    #include<iostream.h>void main(){char a[]="abc";栈 char b[]="abc";栈 char* c= ...

  7. nginx for Windows

    zt from nginx official site. Known issuesPossible future enhancements Version of nginx for Windows u ...

  8. IT桔子沙龙之本地生活服务O2O探路者笔记整理

    这个沙龙活动侧重于创业融资与投资角度 主持人:真格基金投资分析师顾女士;E-mail:grace@zhenfund.com;新浪微博:@顾三小姐 赞助商七牛云的服务宣传:静态资源托管:上传下载全网加速 ...

  9. html5 file upload and form data by ajax

    html5 file upload and form data by ajax 最近接了一个小活,在短时间内实现一个活动报名页面,其中遇到了文件上传. 我预期的效果是一次ajax post请求,然后在 ...

  10. RPi:QT+wiringPi demo程序

    一个项目里面要用到这玩意儿,网上查了几篇文章凑出来最后还是不行,自己灵机一动就成了. 今天再次搜索的时候,发现另一篇文章已经讲明白了,真是欲哭无泪 程序大部分参考的是之前学qt的摸索出来的,其实只要在 ...