【Redis问题】缓存无法写入到本地磁盘

2,377 阅读2分钟

【Redis问题】缓存无法写入到本地磁盘

前言

最近刚部署了线上的项目,前几天系统正常运行,结果今天早上发现系统异常,查看日志,排查到问题是Redis报错,报错信息:

org.springframework.data.redis.RedisSystemException: 
Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: 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.
省略..........................................

问题出现原因

报错信息翻译
Redis被配置为保存数据库快照,但它目前不能持久化到硬盘。用来修改集合数据的命令不能用。请查看Redis日志的详细错误信息。

简单来说就是Redis无法将缓存信息写入到本次磁盘,出现问题无非以下几种情况:

系统磁盘空间不足问题

这个就很简单,清理磁盘空间或扩容

操作目录权限问题

问题信息

//问题信息
Failed opening the RDB file dump.rdb (in server root dir /data/opt/redis/data) for saving: Permission denied

默认配置

# The filename where to dump the DB
dbfilename dump.rdb

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./

修改目录权限或者修改目录位置

-- 修改目录权限
chmod 777 /data/opt/redis/data
注:仅把/data/opt/redis/data目录的权限设置为rwxrwxrwx
chmod -R 777 目录
注:表示将整个/data/opt/redis/data目录与其中的文件和子目录的权限都设置为rwxrwxrwx`
其中,参数`-R`表示启动递归处理
-- 修改目录
dir /data/opt/redis/data

重启Redis

Redis配置问题

进入redis安装目录,执行客户端连接程序

cd /data/opt/redis/bin
./redis-cli

执行以下命令,关闭快照

127.0.0.1:6379> config set stop-writes-on-bgsave-error no

然后你会惊喜的发现程序可以正常使用了,但是通过这种解决方案治标不治本,从根本上来讲,还是需要大家查看后台异常原因,进行有针对性的解决。

参考文章

MISCONF Redis is configured to save RDB snapshots

stop-writes-on-bgsave-error

解决Redis报错Redis is configured to save RDB snapshots, but it is currently not able to persist on disk