keepalived - 如何在同一接口上定义多个 VRRP 实例?

keepalived - 如何在同一接口上定义多个 VRRP 实例?

我遇到的情况是,我需要在同一接口上设置 2 个 VRRP 实例。我需要实现这一点,因为rsyslogdelasticsearch需要使用接口eth0用于网络通信。

帖子似乎与此类似,但没有提到配置,所以我决定提出一个问题。

我创建了下面的配置,但是在不同的主机上创建了两个主服务器。

Master 端配置

vrrp_script chk_rsyslog {
  script "netstat -atunp | grep rsyslogd | grep '0.0.0.0:514' &>/dev/null"
  interval 2 # every 2 seconds
  weight 2 # add 2 points if OK
}

vrrp_script chk_es {
  script "netstat -atunp | grep java | grep '192.168.21.14:9300' &>/dev/null"
  interval 2 # every 2 seconds
  weight 2 # add 2 points if OK

vrrp_instance RH_1 {
    state MASTER
    interface eth0
    virtual_router_id 50
    priority 10
    advert_int 1
    virtual_ipaddress {
        192.168.11.250/24
    }

    track_script {
      chk_rsyslog
    }
}

vrrp_instance ES_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 10
    advert_int 1
    virtual_ipaddress {
        192.168.11.251/24
    }

    track_script {
      chk_es
    }
}

备份端配置

vrrp_script chk_rsyslog {
  script "netstat -atunp | grep rsyslogd | grep '0.0.0.0:514' &>/dev/null"
  interval 2 # every 2 seconds
  weight 2 # add 2 points if OK
}

vrrp_script chk_es {
  script "netstat -atunp | grep java | grep '192.168.21.15:9300' &>/dev/null"
  interval 2 # every 2 seconds
  weight 2 # add 2 points if OK
}

vrrp_instance RH_1 {
    state BACKUP
    interface eth0
    virtual_router_id 50
    priority 9
    advert_int 1
    virtual_ipaddress {
        192.168.11.250/24
    }

    track_script {
      chk_rsyslog
    }
}

vrrp_instance ES_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 9
    advert_int 1
    virtual_ipaddress {
        192.168.11.251/24
    }

    track_script {
      chk_es
    }
}

备份端的日志显示两个实例均首先启动,但 ES_1 未反映到操作系统的 IP 设置中。

Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: Netlink reflector reports IP 192.168.11.15 added
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: Netlink reflector reports IP 192.168.21.15 added
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: Netlink reflector reports IP fe80::ab04:d4e4:841e:e3e1 added
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: Netlink reflector reports IP fe80::812:1dd8:9ed1:a6af added
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: Registering Kernel netlink reflector
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: Registering Kernel netlink command channel
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: Registering gratuitous ARP shared channel
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: Opening file '/etc/keepalived/keepalived.conf'.
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: Configuration is using : 69267 Bytes
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: Using LinkWatch kernel netlink reflector...
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: VRRP_Instance(RH_1) Entering BACKUP STATE
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: VRRP_Instance(ES_1) Entering BACKUP STATE
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
Apr 19 08:49:54 rhel2 Keepalived_healthcheckers[23320]: Configuration is using : 7722 Bytes
Apr 19 08:49:54 rhel2 Keepalived_healthcheckers[23320]: Using LinkWatch kernel netlink reflector...
Apr 19 08:49:54 rhel2 Keepalived_vrrp[23321]: VRRP_Script(chk_rsyslog) succeeded
Apr 19 08:49:58 rhel2 Keepalived_vrrp[23321]: VRRP_Instance(RH_1) Transition to MASTER STATE

我的 ip addr 命令结果。

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:12:0e:da brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.15/24 brd 192.168.11.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.11.250/24 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::ab04:d4e4:841e:e3e1/64 scope link
       valid_lft forever preferred_lft forever

是否可以在同一个接口上设置多个 VRRP 实例?

我的平台信息如下。

[root@rhel2 keepalived]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.3 (Maipo)
[root@rhel2 keepalived]# rpm -qa | grep keepalived
keepalived-1.2.13-8.el7.x86_64

答案1

我没有为 chk_es 添加右括号 '}'

相关内容