1.VIP漂移的两种方式
1.keeplaived的方式
2.MHA自带的脚本进行VIP漂移
2.配置MHA读取VIP漂移脚本
#编辑配置文件
[root@db03 ~]# vim /service/mha/app1.cnf
#在[server default]标签下添加
[server default]
#使用MHA自带脚本
master_ip_failover_script=/service/mha/master_ip_failover
3.编写脚本
# 默认脚本存放在
[root@db01 ~]# ll mha4mysql-manager-0.56/samples/scripts/
total 32
-rwxr-xr-x 1 4984 users 3648 Apr 1 2014 master_ip_failover
# 上传现成的脚本
# 编辑脚本
[root@db03 mha]# vim master_ip_failover
.......
my $vip = '172.16.1.50/24';
my $key = '1';
my $ssh_start_vip = "/sbin/ifconfig eth1:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig eth1:$key down";
......
4.手动绑定VIP
[root@db01 ~]# ifconfig eth1:1 172.16.1.50/24
[root@db01 ~]# ip a
3: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:2c:76:88 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.51/24 brd 172.16.1.255 scope global noprefixroute eth1
valid_lft forever preferred_lft forever
inet 172.16.1.50/24 brd 172.16.1.255 scope global secondary eth1:1
# 解绑VIP
[root@db01 ~]# ifconfig eth1:1 [172.16.1.50] down
#### 5.重启MHA
# 检测主从
[root@db03 ~]# masterha_check_repl --conf=/service/mha/app1.cnf
MySQL Replication Health is OK.
# 启动MHA
[root@db03 mha]# nohup masterha_manager --conf=/service/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /service/mha/manager.log 2>&1 &
#启动失败:
1.检查配置文件语法是否正确
2.授权是否正确
[root@db03 mha]# chmod 755 master_ip_failover
3.脚本格式要正确
[root@db03 mha]# dos2unix master_ip_failover
dos2unix: converting file master_ip_failover to Unix format ...
6.测试VIP漂移
#停止主库
[root@db01 ~]# systemctl stop mysqld.service
#查看切换成主库的ip地址
[root@db02 ~]# ip a
3: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:3e:56:1f brd ff:ff:ff:ff:ff:ff
inet 172.16.1.52/24 brd 172.16.1.255 scope global noprefixroute eth1
valid_lft forever preferred_lft forever
inet 172.16.1.50/24 brd 172.16.1.255 scope global secondary eth1:1
valid_lft forever preferred_lft forever
inet6 fe80::de8c:34e1:563e:9f2b/64 scope link tentative noprefixroute dadfailed
valid_lft forever preferred_lft forever
inet6 fe80::a3a8:499:ce26:b3be/64 scope link noprefixroute
valid_lft forever preferred_lft forever