1. 程式人生 > >MySQL之MHA+keepalived方案演示(五)

MySQL之MHA+keepalived方案演示(五)

word [1] send ali etc cond 博文 lin app

接著上篇博文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.log
Sun 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.log
manager_workdir=/var/log/masterha/app1.log
master_binlog_dir=/data/mysql/logs/bin-log
master_ip_failover_script=/usr/local/bin/master_ip_failover
master_ip_online_change_script=/usr/local/bin/master_ip_online_change
password=123456
ping_interval=1
remote_workdir=/tmp
repl_password=123456
repl_user=repmha
report_script=/usr/local/bin/send_report
secondary_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=3306
shutdown_script=""
ssh_port=10280
ssh_user=root
user=monitor

[server2]
candidate_master=1
check_repl_delay=0
hostname=192.168.2.129
port=3306

[server3]
hostname=192.168.2.130
port=3306
You 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.log
manager_workdir=/var/log/masterha/app1.log
master_binlog_dir=/data/mysql/logs/bin-log
master_ip_failover_script=/usr/local/bin/master_ip_failover
master_ip_online_change_script=/usr/local/bin/master_ip_online_change
password=123456
ping_interval=1
remote_workdir=/tmp
repl_password=123456
repl_user=repmha
report_script=/usr/local/bin/send_report
secondary_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=3306
shutdown_script=""
ssh_port=10280
ssh_user=root
user=monitor

[server1]
hostname=192.168.2.129
port=3306

[server2]
candidate_master=1
check_repl_delay=0
hostname=192.168.2.128
port=3306

[server3]
hostname=192.168.2.130
port=3306

kill掉原來的監控進程

[root@server03 app1]# ps -ef|grep perl
root      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_failover
root      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從庫

MySQL之MHA+keepalived方案演示(五)