Recently made by oneself keepalive detection mechanism, directly on the latest optimized script: ########### #start scriptskillall -0 redis-serverif [ "$?" -eq 0 ]; then echo good exit 0else 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 fifi########### #end scripts Current judgment is: The first layer: retry two times process signal judgment. Second layer: netstat and ps -ef judgment of the third layer: /etc/init.d/redis status return code. Fourth level: redis ping return code judgment. Each of these layers fails, and the log is printed. After the failure, the Redis process and business access problems, formally start the switchover operation. Test the environment to test the effect. Log records: [Check_fail_log]thu may 19 09:46:23 cst 2016killall_bad_twoprocess_bad_ Threestatus_bad_fourredis-server is stoppedping_bad_five
This article is from the Linux system maintenance blog, so be sure to keep this source http://linuxadmin.blog.51cto.com/2683824/1774987
Redis and keepalive, detection mechanism revision