自己搭建的MHA+Keepalived+VIP,其中在测试主master宕掉后看备是否接管和VIP是否自动飘移时,发现keepalived随着主master上的mysql宕掉后,keepalived进程也随着宕掉,但是发现一个奇怪的问题,VIP并没有飘走,并且备master上的VIP也同时起来了,即有两个VIP同时存在!
我的主和备的keepalive配置文件如下:
主master上的keepalive:
[root@lf-319-161 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_FTP {
state BACKUP
interface bond0
virtual_router_id 247
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.191.22.247
}
}
virtual_server 10.191.22.247 3306 {
delay_loop 30
lb_algo rr
lb_kind DR
# persistence_timeout 30
protocol TCP
real_server 10.191.22.136 3306 {
weight 1
notify_down /root/kpchange/mysql_down.sh
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
备master上的keepalive:
[root@lf-319-162 ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_FTP {
state BACKUP
interface bond0
virtual_router_id 247
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.191.22.247
}
}
virtual_server 10.191.22.247 3306 {
delay_loop 30
lb_algo rr
lb_kind DR
# persistence_timeout 30
protocol TCP
real_server 10.191.22.137 3306 {
weight 1
notify_down /root/kpchange/mysql_down.sh
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
正常keepalive服务上的VIP是随着keepalived的进程状态进行飘移的,但是VIP并没有飘移。
我的解决办法:
(1)将主和备的keepalived服务都关闭。
service keepalived stop
(2)发现主上的VIP一直没有消除
(3)手动将主上的VIP给去掉
ip addr del 10.191.22.247/32 dev bond0
最后重新启动keepalived服务,VIP能正常切换了。
补充:最后发现VIP不释放的最终原因了,是由于MHA切换脚本写得不对,将它更改后,再次主备切换时,VIP都能正常漂移了,具体的切换代码为:
[mysql@lf-319-163 bin]$ more master_ip_failover
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use Getopt::Long;
my (
$command, $ssh_user, $orig_master_host, $orig_master_ip,
$orig_master_port, $new_master_host, $new_master_ip, $new_master_port
);
my $vip = '10.191.22.247';
#my $ssh_start_vip ="sudo service keepalived start";
my $ssh_start_vip ="sudo ip addr add 10.191.22.247/32 dev bond0";
#my $ssh_stop_vip ="sudo service keepalived stop";
my $ssh_stop_vip ="sudo ip addr del 10.191.22.247/32 dev bond0";
注意点:
当旧master挂掉后,它上面的keepalive进程也会跟着挂掉。所以,当将旧master重新启动的时候,一定要先将旧master给启动,然后再启动上面的keepalive服务,否则keepalive会由于监控不到3306端口而进入“自杀”模式。