Redis 故障恢复

案例一、

ResponseError: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk.

Commands that may modify the data set are disabled. Please check Redis logs for details about the error.
Redis被配置为保存数据库快照,但它目前不能持久化到硬盘。用来修改集合数据的命令不能用。请查看Redis日志的详细错误信息。
原因:强制关闭redis快照导致不能持久化

解决方案:
将:stop-writes-on-bgsave-error 设置为 no

案例二、

logstash 连接redis失败

[WARN ][logstash.outputs.redis   ] Failed to send event to Redis {:event=>#<LogStash::Event:0x63169a41>, :identity=>"redis://@172.31.8.107:6379/0 list:nginx-access", :exception=>#<Redis::CannotConnectError: Error connecting to Redis on 172.31.8.107:6379 (Errno::ECONNREFUSED)>, :backtrace=>["/software/logstash-6.2.2/vendor/bundle/jruby/2.3.0/gems/redis-3.3.5/lib/redis/client.rb:345:in `establish_connection'", "/software/logstash-6.2.2/vendor/bundle/jruby/2.3.0/gems/redis-3.3.5/lib/redis/client.rb:101:in `block in connect

redis现在的版本开启redis-server后,redis-cli只能访问到127.0.0.1,因为在配置文件中固定了ip,因此需要修改redis.conf

# bind 192.168.1.100 10.0.0.1
#bind 127.0.0.1      
#
# 
~~~ If the computer running Redis is directly exposed to the
1
2
3
4
5
6
7
8
9
10
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1 --- 此处写本机IP地址

重启redis,进行连接测试

/software/redis/bin/redis-cli -h 172.31.8.107 -p 6379

如果出现如下,则表明连接成功

172.31.8.107:6379>

案例三

Redis 运行一段时间之后会报错:Background saving terminated by signal

5473:M 01 Aug 2019 15:50:23.601 # Background saving terminated by signal 9
5473:M 01 Aug 2019 15:50:24.002 * 10000 changes in 60 seconds. Saving...
5473:M 01 Aug 2019 15:50:24.021 * Background saving started by pid 7208
5473:M 01 Aug 2019 15:50:27.208 # Background saving terminated by signal 9
5473:M 01 Aug 2019 15:50:30.081 * 10000 changes in 60 seconds. Saving...
5473:M 01 Aug 2019 15:50:30.093 * Background saving started by pid 7234
5473:M 01 Aug 2019 15:50:32.218 # Background saving terminated by signal 9
5473:M 01 Aug 2019 15:50:36.064 * 10000 changes in 60 seconds. Saving...
5473:M 01 Aug 2019 15:50:36.076 * Background saving started by pid 7236
5473:M 01 Aug 2019 15:50:36.293 # Background saving terminated by signal 9

问题原因:
还未定位到具体的原因

决绝办法:

1、加内存(如果已经充分利用了Redis的存储结构来保存了最适合的数据,即Redis层已经最优了,不然的话,需要先优化Redis层)
2、将Redis的Maxmemory调到物理内存的3/5,并且将overcommit_memory=1,这样子虽然可以避免OOM,但是内存是redis运行的瓶颈了。

案例四

故障报错:

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' as root, 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.

内核启用THP可能会导致内存使用问题

解决办法:

临时解决:
echo never > /sys/kernel/mm/transparent_hugepage/enabled

永久:
将如下代码写入: /etc/rc.local 文件中

if test -f /sys/kernel/mm/redhat_transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/redhat_transparent_hugepage/enabled
fi

保存后重启redis

-------------本文结束感谢您的阅读-------------
请我吃辣条
0%