keepalived 检测脑裂切换脚本
#!/bin/bash count=0 run1=`curl -I 192.168.30.12:8000 | grep "200 OK" | wc -l` run2=`curl -I 192.168.30.12:8020 | grep "200 OK" | wc -l` run3=`curl -I 192.168.30.12:8080 | grep "200 OK" | wc -l` run=$[$run1 + $run2 + $run3] for (( k=0; k<10; k++ )) ; do /usr/bin/mysql -uroot -p'123456!' -h'192.168.30.21' -e "show databases;" > /dev/null if [ $? != 0 ];then echo "mysql faild !" >> /etc/keepalived/keepalived.log break fi if [ $run -ne 3 ] ; then sleep 2 /etc/init.d/httpd start run1=`curl -I 192.168.30.12:8000 | grep "200 OK" | wc -l` run2=`curl -I 192.168.30.12:8020 | grep "200 OK" | wc -l` run3=`curl -I 192.168.30.12:8080 | grep "200 OK" | wc -l` run=$[$run1 + $run2 + $run3] count=$(($count+1)) echo "httpd start $count faild !" >> /etc/keepalived/keepalived.log else #echo "httpd start $count ok !" >> /etc/keepalived/keepalived.log break fi if [ "$count" == "9" ]; then /etc/init.d/keepalived stop echo “192.168.30.12 keepalived changed” | mail -s "keepalived changd" team_cloud_service@syberos.com echo "keepalived change !" >> /etc/keepalived/keepalived.log break fi done