码迷,mamicode.com
首页 > 其他好文 > 详细

redis与keepalive合用,检测机制修订

时间:2016-05-19 13:25:49      阅读:357      评论:0      收藏:0      [点我收藏+]

标签: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 "[check_fail_log]" >> $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进程及业务访问出现问题,正式开始启动切换操作。
测试环境测试效果。
日志记录:
[check_fail_log]
Thu May 19 09:46:23 CST 2016
killall_bad_two
process_bad_three
status_bad_four
redis-server is stopped
ping_bad_five


本文出自 “linux系统维护” 博客,请务必保留此出处http://linuxadmin.blog.51cto.com/2683824/1774987

redis与keepalive合用,检测机制修订

标签:redis 与keepalive合用   检测机制修订   

原文地址:http://linuxadmin.blog.51cto.com/2683824/1774987

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!