针对于LVS分发MySQL的监控


需求:LVS给MySQL进行读负载,如果主从出现主从不同步,那就会出现问题,如何实现主从不同步的时候我就在LVS上去掉那台从库呢,而且如果当LVS上指负载一台从库的时候,我要是再去掉的话,岂不无从库可查了,故写个脚本,个人认为逻辑性还是很强的。

#!/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
                                              #sh /www/shell/syslog_2.sh $i-slave-stop `hostname` 1 2 1 6
                                              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
                                              # sh /www/shell/syslog_2.sh $i-slave-stop `hostname` 1 2 1 6
                                              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

通过LVS实现WEB站点的MySQL高可用

LVS+Apache+PHP+MySQL读写分离

MySQL LVS负载均衡

企业Web高可用集群实战之LVS+Keepalived+MySQL HA

相关内容