redis突然掉电导致aof文件损坏修复一例

公司一批服务器突然掉电宕机,一通折腾后,发现redis未开启,去服务器启动redis,其中一台在将aof文件load进内存的时候,中断,总不能开启!

现象是,load一段时间之后,redis进程自动关闭!

查看日志文件,发现有如下内容:

[2716] 28 Apr 10:16:51.234 # Server started, Redis version 2.8.8
[2716] 28 Apr 10:16:51.234 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. 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.
[2716] 28 Apr 10:17:27.915 # Bad file format reading the append only file: make a backup of your AOF file, then use ./redis-check-aof --fix <filename>
[2761] 28 Apr 10:19:40.866 * Increased maximum number of open files to 10032 (it was originally set to 1024).

发现是aof文件损坏。

去redis数据目录,将aof文件备份,用redis-check-aof工具修复

[root@db redis]# cp appendonly.aof appendonly.aof.bak
[root@db redis]# redis-check-aof --fix appendonly.aof
0x        c93488e5: Expected prefix '
AOF analyzed: size=3375772775, ok_up_to=3375663333, diff=109442
This will shrink the AOF from 3375772775 bytes, with 109442 bytes, to 3375663333 bytes
Continue? [y/N]: y
Successfully truncated AOF

重新启动,发现redis启动完成!

投入生产,正常使用!


你可能感兴趣的:(redis,redis启动,aof文件损坏)