在写入Redis (SET foo bar)期间,我得到以下错误:
MISCONF Redis被配置为保存RDB快照,但当前为 无法在磁盘上持久保存。可能修改数据集的命令是 禁用。有关错误的详细信息,请查看Redis日志。
基本上我理解的问题是,redis是不能在磁盘上保存数据,但不知道如何摆脱这个问题。
下面的问题也有同样的问题,它在很久以前就被抛弃了,没有答案,很可能没有尝试解决这个问题。
在写入Redis (SET foo bar)期间,我得到以下错误:
MISCONF Redis被配置为保存RDB快照,但当前为 无法在磁盘上持久保存。可能修改数据集的命令是 禁用。有关错误的详细信息,请查看Redis日志。
基本上我理解的问题是,redis是不能在磁盘上保存数据,但不知道如何摆脱这个问题。
下面的问题也有同样的问题,它在很久以前就被抛弃了,没有答案,很可能没有尝试解决这个问题。
当前回答
$ redis-cli
设置stop-writes-on-bgsave-error no
根据Redis文档,只有当您没有启用RDB快照或您不关心快照中的数据持久性时,才建议这样做。
默认情况下,如果RDB快照启用(至少一个保存点)并且最近的后台保存失败,Redis将停止接受写入。这将使用户意识到(以一种艰难的方式)数据没有正确地保存在磁盘上,否则,强文本的机会是没有人会注意到,并且会发生一些灾难。”
你应该做的是:
# redis-cli
127.0.0.1:6379> CONFIG SET dir /data/tmp
OK
127.0.0.1:6379> CONFIG SET dbfilename temp.rdb
OK
127.0.0.1:6379> BGSAVE
Background saving started
127.0.0.1:6379>
请确保/data/tmp有足够的磁盘空间。
其他回答
FWIW,我遇到了这个问题,解决方案是简单地向盒子添加一个交换文件。我使用了这个方法:https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
此错误是由于BGSAVE失败导致的。在BGSAVE期间,Redis会fork一个子进程来将数据保存到磁盘上。虽然BGSAVE失败的确切原因可以从日志中检查(通常在linux机器上的/var/log/redis/redis-server.log),但很多时候bgive失败是因为fork不能分配内存。很多时候,由于操作系统的优化冲突,fork无法分配内存(尽管机器有足够的可用RAM)。
可以从Redis常见问题中阅读:
Redis background saving schema relies on the copy-on-write semantic of fork in modern operating systems: Redis forks (creates a child process) that is an exact copy of the parent. The child process dumps the DB on disk and finally exits. In theory the child should use as much memory as the parent being a copy, but actually thanks to the copy-on-write semantic implemented by most modern operating systems the parent and child process will share the common memory pages. A page will be duplicated only when it changes in the child or in the parent. Since in theory all the pages may change while the child process is saving, Linux can't tell in advance how much memory the child will take, so if the overcommit_memory setting is set to zero fork will fail unless there is as much free RAM as required to really duplicate all the parent memory pages, with the result that if you have a Redis dataset of 3 GB and just 2 GB of free memory it will fail. Setting overcommit_memory to 1 says Linux to relax and perform the fork in a more optimistic allocation fashion, and this is indeed what you want for Redis.
Redis不需要像操作系统认为的那样多的内存来写入磁盘,所以可能会预先导致fork失败。
要解决这个问题,您可以:
修改/etc/sysctl.conf,增加:
vm.overcommit_memory=1
然后重新启动sysctl:
在FreeBSD上:
sudo /etc/rc.d/sysctl reload
在Linux上:
sudo sysctl -p /etc/sysctl.conf
一个更永久的修复方法可能是查看/etc/redis/redis.conf中200-250行左右的rdb特性的设置,这不是redis 2中的一部分。x天。
值得注意的是
dir ./
可更改为
dir /home/someuser/redislogfiledirectory
或者您可以注释掉所有保存行,而不用担心持久性。(见/etc/redis/redis.conf中的注释)
还有,别忘了
service redis-server stop
service redis-server start
$ redis-cli
设置stop-writes-on-bgsave-error no
根据Redis文档,只有当您没有启用RDB快照或您不关心快照中的数据持久性时,才建议这样做。
默认情况下,如果RDB快照启用(至少一个保存点)并且最近的后台保存失败,Redis将停止接受写入。这将使用户意识到(以一种艰难的方式)数据没有正确地保存在磁盘上,否则,强文本的机会是没有人会注意到,并且会发生一些灾难。”
你应该做的是:
# redis-cli
127.0.0.1:6379> CONFIG SET dir /data/tmp
OK
127.0.0.1:6379> CONFIG SET dbfilename temp.rdb
OK
127.0.0.1:6379> BGSAVE
Background saving started
127.0.0.1:6379>
请确保/data/tmp有足够的磁盘空间。
使用redis-cli,你可以阻止它尝试保存快照:
config set stop-writes-on-bgsave-error no
这是一个快速的解决方法,但是如果你关心使用它的数据,你应该检查一下为什么bgsave首先失败了。