架构图:
详细内容参考:
结果展示:
- 178.119.30.16(从)- master
- 178.119.30.17(从)- slave
由上述结果可以看出,产生了主备节点同时抢占VIP的问题(即脑裂问题)
解决方法:
#通过配置来指定IP的两台服务器间进行单播通讯# 本地IP地址unicast_src_ip 178.119.30.16# 对端IP地址unicast_peer {178.119.30.17}
- master
vim keepalived.conf
global_defs {router_id LVS_1script_user root
}vrrp_script check_mysql_port {script "/etc/keepalived/check_mysql_port.sh" # 脚本存放的位置interval 2 # 每隔两秒运行上一行脚本weight 2
}vrrp_instance VI_1 {# 主机=MASTER;备用机=BACKUPstate MASTER# 该实例绑定的网卡名称interface ens192# 保证主备节点一致virtual_router_id 150# 权重,master值 > backup值priority 100# 主备组播报发送间隔时间1秒advert_int 1unicast_src_ip 178.119.30.16unicast_peer {178.119.30.17}# 认证权限密码,防止非法节点进入authentication {auth_type PASSauth_pass 1111}# 虚拟出来的ip,可以有多个(vip)virtual_ipaddress {178.119.30.18}# 调用监控脚本track_script {check_mysql_port}
}
- slave
vim keepalived.conf
global_defs {router_id LVS_1script_user root
}vrrp_script check_mysql_port {script "/etc/keepalived/check_mysql_port.sh" # 脚本存放的位置interval 2 # 每隔两秒运行上一行脚本weight 2
}vrrp_instance VI_1 {# 主机=MASTER;备用机=BACKUPstate BACKUP# 该实例绑定的网卡名称interface ens192# 保证主备节点一致virtual_router_id 150# 权重,master值 > backup值priority 50 # 主i备组播报发送间隔时间1秒advert_int 1 unicast_src_ip 178.119.30.17unicast_peer { 178.119.30.16}# 认证权限密码,防止非法节点进入authentication {auth_type PASSauth_pass 1111} # 虚拟出来的ip,可以有多个(vip)virtual_ipaddress { 178.119.30.18}# 调用监控脚本track_script {check_mysql_port }
}
结果展示:
- 178.119.30.16(从)- master
- 178.119.30.17(从)- slave
VIP 漂移测试
systemctl stop keepalived
- 178.119.30.16(从)- master
- 178.119.30.17(从)- slave