Redis 运行一段时间后报错导致挂掉,有什么办法解决呢? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Geekerstar
V2EX    Redis

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

  •  
  •   Geekerstar 197 天前 2771 次点击
    这是一个创建于 197 天前的主题,其中的信息可能已经有所发展或是发生改变。
    使用 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>
    第 1 条附言    196 天前
    感谢大家,在大家的提示下,我找到了问题原因:

    Redis 依赖 Linux 的内存过量提交机制( Memory Overcommit ),但当前系统 未启用 该机制,导致:

    后台保存( BGSAVE )或 AOF 持久化 可能失败。

    主从复制 可能失败。

    即使内存充足,也可能出现 OOM ( Out of Memory )相关错误,导致 Redis 启动失败或进程崩溃。


    具体解决方案 gpt 有提供
    10 条回复    2025-03-31 12:04:31 +08:00
    opengps
        1
    opengps  
       197 天前
    这提示看起来很明白了
    fcten
        2
    fcten  
       197 天前
    显示 aof 损坏是 redis 挂了的结果不是原因吧
    你找找挂掉时的日志,是不是 OOM 了
    Geekerstar
        3
    Geekerstar  
    OP
       197 天前
    @fcten redis 也会 OOM 吗?是通过 docker logs 看日志吗?日志好像没持久化到宿主机
    lasuar
        4
    lasuar  
       197 天前
    1. 你这台机运行了其他服务占用过多内存,把 redis 挤崩了。
    2. 文中提供的 issue 导致的。
    Geekerstar
        5
    Geekerstar  
    OP
       197 天前
    @lasuar 这台服务器 128g 内存,总内存只用了十多 G 呢?
    Geekerstar
        6
    Geekerstar  
    OP
       196 天前
    @fcten
    @lasuar
    @opengps 感谢,找到问题原因了
    SKYNE
        7
    SKYNE  
       196 天前
    看起来是 redis 在持久化 AOF 时异常停掉了,导致的 AOF 文件不完整,启动时就是这样的报错,查一下系统 message 中有没有有用的信息
    Geekerstar
        8
    Geekerstar  
    OP
       196 天前
    @SKYNE 我看报错的提示查了一下是因为操作系统没开启 Linux 的内存过量提交机制,导致 AOF 文件写失败
    SKYNE
        9
    SKYNE  
       196 天前
    看来 redis 日志的 WARNING 还是非常有用的
    julyclyde
        10
    julyclyde  
       196 天前
    overcommit 这一句是本轮启动开头的内容
    而 AOF 文件损坏其实是上一轮损坏的
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5940 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 03:02 PVG 11:02 LAX 20:02 JFK 23:02
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86