针对于lvs分发mysql的监控

#!/bin/bash


c=`cat /opt/duoyongtu/10/mysql.txt`

for i in $c

do

   a=`mysql -uroot -h$i -p12345678 -P3306 -e "show slave status\G"|egrep '(Slave_IO_Running|Slave_SQL_Running)'|awk '{print $NF}'`

         for k in $a

         do

             if [ "$k" != "Yes" ]; then

                   f=`ssh 192.168.0.146 "ip a|grep 192.168.1.5|wc -l"`

                   if [ "$f" -eq 1 ]; then

                   b=`ssh 192.168.0.146 "cat /opt/yanchao/xianzai.txt| wc -l"`

if [ "$b" -ge 2 ]; then

ssh $i "iptables -A INPUT -s 192.168.0.146 -p tcp -m tcp --dport 3306 -j DROP"

ssh $i "iptables -A INPUT -s 192.168.0.147 -p tcp -m tcp --dport 3306 -j DROP"

echo bad

else

echo good

fi

else

b=`ssh 192.168.0.147 "cat /opt/yanchao/xianzai.txt| wc -l"`

                        if [ "$b" -ge 2 ]; then

ssh $i "iptables -A INPUT -s 192.168.0.146 -p tcp -m tcp --dport 3306 -j DROP"

                                ssh $i "iptables -A INPUT -s 192.168.0.147 -p tcp -m tcp --dport 3306 -j DROP"

                                      echo bad

                         else

                                      echo good

fi

fi

             else

                         d=`ssh $i "iptables -L -n|grep 192.168.0.146|wc -l"`

                         if [ "$d" -ge 1 ]; then 

                              for e in 192.168.0.146 192.168.0.147

                              do

                                    ssh $i "iptables -F"

                              done

                         fi

             fi

        done

done


你可能感兴趣的:(mysql,status,监控)