公司一批服務器突然掉電宕機,一通折騰後,發現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啓動完成!
投入生產,正常使用!