Requirement: LVS performs read load on MySQL. If the master and slave nodes are not synchronized, the problem may occur, how can I remove the slave database from LVS when the master node is not synchronized? And if I remove the slave database when the LVS server loads one slave database, there is no way to check the database, so I write a script, and I think the logic is strong.
#! /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 $
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
Implement MySQL high availability for WEB sites through LVS
LVS + Apache + PHP + MySQL read/write splitting
MySQL LVS Server Load balancer
Enterprise Web high availability cluster practice-LVS + Keepalived + MySQL HA