1.主主模式,需要两个VIP,互为主备,需要修改之前主从模式keepalived配置文件
node1 192.168.3.15 vip 192.168.3.11
node2 192.168.3.8 vip 192.168.3.12
2.修改keepalived的配置文件,采用MASTER-BACKUP、BACKUP-MASTER模式
virtual_router_id需要做修改
node1的keepalived配置文件
! Configuration File for keepalived
global_defs {
router_id master_node
}
vrrp_script chk_nginx {
script "/etc/keepalived/nginx_check.sh"
interval 2
weight 20
}
vrrp_instance VI_1 {
state MASTER # master模式
interface enp0s3 # 绑定网卡
virtual_router_id 51 # 需要修改
mcast_src_ip 192.168.3.15 #地址
priority 100
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.3.11/24 #虚IP
}
}
vrrp_instance VI_2 {
state BACKUP
interface enp0s3
virtual_router_id 52
mcast_src_ip 192.168.3.8
priority 90
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.3.12/24
}
}
node2的配置
! Configuration File for keepalived
global_defs {
router_id slave_node
}
vrrp_script chk_nginx {
script "/etc/keepalived/nginx_check.sh"
interval 2
weight 20
}
vrrp_instance VI_1 {
state BACKUP
interface enp0s3
virtual_router_id 51
mcast_src_ip 192.168.3.15
priority 90
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.3.11/24
}
}
vrrp_instance VI_2 {
state MASTER
interface enp0s3
virtual_router_id 52
mcast_src_ip 192.168.3.8
priority 100
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_nginx
}
virtual_ipaddress {
192.168.3.12/24
}
}
现在利用3.11和3.12是访问的不同的nginx。
停掉3.11对应的主机3.15上的keepalived后,
- 3.11和3.12已经到漂移到3.8这台机器上。
- 现在仍然可以利用3.11访问,互为主备。
- nginx的主主模式基本搭建完毕。