MHA 的vip功能
修改脚本内容
[root@db03 bin]# vi /usr/local/bin/master_ip_failover my $vip = '10.0.0.205/24'; ###同一网段,不能占用 my $key = '1';####相当于设置系统临时地址(ifconfig eth0:1 10.0.0.205/24),取消ifconfig eth0:1 down my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip"; my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down"; [root@db03 bin]# chmod +x /usr/local/bin/master_ip_failover ####添加权限 [root@db03 bin]# dos2unix /usr/local/bin/master_ip_failover 去除脚本中的中文字符
更改manager配置文件
vi /etc/mha/app1.cnf 添加: master_ip_failover_script=/usr/local/bin/master_ip_failover
主库上,手工生成第一个vip地址
手工在主库上绑定vip,注意一定要和配置文件中的ethN一致,我的是eth0:1(1是key指定的值) [root@db02 ~]# ifconfig eth0:1 10.0.0.205/24 [root@db02 ~]# ip a 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 inet 10.0.0.205/24 brd 10.0.0.255 scope global secondary eth0:1 valid_lft forever preferred_lft forever
重启mha
[root@db03 bin]#masterha_stop --conf=/etc/mha/app1.cnf [root@db03 bin]#nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/mha/app1/manager.log 2>&1 & [root@db03 ~]# masterha_check_status --conf=/etc/mha/app1.cnf
VIP故障模拟及恢复
故障模拟
[root@db02 ~]# pkill mysql [root@db01 ~]# ifconfig eth0:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.0.205 netmask 255.255.255.0 broadcast 10.0.0.255 db03 [(none)]>show slave status \G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.0.0.200
故障恢复
[root@db02 ~]# systemctl start mysqld [root@db03 bin]# cat /var/log/mha/app1/manager CHANGE MASTER TO MASTER_HOST='10.0.0.200', MASTER_PORT=3306, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123'; db02 [(none)]>CHANGE MASTER TO MASTER_HOST='10.0.0.200', MASTER_PORT=3306, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123'; db02 [(none)]>start slave; [root@db03 bin]# vim /etc/mha/app1.cnf 添加 [server2] hostname=10.0.0.201 port=3306
重启mha
[root@db03 bin]#nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/mha/app1/manager.log 2>&1 & [root@db03 ~]# masterha_check_status --conf=/etc/mha/app1.cnf