今天第二次遇到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”这个提示,找到了解决方法:

  1. // 原文:http://pydelion.com/2013/05/27/redis-cant-save-in-background-fork-cannot-allocate-memory/
  2. If you get this error
  3. Can't save in background: fork: Cannot allocate memory
  4. it means that your current database is bigger than memory you have. To fix the issue enable vm.overcommit_memory:
  5. sysctl vm.overcommit_memory=1
  6. To have if after reboot add this line to /etc/sysctl.cnf:
  7. 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, but is currently not able to persist on disk"问题的解决(转)的更多相关文章

  1. Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"问题的解决

    异常详细信息 Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: MISCO ...

  2. Redis "MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk"问题

    今天在程序中,jedis put数据到redis过程中,“MISCONF Redis is configured to save RDB snapshots, but is currently not ...

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

    今天运行Redis时发生错误,错误信息如下: (error) MISCONF Redis is configured to save RDB snapshots, but is currently n ...

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

    运行redis过程中,突然报错如下: (error) MISCONF Redis is configured to save RDB snapshots, but is currently not a ...

  5. redis 不能持久化问题 MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk.

    转载自:http://www.cnblogs.com/anny-1980/p/4582674.html kombu.exceptions.OperationalError: MISCONF Redis ...

  6. 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报错了,重启了一下好了,一会又报错了. 错误信息: MISCONF Redis is configured to save RDB snapshots, but ...

  7. redis 异常 MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk

    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. 解决方 ...

  8. redis 出现(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

    如果在ubuntu安装的redis含端口使用,但是某些时候常常出现 (error) MISCONF Redis is configured to save RDB snapshots, but is ...

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

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

随机推荐

  1. 滚动视差插件skrollr.js

    东西虽好,但也不能懒到自己一点都不去做总结,那么下方将会写出从网上找到,比较好的网址(应该是根据官网翻译的). 自己先做一个总结:这个插件兼容上做到了降级处理,虽然低端浏览器没有那么顺畅的效果,但是勉 ...

  2. AngularJS入门基础——作用域

    作用域$scope是构成AngularJS应用的核心基础,在整个框架中都被广泛使用,因此了解它是非常重要的. $scope对像是定义应用业务逻辑,控制器方法和视图属性的地方.作用域是视图和控制器之间的 ...

  3. vue需要注意的事宜

    1.Vue在进行点击事件的时候大部分是在标签上进行添加的,一般在标签上添加@click: 如果需要在组件上面进行点击事件的时候,直接写@click是木有变化的,需要在后面添加一个.native就如@c ...

  4. 04 uni-app框架学习:禁用顶部原生导航栏

    1.在pages.json中配置 比如要首页禁用 就在首页这个选项里 加上这几句代码 2.效果如下

  5. Jenkins的安装及使用(一)

    操作环境:Windows7 一.环境准备 1 安装JDK 本文采用jdk-8u111-windows-x64.exe: 安装完成后配置环境变量. 2 配置tomcat 本文采用tomcat8,免安装版 ...

  6. EM算法原理详解

    1.引言 以前我们讨论的概率模型都是只含观测变量(observable variable), 即这些变量都是可以观测出来的,那么给定数据,可以直接使用极大似然估计的方法或者贝叶斯估计的方法:但是当模型 ...

  7. Windows下设置oracle数据库定时备份

    1编写备份脚本 echo backup oracle database...... echo %~dp0 set file_dir=%~dp0 echo backup time...... set & ...

  8. 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1 20165301

    2018-2019-2 <网络对抗技术>Exp0 Kali安装 Week1 20165301 安装kali 参考此网站 设置共享文件夹 虚拟机->设置->选项->共享文件 ...

  9. Tomcat启动默认访问项目

    一般有两种可以实现:推荐使用这一种.更灵活 一般项目的编译项目都在Tomcat的webapps下,项目的访问路径一般为:http://localhost:8080/项目虚拟路径.但是Tomcat的默认 ...

  10. .NetCore下使用Autofac做 IOC 容器

    在.NetCore中使用自带的IOC容器 写注入的时候会写很多,如果要自己封装的话也达不到预期的效果,所以这里采用Autofac来时替代 .NetCore自带的容器 nuget首先引用Autofac. ...