1、修复当AB故障切换一次后,mha-manager会自动退出
【只是基本实现,可以在我的基础上修改】
【nohup 后台一直执行】
vi /app/masterha/monitor.sh
#!/bin/bash
while :
do
mhapid=`ps -ef|grep -v grep|grep masterha_manager |wc -l`
echo "mhapid:" $mhapid
if [ $mhapid -eq 0 ];then
masterha_stop --conf=/etc/masterha/app1.cnf
masterha_manager --conf=/etc/masterha/app1.cnf --ignore_last_failover < /dev/null > /app/masterha/app1/app1.log 2>&1 &
/app/masterha/app1/add_ab.sh
mhapid=`ps -ef|grep -v grep|grep masterha_manager |wc -l`
if [ $mhapid -eq 0 ];then
masterha_stop --conf=/etc/masterha/app1.cnf
fi
fi
sleep 5
done
chmod +x /app/masterha/monitor.sh
二、修复原主库,出问题后,修复后不能自动加入现有AB集群
【只是基本实现,可以在我的基础上修改】
1、mha manager管理节点上创建脚本
vi /app/masterha/app1/add_ab.sh
#!/bin/bash
`awk -F: ‘/All other slaves should start replication from here. Statement should be:/{a=$4}END{print a}‘ /app/masterha/app1/app1.log |sed "s/xxx/lipengfei/" > /app/masterha/app1/cmd.txt`
master1="10.142.132.51"
master2="10.142.132.52"
new_master=$(awk ‘/as a new master./{a=$2}END{print a}‘ /app/masterha/app1/app1.log)
echo ‘the new master: ‘${new_master}
if [ "$master1" = "$new_master" ]
then
echo "the text scop begin :"${master2}
scp /app/masterha/app1/cmd.txt 10.142.132.52:/app/masterha/app1
else
echo "the text scop begin :"${master1}
scp /app/masterha/app1/cmd.txt 10.142.132.51:/app/masterha/app1
fi
chmod +x add_ab.sh
2、在 10.142.132.52 和10.142.132.51 上创建脚本
vi /app/masterha/app1/add_ab.sh
#!/bin/bash
MYSQL=/app/mysql/bin/mysql
MYSQL_HOST=localhost
MYSQL_USER=root
MYSQL_PASSWORD=mysql
myFile="/app/masterha/app1/cmd.txt"
lipengfei=$(cat /app/masterha/app1/cmd.txt)
echo "lipengfei:" $lipengfei
if [ ! -f "$myFile" ]
then
echo "the text is not exist, Don‘t do anything!!!!"
else
echo "the text is exist,add the AB!!!!"
$MYSQL -h $MYSQL_HOST -u $MYSQL_USER -p${MYSQL_PASSWORD} -e "stop slave;"
$MYSQL -h $MYSQL_HOST -u $MYSQL_USER -p${MYSQL_PASSWORD} -e "$lipengfei;"
echo $MYSQL -h $MYSQL_HOST -u $MYSQL_USER -p${MYSQL_PASSWORD} -e \"" $lipengfei\""
$MYSQL -h $MYSQL_HOST -u $MYSQL_USER -p${MYSQL_PASSWORD} -e "start slave;"
fi
chmod +x /app/masterha/app1/add_ab.sh
【nohup 后台一直执行】
vi /app/masterha/app1/monitor.sh
#!/bin/bash
while :
do
sh /app/masterha/app1/add_ab.sh
sleep 5
done
chmod +x /app/masterha/monitor.sh