使用 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
错误将不再引发。