redis与keepalive合用,检测机制修订
近期又被自己造的keepalive检测机制搞了,直接上最新优化后的脚本:############start scripts
killall -0 redis-server
if [ "$?" -eq 0 ]; then
echo good
exit 0
else
LOGFILE=/var/log/keepalived-redis-state.log
echo "" >> $LOGFILE
date >> $LOGFILE
killall -0 redis-server
if [ "$?" -ne 0 ]; then
echo killall_bad_two >> /var/log/keepalived-redis-state.log
numprocess1=`netstat -tnpl | grep 6379 -c`
numprocess2=`ps -ef | grep redis-server | grep -c 6379`
if [[ ${numprocess1} -lt 1 ]] && [[ ${numprocess2} -lt 1 ]]; then
echo process_bad_three >> /var/log/keepalived-redis-state.log
#start judge status
/etc/init.d/redis status
if [[ $? -eq 0 ]]; then
echo good
exit 0
else
echo status_bad_four >> /var/log/keepalived-redis-state.log
/etc/init.d/redis status >> /var/log/keepalived-redis-state.log
####start last judge
ALIVE=`/usr/bin/redis-cli -p 6379 PING`
if [ "$ALIVE" != "PONG" ]; then
echo ping_bad_five >> /var/log/keepalived-redis-state.log
exit 1
else
exit 0
fi
###end last judge
fi
#end judge status
else
exit 0
fi
else
exit 0
fi
fi
############end scripts
目前的判断为:
第一层: 重试两次 进程信号判断。
第二层: netstat 及 ps -ef 判断
第三层: /etc/init.d/redis status 返回码判断。
第四层: redis ping 返回码判断。
以上每一层失败,都会打印日志。失败后说明redis进程及业务访问出现问题,正式开始启动切换操作。
测试环境测试效果。
日志记录:
Thu May 19 09:46:23 CST 2016
killall_bad_two
process_bad_three
status_bad_four
redis-server is stopped
ping_bad_five
页:
[1]