今早还才7点钟,公司说app挂了,相关开发瞬间绷起神经,一时间群魔乱舞,最终到我这儿需要重新启动redis,于是乎我到公司第一件事就是查看关于redis的问题。

开机,xhell连上服务器,网速太慢,xhell卡顿,以为网速问题,打开宝塔,宝塔界面正常打开,里面的redis点击重启,重启失败,重新加载配置,失败,启动,毫无疑问,依然失败。那么问题就只能在服务器里看了。
于是开始我排错步骤:
第一步:启动redis的同时,查找日志。
悲剧的是redis没有启动日志,找到redis的配置文件,添加启动日志文件。
logfile "/www/server/redis/redis.log"

redis启动失败的排查

此时,重新启动redis,查看日志
26655:M 14 Oct 2019 09:34:28.182 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
26655:M 14 Oct 2019 09:34:28.182 # Server initialized
26655:M 14 Oct 2019 09:34:28.182 # WARNING overcommit_memory is set to 0! Background savemay 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.
26655:M 14 Oct 2019 09:34:28.182 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' asroot, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
26655:M 14 Oct 2019 09:34:28.182 Reading RDB preamble from AOF file...
26655:M 14 Oct 2019 09:34:28.189
Reading the remaining AOF tail...
26655:M 14 Oct 2019 09:34:28.189 # Unknown command 'DEL' reading the append only file
28784:C 14 Oct 2019 09:39:40.176 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
28784:C 14 Oct 2019 09:39:40.176 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=28784, just started

在服务器上做如下操作:

echo 1 > /proc/sys/vm/overcommit_memory
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
echo never > /sys/kernel/mm/transparent_hugepage/enabled

重启redis之后依然有报错,针对/proc/sys/net/core/somaxconn is set to the lower value of 128这个做了是
在/etc/sysctl.conf中添加如下

net.core.somaxconn = 2048

然后在终端中执行

sysctl -p

redis启动失败的排查
随后发现还是有一个问题:
Unknown command 'DEL' reading the append only file
我在配置文件中找到了这行,并查找了原因,是这样解释的,

为了redis cluster禁用一些危险命令,使用的方法都是在配置文件中增加以下内容:

rename-command flushall hufuflushall
rename-command flushdb hufuflushdb
rename-command keys hufukeys

这就带来了问题,在服务器以外重启后,会造成cluster中redis服务启动不了,而且还会报“ Unknown command 'flushall' reading the append only file”。通常的做法关闭启动不了服务的持久化配置“appendonly no”。然后再启动redis实例服务。但会遇到以下问题,连接cluster服务时会提示cluster不可用。这时redis-trib.rb的作用就体现出了,执行fix操作集群服务就能恢复了。但修改持久配置的结果是,再发生关机操作或意外,redis数据就找不回来了。这时还是用redis-trib.rb的add功能为出问题的redis实例增加slave,再通过failover的方式进行master与slave的切换。
那么我想不如注释一下试试。
redis启动失败的排查_第1张图片

之后,突然间redis就启动了!!!!
如图:
redis启动失败的排查

小错误总结:看日志,看日志,看日志,重要的事情说三遍!!!