1

有 2 个服务器,每个服务器有 2 个以太网(一个是主要的,一个是辅助的)

keepalived.conf(服务器 1)

vrrp_instance vi_1 {
    state MASTER
    interface enp2s0
    virtual_router_id 100
    priority 255
    advert_int 1
    authentication {
            auth_type PASS
            auth_pass k@l!ve4
    }
    virtual_ipaddress {
            xxx.xxx.xxx.xxx/25
    }
}

vrrp_instance vi_2 {
    state MASTER
    interface enx00000000a3c2
    virtual_router_id 101
    priority 255
    advert_int 1
    authentication {
            auth_type PASS
            auth_pass k@l!ve4
    }
    virtual_ipaddress {
            192.168.0.4/24
    }
}

keepalived.conf(服务器 2)

vrrp_instance vi_1 {
    state BACKUP
    interface enp0s31f6
    virtual_router_id 100
    priority 100
    advert_int 1
    authentication {
            auth_type PASS
            auth_pass k@l!ve4
    }
    virtual_ipaddress {
           xxx.xxx.xxxx/25
    }
}

vrrp_instance vi_2 {
    state BACKUP
    interface enx000ec6c8ae33
    virtual_router_id 101
    priority 100
    advert_int 1
    authentication {
            auth_type PASS
            auth_pass k@l!ve4
    }
    virtual_ipaddress {
            192.168.0.4/24
    }
}

IP 列表(Server1) 正常

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet xxx.xxx.xxx.xxx/25 brd xxx.xxx.xxx scope global enp2s0
       valid_lft forever preferred_lft forever
    inet xxx.xxx.xxx.xxx/25 scope global secondary enp2s0
       valid_lft forever preferred_lft forever
    inet6 xxxx::xxxx:xxxx:xxxx:xxxx/64 scope link
       valid_lft forever preferred_lft forever
313: enx00000000a3c2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.2/24 brd 192.168.0.255 scope global enx00000000a3c2
       valid_lft forever preferred_lft forever
    inet 192.168.0.4/24 scope global secondary enx00000000a3c2
       valid_lft forever preferred_lft forever
    inet6 xxxx::xxxx:xxxx:xxxx:xxxx/64 scope link
       valid_lft forever preferred_lft forever

IP 列表(Server2)很奇怪。
Q1) 为什么Server2上打印的是192.168.0.4?

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet xxx.xxx.xxx.xx/25 brd xxx.xxx.xxx.xxx scope global enp0s31f6
       valid_lft forever preferred_lft forever
    inet6 xxxx::xxxx:xxxx:xxxx:xxxx/64 scope link
       valid_lft forever preferred_lft forever
3: enx000ec6c8ae33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.3/24 brd 192.168.0.255 scope global enx000ec6c8ae33
       valid_lft forever preferred_lft forever
    inet 192.168.0.4/24 scope global secondary enx000ec6c8ae33
       valid_lft forever preferred_lft forever
    inet6 xxxx::xxxx:xxxx:xxxx:xxxx/64 scope link
       valid_lft forever preferred_lft forever

journalctl 日志(服务器 2)

Jul 07 08:41:07 SERVER2 Keepalived_vrrp[20864]: (vi_2) Master received advert from 192.168.0.2 with higher priority 2
Jul 07 08:41:07 SERVER2 Keepalived_vrrp[20864]: (vi_2) Entering BACKUP STATE
Jul 07 08:46:09 SERVER2 Keepalived_vrrp[20864]: (vi_2) Entering MASTER STATE
Jul 07 08:46:52 SERVER2 Keepalived_vrrp[20864]: (vi_2) Master received advert from 192.168.0.2 with higher priority 2
Jul 07 08:46:52 SERVER2 Keepalived_vrrp[20864]: (vi_2) Entering BACKUP STATE
Jul 07 08:51:54 SERVER2 Keepalived_vrrp[20864]: (vi_2) Entering MASTER STATE
Jul 07 09:21:39 SERVER2 Keepalived_vrrp[20864]: (vi_2) Master received advert from 192.168.0.2 with higher priority 2
Jul 07 09:21:39 SERVER2 Keepalived_vrrp[20864]: (vi_2) Entering BACKUP STATE
Jul 07 09:26:41 SERVER2 Keepalived_vrrp[20864]: (vi_2) Entering MASTER STATE
Jul 07 09:41:08 SERVER2 Keepalived_vrrp[20864]: (vi_2) Master received advert from 192.168.0.2 with higher priority 2
Jul 07 09:41:08 SERVER2 Keepalived_vrrp[20864]: (vi_2) Entering BACKUP STATE

Q2) 为什么 Server2 中的 MASTER 和 BACKUP 会不断变化?

正常的时候Server1是MASTER,Server2是BACKUP Keepalived版本是1.4.3,我测试的是最新版本(2.xx),但是症状都是一样的。

4

0 回答 0