Nginx+keepalived(高可用双主模式)
tips:前面已经介绍了nginx+keepalived高可用主从模式,今天补充下高可用的双主模式,均可以作为主机使用
server1:192.168.237.128 VIP1:192.168.237.10
server2:192.168.237.129 VIP2:192.168.237.20
vim /etc/keepalived/keepalived.conf //编辑配置文件,增加一段新的vrrp_instance 规则
keepalivedA配置文件新增如下:
vrrp_instance VI_2 {
state BACKUP #备机
interface eth0 #网卡名称
virtual_router_id 52 #路由ID
priority 100 #优先级
authentication {
auth_type PASS
auth_pass 2222 #########
}
virtual_ipaddress {
192.168.237.20 #######VIP2
}
track_script {
chk_nginx
}
}
keepalivedB配置文件新增如下:
vrrp_instance VI_2 {
state MASTER #主机
interface eth0 #网卡名称
virtual_router_id 52 #路由ID
priority 110 #优先级
authentication {
auth_type PASS
auth_pass 2222 #########
}
virtual_ipaddress {
192.168.237.20 #######VIP2
}
track_script {
chk_nginx
}
}
分别启动 keepalivedA 和keepalivedB,查看绑定VIP情况
停止keepalivedA service keepalived stop ,KeepalivedB接替keepalivedA工作,查看B机器ip绑定情况,访问192.168.273.10正常运行
重启keepalivedA,keepalivedA恢复工作,重新绑定VIP1,keepalivedB移除VIP1,继续监听
同上,停止keepalivedB,查看keepalivedA绑定VIP情况
总结:访问 keepalived 中配置的两个 VIP 都可以正常调度,当我们停止任意一台 keepalived节点,同样还是正常访问;到此,keepalived+nginx 高可用集群(双主模式)就搭建完成了
原文地址:https://www.cnblogs.com/vincentYw/p/11765475.html