1)

同一套keepalived集群中virtual_router_id 要保持一致

/var/log/messages日志keepalived啟動正常日志:

Nov 18 22:42:07 db01 Keepalived_vrrp[26691]: Opening file '/etc/keepalived/keepalived.conf'.
Nov 18 22:42:07 db01 Keepalived_vrrp[26691]: VRRP_Instance(VI_2) removing protocol VIPs.
Nov 18 22:42:07 db01 Keepalived_vrrp[26691]: Using LinkWatch kernel netlink reflector...
Nov 18 22:42:07 db01 Keepalived_vrrp[26691]: VRRP sockpool: [ifindex(6), proto(112), unicast(0), fd(10,11)]
Nov 18 22:42:08 db01 Keepalived_vrrp[26691]: VRRP_Instance(VI_2) Transition to MASTER STATE
Nov 18 22:42:09 db01 Keepalived_vrrp[26691]: VRRP_Instance(VI_2) Entering MASTER STATE
Nov 18 22:42:09 db01 Keepalived_vrrp[26691]: VRRP_Instance(VI_2) setting protocol VIPs.
Nov 18 22:42:09 db01 Keepalived_vrrp[26691]: Sending gratuitous ARP on bond0 for 192.168.123.147
Nov 18 22:42:09 db01 Keepalived_vrrp[26691]: VRRP_Instance(VI_2) Sending/queueing gratuitous ARPs on bond0 for 192.168.10.147
Nov 18 22:42:09 db01 Keepalived_vrrp[26691]: Sending gratuitous ARP on bond0 for 192.168.123.147
Nov 18 22:42:09 db01 Keepalived_vrrp[26691]: Sending gratuitous ARP on bond0 for 192.168.123.147
Nov 18 22:42:09 db01 Keepalived_vrrp[26691]: Sending gratuitous ARP on bond0 for 192.168.123.147
Nov 18 22:42:09 db01 Keepalived_vrrp[26691]: Sending gratuitous ARP on bond0 for 192.168.123.147
Nov 18 22:42:14 db01 Keepalived_vrrp[26691]: Sending gratuitous ARP on bond0 for 192.168.123.147
Nov 18 22:42:14 db01 Keepalived_vrrp[26691]: VRRP_Instance(VI_2) Sending/queueing gratuitous ARPs on bond0 for 192.168.10.147
Nov 18 22:42:14 db01 Keepalived_vrrp[26691]: Sending gratuitous ARP on bond0 for 192.168.123.147
Nov 18 22:42:14 db01 Keepalived_vrrp[26691]: Sending gratuitous ARP on bond0 for 192.168.123.147
Nov 18 22:42:14 db01 Keepalived_vrrp[26691]: Sending gratuitous ARP on bond0 for 192.168.123.147
Nov 18 22:42:14 db01 Keepalived_vrrp[26691]: Sending gratuitous ARP on bond0 for 192.168.123.147
(END)

 

2)

在同一網段內非同一套keepalived集群中virtual_router_id 值不能相同

案例:

配置文件內容:

cat /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id Server_01
}

vrrp_instance VI_1 {
    state MASTER
    interface bond0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.3/24
    }
}

/var/log/messages日志keepalived啟動報錯

Mar 14 01:29:21 test Keepalived_vrrp[819]: VRRP_Instance(mysql-ha) ignoring received advertisment...
Mar 14 01:29:22 test Keepalived_vrrp[819]: ip address associated with VRID not present in received packet : 192.168.32.53
Mar 14 01:29:22 test Keepalived_vrrp[819]: one or more VIP associated with VRID mismatch actual MASTER advert
Mar 14 01:29:22 test Keepalived_vrrp[819]: bogus VRRP packet received on bond0 !!!
Mar 14 01:29:22 test Keepalived_vrrp[819]: VRRP_Instance(mysql-ha) ignoring received advertisment...
Mar 14 01:29:23 test Keepalived_vrrp[819]: ip address associated with VRID not present in received packet : 192.168.32.53
Mar 14 01:29:23 test Keepalived_vrrp[819]: one or more VIP associated with VRID mismatch actual MASTER advert
Mar 14 01:29:23 test Keepalived_vrrp[819]: bogus VRRP packet received on bond0 !!!

解決方法:
修改virtual_router_id的值,從51改為88,因為之前在同一網段還有別的機器安裝過keepalived,并設置了virtual_router_id=51,改成不同的值后重啟keepalived后問題得到解決.

3)

在同一個網段內的,若為不同的應用做高可用,不同應用使用不同的VIP,那么vrrp_instance的名字(這里是VI_1)、virtual_router_id在不同的高可用實例必須設置不同的值區分開

案例:

配置文件內容:

cat /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id Server_01
}

vrrp_instance VI_1 {
    state MASTER
    interface bond0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.100.3/24   ##做為數據庫的高可用

192.168.100.4/24 ##做為tomcat的高可用
    }
}

 

/var/log/messages日志keepalived啟動報錯:

Aug 11 11:28:36 localhostKeepalived_vrrp[16958]: (VI_1): received an invalid ip number count 1, expected2!

Aug 11 11:28:36 localhostKeepalived_vrrp[16958]: bogus VRRP packet received on eth1 !!!

Aug 11 11:28:36 localhostKeepalived_vrrp[16958]: VRRP_Instance(VI_1) Dropping received VRRP packet…

解決辦法:針對不通應用的高可用,配置不同的vrrp_instance和virtual_router_id

詳情配置如下:

cat /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id Server_01
}

vrrp_instance VI_1 {
    state MASTER
    interface bond0
    virtual_router_id 88
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.100.3/24   ##做為數據庫的高可用
   
    }
}

vrrp_instance VI_2 {
    state MASTER
    interface bond0
    virtual_router_id 99
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
     
        192.168.100.4/24   ##做為tomcat的高可用
    }
}