Redis 运行一段时间后报错导致挂掉,有什么办法解决呢?

215 天前
 Geekerstar
使用 docker 安装的 Redis ,版本 7.4.1 ,挂载 config 和 data 文件夹到宿主机,运行一段时间(一个月)后突然发现挂掉了,查看日志有如下信息,看上去像是 aof 文件损坏,如何避免这个问题呢?

1:C 31 Mar 2025 10:15:53.909 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:C 31 Mar 2025 10:15:53.909 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 31 Mar 2025 10:15:53.909 * Redis version=7.4.1, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 31 Mar 2025 10:15:53.909 * Configuration loaded
1:M 31 Mar 2025 10:15:53.909 * monotonic clock: POSIX clock_gettime
1:M 31 Mar 2025 10:15:53.910 # Failed to write PID file: Permission denied
1:M 31 Mar 2025 10:15:53.910 * Running mode=standalone, port=6379.
1:M 31 Mar 2025 10:15:53.910 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 31 Mar 2025 10:15:53.910 * Server initialized
1:M 31 Mar 2025 10:15:53.910 * Reading RDB base file on AOF loading...
1:M 31 Mar 2025 10:15:53.910 * Loading RDB produced by version 7.4.1
1:M 31 Mar 2025 10:15:53.910 * RDB age 159448 seconds
1:M 31 Mar 2025 10:15:53.910 * RDB memory usage when created 3.08 Mb
1:M 31 Mar 2025 10:15:53.910 * RDB is base AOF
1:M 31 Mar 2025 10:15:53.915 * Done loading RDB, keys loaded: 1103, keys expired: 0.
1:M 31 Mar 2025 10:15:53.916 * DB loaded from base file appendonly.aof.12754.base.rdb: 0.006 seconds
1:M 31 Mar 2025 10:15:54.042 # Bad file format reading the append only file appendonly.aof.12754.incr.aof: make a backup of your AOF file, then use ./redis-check-aof --fix <filename.manifest>
2876 次点击
所在节点    Redis
10 条回复
opengps
215 天前
这提示看起来很明白了
fcten
215 天前
显示 aof 损坏是 redis 挂了的结果不是原因吧
你找找挂掉时的日志,是不是 OOM 了
Geekerstar
215 天前
@fcten redis 也会 OOM 吗?是通过 docker logs 看日志吗?日志好像没持久化到宿主机
lasuar
215 天前
1. 你这台机运行了其他服务占用过多内存,把 redis 挤崩了。
2. 文中提供的 issue 导致的。
Geekerstar
215 天前
@lasuar 这台服务器 128g 内存,总内存只用了十多 G 呢?
Geekerstar
215 天前
@fcten
@lasuar
@opengps 感谢,找到问题原因了
SKYNE
215 天前
看起来是 redis 在持久化 AOF 时异常停掉了,导致的 AOF 文件不完整,启动时就是这样的报错,查一下系统 message 中有没有有用的信息
Geekerstar
214 天前
@SKYNE 我看报错的提示查了一下是因为操作系统没开启 Linux 的内存过量提交机制,导致 AOF 文件写失败
SKYNE
214 天前
看来 redis 日志的 WARNING 还是非常有用的
julyclyde
214 天前
overcommit 这一句是本轮启动开头的内容
而 AOF 文件损坏其实是上一轮损坏的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://ex.noerr.eu.org/t/1122194

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX