标签:文件 mysqld 数据库 null 主机 amp grep sql ash
[root@db02 ~]# vim start_mha.sh
#/bin/bash
# 判断数据库是否挂掉
mysql_pid=`ps -ef | grep [m]ysqld | wc -l`
# 如果挂掉则重启,如果没挂则杀掉重启
if [ $mysql_pid -eq 0 ];then
systemctl start mysqld
else
systemctl restart mysqld
fi
sleep 3
# 获取change master to语句
change=`ssh 172.16.1.53 "grep ‘CHANGE MASTER TO‘ /service/mha/manager | tail -1 | sed ‘s#xxx#123#g‘" | awk -F: ‘{print $4}‘` &&
# 重启的数据库执行change master to
mysql -e "$change;start slave"
# 修复MHA配置文件
ssh 172.16.1.53 "\cp /service/mha/app1.cnf.bak /service/mha/app1.cnf" &&
# 远程启动MHA
ssh 172.16.1.53 "/bin/bash /root/start_bin.sh"
[root@db03 ~]# vim start_bin.sh
#/bin/bash
# 获取主机地址
mha_master_host=`grep ‘as a new master‘ /service/mha/manager | tail -1 | awk -F "[ ,(]" ‘{print $2}‘`
# 启动保存binlog
cd /root/binlog/
nohup mysqlbinlog -R --host="$mha_master_host" --user=mha --password=mha --raw --stop-never mysql-bin.000001 >/dev/null &
# 启动MHA
nohup masterha_manager --conf=/service/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /service/mha/manager.log 2>&1 &
标签:文件 mysqld 数据库 null 主机 amp grep sql ash
原文地址:https://www.cnblogs.com/Applogize/p/13399271.html