009.MySQL-Keepalived搭配指令碼03
阿新 • • 發佈:2018-11-05
1 vim /etc/keepalived/check_MySQL.sh 2 #vim #!/bin/bash 3 MYSQL=/usr/local/mysql/bin/mysql 4 MYSQL_HOST=localhost 5 MYSQL_USER=root 6 MYSQL_PASSWORD= 7 CHECK_TIME=3 8 #mysql is working MYSQL_OK is 1 , mysql down MYSQL_OK is 0 9 MYSQL_OK=1 10 function check_mysql_helth (){ 11 $MYSQL -h $MYSQL_HOST -u $MYSQL_USER -e "show status;" >/dev/null 2>&1 12 if [ $? = 0 ] ;then 13 MYSQL_OK=1 14 else 15 MYSQL_OK=0 16 fi 17 return $MYSQL_OK 18 } 19 while [ $CHECK_TIME -ne 0 ] 20 do 21 let "CHECK_TIME -= 1" 22 check_mysql_helth 23 if [ $MYSQL_OK = 1 ] ; then 24 CHECK_TIME=0 25exit 0 26 fi 27 if [ $MYSQL_OK -eq 0 ] && [ $CHECK_TIME -eq 0 ] 28 then 29 /etc/init.d/keepalived stop 30 exit 1 31 fi 32 sleep 1 33 done