本文翻译自:MISCONF Redis is configured to save RDB snapshots
During writes to Redis ( SET foo bar
) I am getting the following error: 在写入Redis( SET foo bar
)期间,出现以下错误:
MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. MISCONF Redis配置为保存RDB快照,但当前无法持久保存在磁盘上。 Commands that may modify the data set are disabled. 禁用了可能修改数据集的命令。 Please check Redis logs for details about the error. 请检查Redis日志以获取有关该错误的详细信息。
Basically I understand that the problem is that redis is not able to save data on the disk, but have no idea how to get rid of the problem. 基本上,我了解到问题在于redis无法将数据保存在磁盘上,但是不知道如何解决该问题。
Also the following question has the same problem, it is abandoned long time ago with no answers and most probably no attempts to solve the problem. 同样,以下问题也有相同的问题,它很久以前就被抛弃了,没有答案,很可能没有尝试解决该问题。
#1楼
参考:https://stackoom.com/question/1K9vX/MISCONF-Redis配置为保存RDB快照
#2楼
Thanks everyone for checking the problem, apparently the error was produced during bgsave
. 感谢大家检查问题,显然错误是在bgsave
期间bgsave
。
For me, typing config set stop-writes-on-bgsave-error no
in a shell and restarting Redis solved the problem. 对我来说,在shell中键入config set stop-writes-on-bgsave-error no
并重新启动Redis解决了该问题。
#3楼
In case you encounter the error and some important data cannot be discarded on the running redis instance (problems with permissions for the rdb
file or its directory incorrectly, or running out of disk space), you can always redirect the rdb
file to be written somewhere else. 如果遇到错误,并且一些重要数据无法在正在运行的Redis实例上丢弃(存在对rdb
文件或其目录的权限不正确的问题,或者磁盘空间不足),则始终可以重定向将rdb
文件写入某处其他。
Using redis-cli
, you can do something like this: 使用redis-cli
,您可以执行以下操作:
CONFIG SET dir /tmp/some/directory/other/than/var
CONFIG SET dbfilename temp.rdb
After this, you might want to execute a BGSAVE
command to make sure that the data will be written to the rdb
file. 此后,您可能要执行BGSAVE
命令以确保将数据写入rdb
文件。 Make sure that when you execute INFO
, bgsave_in_progress
is already 0
(either the operation is successful or there is an error encountered). 确保执行INFO
, bgsave_in_progress
已经为0
(操作成功或遇到错误)。 After that, you can now start backing up the generated rdb
file somewhere safe. 之后,您现在可以在安全的地方开始备份生成的rdb
文件。
#4楼
There might be errors during the bgsave process due to low memory. 由于内存不足,在bgsave过程中可能会出错。 Try this (from redis background save FAQ) 试试看(从Redis后台保存常见问题解答)
echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1
#5楼
Using redis-cli
, you can stop it trying to save the snapshot: 使用redis-cli
,可以尝试保存快照来停止它:
config set stop-writes-on-bgsave-error no
This is a quick workaround, but if you care about the data you are using it for, you should check to make sure why bgsave failed in first place. 这是一个快速的解决方法,但是如果您关心要使用它的数据,则应检查以确保bgsave首先失败的原因。
#6楼
in case you are working on a linux machine, also recheck the file and folder permissions of the database. 如果您在Linux机器上工作,还请重新检查数据库的文件和文件夹权限。
The db and the path to it can be obtained via: 可以通过以下方式获取数据库及其路径:
in redis-cli
: 在redis-cli
:
CONFIG GET dir 配置获取目录
CONFIG GET dbfilename 配置获取dbfilename
and in the commandline ls -l
. 并在命令行ls -l
。 The permissions for the directory should be 755 , and those for the file should be 644 . 目录的权限应为755 ,文件的权限应为644 。 Also, normally redis-server executes as the user redis
, therefore its also nice to give the user redis
the ownership of the folder by executing sudo chown -R redis:redis /path/to/rdb/folder
. 另外,通常redis-server会以用户redis
身份执行,因此也可以通过执行sudo chown -R redis:redis /path/to/rdb/folder
给用户redis
文件夹的所有权。 This has been elaborated in the answer here . 这已经在这里的答案中得到了阐述。