【问题标题】:Redis is configured to save RDB snapshots, but is currently not able to persist on diskRedis 配置为保存 RDB 快照,但目前无法在磁盘上持久化
【发布时间】:2013-11-21 06:55:53
【问题描述】:

每当我执行任何修改redis中数据的命令时,我都会收到以下错误

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.

我在 mac 上使用 brew 安装了 redis。如何获取 redis-server 记录信息的日志文件的位置。我试图寻找redis conf。文件,但也找不到。

[1] redis conf 文件 [2] redis 日志文件的默认位置是什么。

如何摆脱上述错误,并能够执行修改redis中数据的命令。

【问题讨论】:

标签: redis


【解决方案1】:

使用 brew 安装时,日志文件设置为标准输出。您需要编辑/usr/local/etc/redis.conf 并将日志文件更改为其他内容。我将我的设置为:

logfile /var/log/redis-server.log

您还要确保运行 redis 的用户对日志文件具有写入权限,否则 redis 将无法完全启动。然后重启redis:

brew services restart redis

重新启动后,错误需要一段时间才能显示在日志中,因为它发生在 redis 定时刷新失败之后。您应该会看到如下内容:

[7051] 29 Dec 02:37:47.164 # Background saving error
[7051] 29 Dec 02:37:53.009 * 10 changes in 300 seconds. Saving...
[7051] 29 Dec 02:37:53.010 * Background saving started by pid 7274
[7274] 29 Dec 02:37:53.010 # Failed opening .rdb for saving: Permission denied

在 brew install 之后,它会尝试保存到 /usr/local/var/db/redis/,并且由于 redis 可能是以您当前用户而不是 root 用户身份运行的,因此它无法写入它。一旦 redis 有权写入目录,您的日志文件将显示:

[7051] 29 Dec 03:08:59.098 * 1 changes in 900 seconds. Saving...
[7051] 29 Dec 03:08:59.098 * Background saving started by pid 8833
[8833] 29 Dec 03:08:59.099 * DB saved on disk
[7051] 29 Dec 03:08:59.200 * Background saving terminated with success

并且stop-writes-on-bgsave-error 错误将不再出现。

【讨论】:

    【解决方案2】:

    所以我想在这里添加答案有点晚了,但是我想知道你的问题,因为我有同样的错误。我通过像这样更改我的 redis.conf 的 dir 变量来解决它:

    # 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 /root/path/to/dir/with/write/access/
    

    默认值为:./,因此根据您启动 redis 服务器的方式,您可能无法保存快照。

    希望对某人有所帮助!

    【讨论】:

      【解决方案3】:

      就我而言,我通过以下步骤解决了这个问题

      原因:默认情况下redis存储数据@./,如果redis以redis用户运行,这意味着redis将无法在./文件中写入数据,那么您将面临上述错误。

      分辨率: 步骤#1(输入redis可以进行写操作的有效位置) root@fpe:/var/lib/redis# vim /etc/redis/redis.conf

      dir /var/lib/redis #(这个位置必须有redis用户可以写的权限)

      步骤 #2(连接到 redis cli 和映射目录以写入并发出以下变量)

      127.0.0.1:6379> 配置设置目录“/var/lib/redis”

      127.0.0.1:6379> BGSAVE -

      这将使redis能够将数据写入转储文件。

      【讨论】:

        【解决方案4】:

        正在通过 github 讨论,建议的解决方案是 运行

        config set stop-writes-on-bgsave-error no 在 redis-cli 中。 这是链接 https://github.com/redis/redis/issues/584#issuecomment-11416418

        【讨论】:

          【解决方案5】:

          修复此错误的步骤:

          输入redis-cli进入redis cli

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

          然后尝试设置键值

          127.0.0.1:6379> set test_key 'Test Value'
          127.0.0.1:6379> get test_key
          "Test Value"
          

          【讨论】:

            【解决方案6】:

            检查以下地方:

            /usr/local/Cellar/redis...
            /usr/local/var/log/redis.log
            /usr/local/etc/redis.conf
            

            此错误通常表示写权限有问题,请确保您的 RDB 目录是可写的。

            【讨论】:

              【解决方案7】:

              通常是因为权限限制。就我而言,它是 redis 禁用的写入选项。

              你可以尝试在shell中运行redis-cli,然后运行如下命令:

              set stop-writes-on-bgsave-error yes
              

              【讨论】:

              • 这个答案不应该有 5 个赞成票,因为它具有误导性。 “stop-writes-on-bgsave-error”是一个 redis 设置,如果 bgsave(dump.rdb 的)失败,可以用来要求 redis 服务器停止接受写入。这反过来是为了让用户知道此类故障。 s3-us-west-2.amazonaws.com/scaleyourcode/images/blog/redis/…
              • 尽管如此古老,但有义务补充说,如上所述,答案具有误导性。通过进入redis.conf 文件并将stop-writes-on-bgsave-error yes 更改为no,我能够修复问题中的给定错误。但是,除非您严格使用 redis 进行缓存和会话,否则我不会这样做。
              • 这显然会引发一些恢复问题,因为在没有快照的情况下会继续写入。
              • 这应该设置为“no” redis 127.0.0.1:6379> config set stop-writes-on-bgsave-error no
              猜你喜欢
              • 2018-01-09
              • 1970-01-01
              • 2019-01-02
              • 2020-05-23
              • 1970-01-01
              • 2013-11-04
              • 2016-02-15
              • 2020-06-29
              • 1970-01-01
              相关资源
              最近更新 更多