1. 程式人生 > >007.MySQL-Keepalived搭配指令碼01

007.MySQL-Keepalived搭配指令碼01

  1 vim /etc/keepalived/check_MySQL.sh
  2 #!/bin/bash
  3 MYSQL=/usr/bin/mysql
  4 MYSQL_HOST=localhost
  5 MYSQL_USER=root
  6 CHECK_COUNT=5
  7 counter=1
  8 while true
  9 do
 10         mysql -h $MYSQL_HOST -u $MYSQL_USER -e "show status;"  >/dev/null 2>&1
 11         i=$?
 12         ps aux | grep mysqld | grep -v grep > /dev/null
2>&1 13 j=$? 14 if [ $i = 0 ] && [ $j = 0 ] 15 then 16 exit 0 17 else 18 if [ $i = 1 ] && [ $j = 0 ] 19 then 20 exit 0 21 else 22 if
[ $counter -gt $CHECK_COUNT ] 23 then 24 break 25 fi 26 let counter++ 27 continue 28 fi 29 fi 30 done 31 /etc/init.d/keepalived stop 32 exit 1