今天redis突然报错,启动不了了记录一下排错过程:
错误1
Connection refused - Unable to connect to Redis on localhost:6379
首先检查redis是否没有启动,通过如下命令即可
# ps aux | grep redis
错误2
Short read or OOM loading DB. Unrecoverable error, aborting now.
删除一下redis的db文件和进程文件,然后重启
# rm -rf /var/lib/redis/dump.rdb
# rm -rf /var/run/redis.pid
# service redis-server start
如果之前redis能正常运行,突然某天出问题了,以上2步应该能解决,多半是由于dump.rdb文件出错导致的
错误3
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.
照着提示在 /etc/sysctl.conf 增加一行试试
vm.overcommit_memory = 1
错误4
Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 3984.
可以做以下尝试:
在文件增加一行 /etc/sysctl.conf
net.core.somaxconn = 1024
打开文件 /etc/defaults/redis-server,将下面这行去掉注释,如果没有就新增
ULIMIT=65536
打开文件新增以下行 /etc/security/limits.conf
redis soft nofile 65536
redis hard nofile 65536
nginx soft nofile 262144
nginx hard no file 262144
参考:
https://community.nodebb.org/topic/1563/redis-advice-on-low-memory-system/7
https://blog.argcv.com/articles/3212.c
https://stackoverflow.com/questions/4670049/rescue-connection-refused-unable-to-connect-to-redis-on-localhost6379
https://stackoverflow.com/questions/19700404/short-read-or-oom-loading-db-unrecoverable-error-aborting-now