赞
踩
今天同事反应测试环境业务一直报错,好像是redis持久化出现了问题,并给出了错误信息,让我帮忙看一下,说明明还有2G内存为何还会报错
MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.. channel: [id: 0xb07fbbd2, L:/10.4.11.84:43534 - R:ruigecloud-redis/10.4.11.165:6379] command: (EXPIRE), params: [[49, 51, 58, 114, 117, 105, 103, 101, 99, 108, ...], 2592000]
我想内存不够用通常导致持久化失败,但同事告知还有2G内存,我大致明白问题出在哪里了
问题主要有以下几个方面:
1、内存确实没有不够没有合理化分配
解释:Redis在保存数据时为避免主进程假死,会Fork一份主进程,Fork进程完成数据保存到硬盘的操作,若主进程用了4GB,Fork子进程的时候需要额外的4GB,所以内存确实不够了
2、临时处理(日志中有提示“because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option).”)
连接redis后运行 config set stop-writes-on-bgsave-error no 命令
提示:仅仅是让程序忽略了这个异常,使得程序能够继续往下运行,但实际上数据还是会存储到硬盘失败!
3、为了看日志方便一定要配置日志路径:
修改配置文件设置logfile
4、低内存环境下,修正后台保存失败问题。
/etc/sysctl.conf
末尾添加
vm.overcommit_memory = 1
sysctl -p
目前为止此问题暂时解决,还需要对Redis的相关配置进行优化!!!
5、配置日志文件、日志级别
loglevel notice
logfile "/data/log/redis-6379.log"
6、做好内存容量规划,设置回收策略
maxmemory 4294967296
maxmemory-policy volatile-lru允许长期不活跃的数据从Redis丢失
dir 路径
dbfilename dump6379.rdb
7、重启redis
Redis的重启不要kill!!!
127.0.0.1:6379> SHUTDOWN
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。