1、安装
系统:ubuntu1804
两个节点(us248,us249)都安装了nginx代理mysql(us251,us252,us253,us254)
sudo apt install keepalived
查看版本:keepalived -v
查看服务状态:sudo systemctl status keepalived
2、配置
参考/usr/share/doc/keepalived/keepalived.conf.说明
配置文件/etc/keepalived/keepalived.conf
global_defs {
router_id node1 #node2 备节点
}
vrrp_script chk_nginx {
script "killall -0 nginx"
interval 1
}
vrrp_instance vrrp1 {
state MASTER #BACKUP 备节点
interface ens33
virtual_router_id 51
priority 100 #90 备节点
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.240
}
track_script {
chk_nginx
}
}
3、测试
1)主从节点启动:
sudo systemctl restart keepalived
2)主节点检查是否有虚拟IP:192.168.1.240
ip a(VIP在主节点)
3)关闭主节点,从节点检查虚拟IP
ip a(VIP在从节点)
4)重启主节点,检查VIP
VIP回到了主节点
4、脑裂问题
TODO