本文共 3279 字,大约阅读时间需要 10 分钟。
接着上篇博文MySQL之MHA+keepalived方案演示(四)中的MySQL的故障切换,当前主库变为了192.168.2.129机器,同时129机器上的keepalived服务被开启。然而192.168.2.128原来的主库被挂掉了,运行的keepalived也被停止了。重新启动192.168.2.128机器上的mysql,添加192.168.2.128机器上的mysql作为192.168.2.129新主库的slave从库.
查看 192.168.2.130 机器上的故障切换日志:
grep "MASTER_PASSWORD" /var/log/masterha/app1/manager.logSun Jul 1 17:04:32 2018 - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.2.129', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=154, MASTER_USER='repmha', MASTER_PASSWORD='xxx';
直接登陆192.168.2.128上的mysql,执行(切忌不要画蛇添足从129机器上dump出数据恢复到128机器这样的方式来做MySQL同步)
CHANGE MASTER TO MASTER_HOST='192.168.2.129', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=154, MASTER_USER='repmha', MASTER_PASSWORD='123456'; start slave;show master status\G
192.168.2.128源主库成功添加为129新主库的slave从库。
手动修改监控机 192.168.2.130配置文件app1.cnf
现在的配置文件如下:[root@server03 ~]# mkdir -p /etc/masterha[root@server03 masterha]# cat /etc/masterha/app1.cnf[server default]manager_log=/var/log/masterha/app1/manager.logmanager_workdir=/var/log/masterha/app1.logmaster_binlog_dir=/data/mysql/logs/bin-logmaster_ip_failover_script=/usr/local/bin/master_ip_failovermaster_ip_online_change_script=/usr/local/bin/master_ip_online_changepassword=123456ping_interval=1remote_workdir=/tmprepl_password=123456repl_user=repmhareport_script=/usr/local/bin/send_reportsecondary_check_script=/usr/local/bin/masterha_secondary_check -s server03 -s server02 --user=root --master_host=server02 --master_ip=192.168.2.128 --master_port=3306shutdown_script=""ssh_port=10280ssh_user=rootuser=monitor[server2]candidate_master=1check_repl_delay=0hostname=192.168.2.129port=3306[server3]hostname=192.168.2.130port=3306You have new mail in /var/spool/mail/root[root@server03 masterha]#
修改后的配置文件如下:
[root@server03 ~]# cat /etc/masterha/app1.cnf[server default]manager_log=/var/log/masterha/app1/manager.logmanager_workdir=/var/log/masterha/app1.logmaster_binlog_dir=/data/mysql/logs/bin-logmaster_ip_failover_script=/usr/local/bin/master_ip_failovermaster_ip_online_change_script=/usr/local/bin/master_ip_online_changepassword=123456ping_interval=1remote_workdir=/tmprepl_password=123456repl_user=repmhareport_script=/usr/local/bin/send_reportsecondary_check_script=/usr/local/bin/masterha_secondary_check -s server02 -s server03 --user=root --master_host=server03 --master_ip=192.168.2.129 --master_port=3306shutdown_script=""ssh_port=10280ssh_user=rootuser=monitor[server1]hostname=192.168.2.129port=3306[server2]candidate_master=1check_repl_delay=0hostname=192.168.2.128port=3306[server3]hostname=192.168.2.130port=3306
kill掉原来的监控进程
[root@server03 app1]# ps -ef|grep perlroot 47458 40702 0 15:29 pts/3 00:00:00 perl /usr/local/bin/masterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf --ignore_last_failoverroot 47604 40702 0 15:30 pts/3 00:00:00 grep perl[root@server03 app1]# kill -9 47458
重新启动masterha_manager
[root@server03 app1]# nohup masterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log 2>&1 & [1] 47458
到此处128原来的主MySQL成功的添加为129新主库的slave从库
转载于:https://blog.51cto.com/wujianwei/2142654