现象
启动redis-server无提示,但是使用redis-cli连接时出现Could not connect to Redis at 127.0.0.1:6379: Connection refused
查看系统日志:
$ cat /var/log/redis/redis.log
[50234] 15 Apr 07:51:39 * Server started, Redis version 2.4.10
[50234] 15 Apr 07:51:39 # 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.
[50234] 15 Apr 07:51:39 # Can't handle RDB format version 7
[50234] 15 Apr 07:51:39 # Fatal error loading the DB. Exiting.
原因
一般是低版本无法兼容高版本的 rdb 导致的。因为我Docker里面的redis版本较高,和服务器redis共用。
解决
# 查找 redis生成的dump.rdb文件进行删除,再启动 redis-server。
$ find / -name "dump.rdb"
$ sudo rm /var/lib/redis/dump.rdb
$ systemctl start redis