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情况