LVS+keepalived+MYSQL 双机主备下备机 telnet 不通 VIP的 3306端口
双机主备: LVS+keepalived+MYSQL 高可用方案
方案:
两台机器,都安装MYSQL和keepalived,一台机器做主keepalived,一台备keepalived,mysql为主主同步,两台机器的mysql连接同一个虚拟IP(配置文件在
最下方)
说明:
正常情况下虚拟VIP绑定到主机上,当主机MYSQL挂了之后,keepalived检查到mysql挂了则执行脚本check_mysql.sh,脚本执行会关闭主机keepalived进程,
此时VIP自动漂移到备机上
问题:
在Red Hat Enterprise Linux Server release 6.7 (Santiago)版本上如下配置,一切正常,主备机器的都能telnet通VIP地址 +3306端口,而且mysql挂了之
后,该服务器的keepalived自动检查mysql状态,然后执行脚本check_mysql.sh
但是在系统Red Hat Enterprise Linux Server release 7.2版本下,其他配置都一样,备机就不能 telnet通VIP地址 +3306端口,即不能通过虚拟IP连接到
mysql服务,但是却能ping通VIP地址;然后我用另一台同一网段的没有安装keepalived的服务器 telnet通VIP地址 +3306端口,也是能通。
解决:
有人通过注释掉备机的virtual_server中的两个参数后可以telnet通VIP地址 +3306端口
#lb_algo wrr
#lb_kind DR
验证:
我注释两个参数后,备机的确能 telnet通VIP地址 +3306端口,但是又出现另外的问题,即当mysql挂了之后,该服务器的keepalived自动检查mysql状态,发
现mysql挂了之后正常情况下应该执行脚本check_mysql.sh,但是实际上却不执行这个脚本。查看系统日志如下
系统日志如下:
Feb 9 19:49:02 SZC-L0040683 Keepalived_healthcheckers[59739]: TCP connection to [30.16.10.135]:3306 failed.
Feb 9 19:49:05 SZC-L0040683 Keepalived_healthcheckers[59739]: TCP connection to [30.16.10.135]:3306 failed.
Feb 9 19:49:05 SZC-L0040683 Keepalived_healthcheckers[59739]: Check on service [30.16.10.135]:3306 failed after 1 retry.
Feb 9 19:49:05 SZC-L0040683 Keepalived_healthcheckers[59739]: Removing service [30.16.10.135]:3306 from VS [30.16.11.54]:3306
Feb 9 19:49:05 SZC-L0040683 Keepalived_healthcheckers[59739]: IPVS: Service not defined
Feb 9 19:49:05 SZC-L0040683 Keepalived_healthcheckers[59739]: Remote SMTP server [127.0.0.1]:25 connected.
Feb 9 19:49:05 SZC-L0040683 Keepalived_healthcheckers[59739]: SMTP alert successfully sent.
Feb 9 19:49:07 SZC-L0040683 Keepalived_healthcheckers[59739]: TCP connection to [30.16.10.135]:3306 failed.
Feb 9 19:49:10 SZC-L0040683 Keepalived_healthcheckers[59739]: TCP connection to [30.16.10.135]:3306 failed.
Feb 9 19:49:10 SZC-L0040683 Keepalived_healthcheckers[59739]: Check on service [30.16.10.135]:3306 failed after 1 retry.
Feb 9 19:49:10 SZC-L0040683 Keepalived_healthcheckers[59739]: Removing service [30.16.10.135]:3306 from VS [30.16.11.54]:3306
Feb 9 19:49:10 SZC-L0040683 Keepalived_healthcheckers[59739]: IPVS: Service not defined
Feb 9 19:49:10 SZC-L0040683 Keepalived_healthcheckers[59739]: Remote SMTP server [127.0.0.1]:25 connected.
Feb 9 19:49:10 SZC-L0040683 Keepalived_healthcheckers[59739]: SMTP alert successfully sent.
Feb 9 19:49:12 SZC-L0040683 Keepalived_healthcheckers[59739]: TCP connection to [30.16.10.135]:3306 failed.
Feb 9 19:49:15 SZC-L0040683 Keepalived_healthcheckers[59739]: TCP connection to [30.16.10.135]:3306 failed.
Feb 9 19:49:15 SZC-L0040683 Keepalived_healthcheckers[59739]: Check on service [30.16.10.135]:3306 failed after 1 retry.
Feb 9 19:49:15 SZC-L0040683 Keepalived_healthcheckers[59739]: Removing service [30.16.10.135]:3306 from VS [30.16.11.54]:3306
折腾了几天还是不行,谁有成功的配置,求指教。
以下是环境和配置:
1:操作系统版本:Red Hat Enterprise Linux Server release 7.2 (Maipo)
2:keepalived版本:keepalived-1.2.24
3:mysql版本:MySQL-server-5.6.21
安装完ipv,mysql,keepalive
真实ip
主 IP:30.16.10.130
备 IP: 30.16.10.135
虚拟IP:
30.16.10.200
问题:
1:
KEEPALIVED配置如下:
主:MASTER 配置
global_defs {
notification_email {
zhanrui153@pingan.com.cn
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 11
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
30.16.10.200
}
}
virtual_server 30.16.10.200 3306 {
delay_loop 2
lb_algo wrr #LV
lb_kind DR #LV
persistence_timeout 60
protocol TCP
real_server 30.16.10.130 3306 {
weight 1
notify_down /root/check_mysql.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
备:BACKUP 配置
global_defs {
notification_email {
zhanrui153@pingan.com.cn
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP
virtual_router_id 11
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
30.16.10.200
}
}
virtual_server 30.16.10.200 3306 {
delay_loop 2
lb_algo wrr #LV
lb_kind DR #LV
persistence_timeout 60
protocol TCP
real_server 30.16.10.130 3306 {
weight 1
notify_down /root/check_mysql.sh
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}