小言_互联网的博客

keepalived --- 配置虚拟路由器示例

386人阅读  评论(0)

绘制拓扑

前提检查

1、时间必须同步

进行各个节点的时间是否同步。如果不同步,进行配置时间同步服务器进行时间同步。

2、确保iptables及selinux不会成为阻碍

进行相应iptables和selinux检查,避免各个节点之间无法进行正常通信和交互。

3、各节点之间可通过主机名互相通信(对KA并非必须)

  • 节点 1

    [root@Neo_Neo ~]# hostname
    Neo_Neo
    [root@Neo_Neo ~]# cat /etc/hosts | grep "192"
    192.168.1.12 Neo_Tang
    [root@Neo_Neo ~]# ping Neo_Tang
    PING Neo_Tang (192.168.1.12) 56(84) bytes of data.
    64 bytes from Neo_Tang (192.168.1.12): icmp_seq=1 ttl=64 time=0.553 ms
    64 bytes from Neo_Tang (192.168.1.12): icmp_seq=2 ttl=64 time=0.581 ms
    64 bytes from Neo_Tang (192.168.1.12): icmp_seq=3 ttl=64 time=0.618 ms
    64 bytes from Neo_Tang (192.168.1.12): icmp_seq=4 ttl=64 time=0.449 ms
    ^C
    --- Neo_Tang ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3003ms
    rtt min/avg/max/mdev = 0.449/0.550/0.618/0.064 ms
    
  • 节点 2

    [root@Neo_Tang ~]# hostname 
    Neo_Tang
    [root@Neo_Tang ~]# cat /etc/hosts | grep "192"
    192.168.1.11 Neo_Neo
    [root@Neo_Tang ~]# ping Neo_Neo
    PING Neo_Neo (192.168.1.11) 56(84) bytes of data.
    64 bytes from Neo_Neo (192.168.1.11): icmp_seq=1 ttl=64 time=0.521 ms
    64 bytes from Neo_Neo (192.168.1.11): icmp_seq=2 ttl=64 time=0.472 ms
    64 bytes from Neo_Neo (192.168.1.11): icmp_seq=3 ttl=64 time=1.40 ms
    64 bytes from Neo_Neo (192.168.1.11): icmp_seq=4 ttl=64 time=0.897 ms
    ^C
    --- Neo_Neo ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3004ms
    rtt min/avg/max/mdev = 0.472/0.824/1.407/0.375 ms
    

4、确保各节点的用于集群服务的接口支持MULTICAST通信

  • 节点 1

    [root@Neo_Neo ~]# ifconfig ens33 
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.11  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::20c:29ff:fe47:2ddd  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:47:2d:dd  txqueuelen 1000  (Ethernet)
            RX packets 902  bytes 76346 (74.5 KiB)
            RX errors 0  dropped 132  overruns 0  frame 0
            TX packets 538  bytes 75874 (74.0 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
  • 节点 2

    [root@Neo_Tang ~]# ifconfig ens33
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.12  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::20c:29ff:fe85:7535  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:85:75:35  txqueuelen 1000  (Ethernet)
            RX packets 204  bytes 18942 (18.4 KiB)
            RX errors 0  dropped 31  overruns 0  frame 0
            TX packets 147  bytes 17222 (16.8 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

4.1 接口 MULTICAST 设置方式

[root@Neo_Neo ~]# ifconfig ens33 | grep "ens33"
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

[root@Neo_Neo ~]# ip link set multicast off dev ens33

[root@Neo_Neo ~]# ifconfig ens33 | grep "ens33"
ens33: flags=67<UP,BROADCAST,RUNNING>  mtu 1500

[root@Neo_Neo ~]# ip link set multicast on dev ens33

[root@Neo_Neo ~]# ifconfig ens33 | grep "ens33"
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

虚拟路由器配置

1、keepalived 安装及启动、停止

~]# yum install keepalived -y
~]# rpm -ql keepalived
~]# systemctl start keepalived.service
~]# systemctl stop keepalived.service

2、虚拟路由器配置

2.1 节点 1 配置

[root@Neo_Neo ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
	root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id Neo_Tang
   vrrp_mcast_group4 224.0.0.58
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 33
    priority 96
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass JIAOTANG
    }
    virtual_ipaddress {
	192.168.1.99/24 dev ens33 label ens33:0
    }
}

vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 34
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass JIAOtANG
    }
    virtual_ipaddress {
        192.168.1.98/24 dev ens33 label ens33:1
    }
}

2.2 节点 2 配置

[root@Neo_Tang ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
	root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id neo-neo
   vrrp_mcast_group4 224.0.0.58
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 33
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass JIAOTANG
    }
    virtual_ipaddress {
	192.168.1.99/24 dev ens33 label ens33:0
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 34
    priority 95
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass JIAOtANG
    }
    virtual_ipaddress {
        192.168.1.98/24 dev ens33 label ens33:1
    }
}

3、状态查看

3.1 节点 1 开启 keepalived 程序,节点 2 不开启

  • 节点 1

    [root@Neo_Neo ~]# systemctl start keepalived.service
    [root@Neo_Neo ~]# systemctl status keepalived.service
    ● keepalived.service - LVS and VRRP High Availability Monitor
       Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
       Active: active (running) since Fri 2019-10-04 04:57:24 EDT; 5s ago
      Process: 6881 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
     Main PID: 6882 (keepalived)
       CGroup: /system.slice/keepalived.service
               ├─6882 /usr/sbin/keepalived -D
               ├─6883 /usr/sbin/keepalived -D
               └─6884 /usr/sbin/keepalived -D
    
    Oct 04 04:57:26 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.98
    Oct 04 04:57:28 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_1) Transition to MASTER STATE
    Oct 04 04:57:29 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_1) Entering MASTER STATE
    Oct 04 04:57:29 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_1) setting protocol VIPs.
    Oct 04 04:57:29 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 04:57:29 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.1.99
    Oct 04 04:57:29 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 04:57:29 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 04:57:29 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 04:57:29 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.99
    [root@Neo_Neo ~]# ifconfig 
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.11  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::20c:29ff:fe47:2ddd  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:47:2d:dd  txqueuelen 1000  (Ethernet)
            RX packets 1553  bytes 127962 (124.9 KiB)
            RX errors 0  dropped 293  overruns 0  frame 0
            TX packets 910  bytes 153296 (149.7 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.99  netmask 255.255.255.0  broadcast 0.0.0.0
            ether 00:0c:29:47:2d:dd  txqueuelen 1000  (Ethernet)
    
    ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.98  netmask 255.255.255.0  broadcast 0.0.0.0
            ether 00:0c:29:47:2d:dd  txqueuelen 1000  (Ethernet)
    
  • 节点 2

    [root@Neo_Tang ~]# systemctl status keepalived.service
    ● keepalived.service - LVS and VRRP High Availability Monitor
       Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
       Active: inactive (dead)
    
    Oct 04 04:51:42 Neo_Tang Keepalived[7089]: Stopping
    Oct 04 04:51:42 Neo_Tang systemd[1]: Stopping LVS and VRRP High Availability Monitor...
    Oct 04 04:51:42 Neo_Tang Keepalived_vrrp[7091]: VRRP_Instance(VI_1) sent 0 priority
    Oct 04 04:51:42 Neo_Tang Keepalived_vrrp[7091]: VRRP_Instance(VI_1) removing protocol VIPs.
    Oct 04 04:51:42 Neo_Tang Keepalived_vrrp[7091]: VRRP_Instance(VI_2) sent 0 priority
    Oct 04 04:51:42 Neo_Tang Keepalived_vrrp[7091]: VRRP_Instance(VI_2) removing protocol VIPs.
    Oct 04 04:51:42 Neo_Tang Keepalived_healthcheckers[7090]: Stopped
    Oct 04 04:51:43 Neo_Tang Keepalived_vrrp[7091]: Stopped
    Oct 04 04:51:43 Neo_Tang Keepalived[7089]: Stopped Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
    Oct 04 04:51:43 Neo_Tang systemd[1]: Stopped LVS and VRRP High Availability Monitor.
    [root@Neo_Tang ~]# ifconfig 
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.12  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::20c:29ff:fe85:7535  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:85:75:35  txqueuelen 1000  (Ethernet)
            RX packets 1052  bytes 88500 (86.4 KiB)
            RX errors 0  dropped 206  overruns 0  frame 0
            TX packets 640  bytes 120772 (117.9 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

3.2 节点 2 开启 keepalived 程序

  • 节点 2

    [root@Neo_Tang ~]# systemctl start keepalived.service
    [root@Neo_Tang ~]# systemctl status keepalived.service
    ● keepalived.service - LVS and VRRP High Availability Monitor
       Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
       Active: active (running) since Fri 2019-10-04 05:00:21 EDT; 2s ago
      Process: 7151 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
     Main PID: 7152 (keepalived)
       CGroup: /system.slice/keepalived.service
               ├─7152 /usr/sbin/keepalived -D
               ├─7153 /usr/sbin/keepalived -D
               └─7154 /usr/sbin/keepalived -D
    
    Oct 04 05:00:21 Neo_Tang Keepalived_vrrp[7154]: VRRP sockpool: [ifindex(2), proto(112), unicast(0), fd(10,11)]
    Oct 04 05:00:21 Neo_Tang Keepalived_vrrp[7154]: VRRP_Instance(VI_1) Transition to MASTER STATE
    Oct 04 05:00:22 Neo_Tang Keepalived_vrrp[7154]: VRRP_Instance(VI_1) Entering MASTER STATE
    Oct 04 05:00:22 Neo_Tang Keepalived_vrrp[7154]: VRRP_Instance(VI_1) setting protocol VIPs.
    Oct 04 05:00:22 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 05:00:22 Neo_Tang Keepalived_vrrp[7154]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.1.99
    Oct 04 05:00:22 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 05:00:22 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 05:00:22 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 05:00:22 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Hint: Some lines were ellipsized, use -l to show in full.
    [root@Neo_Tang ~]# ifconfig 
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.12  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::20c:29ff:fe85:7535  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:85:75:35  txqueuelen 1000  (Ethernet)
            RX packets 1145  bytes 96996 (94.7 KiB)
            RX errors 0  dropped 221  overruns 0  frame 0
            TX packets 717  bytes 132270 (129.1 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.99  netmask 255.255.255.0  broadcast 0.0.0.0
            ether 00:0c:29:85:75:35  txqueuelen 1000  (Ethernet)
    
  • 节点 1

    [root@Neo_Neo ~]# systemctl status keepalived.service
    ● keepalived.service - LVS and VRRP High Availability Monitor
       Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
       Active: active (running) since Fri 2019-10-04 04:57:24 EDT; 3min 23s ago
      Process: 6881 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
     Main PID: 6882 (keepalived)
       CGroup: /system.slice/keepalived.service
               ├─6882 /usr/sbin/keepalived -D
               ├─6883 /usr/sbin/keepalived -D
               └─6884 /usr/sbin/keepalived -D
    
    Oct 04 04:57:31 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.98
    Oct 04 04:57:34 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 04:57:34 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.1.99
    Oct 04 04:57:34 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 04:57:34 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 04:57:34 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 04:57:34 Neo_Neo Keepalived_vrrp[6884]: Sending gratuitous ARP on ens33 for 192.168.1.99
    Oct 04 05:00:21 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_1) Received advert with higher priority 100, ours 96
    Oct 04 05:00:21 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_1) Entering BACKUP STATE
    Oct 04 05:00:21 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_1) removing protocol VIPs.
    [root@Neo_Neo ~]# ifconfig 
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.11  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::20c:29ff:fe47:2ddd  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:47:2d:dd  txqueuelen 1000  (Ethernet)
            RX packets 1714  bytes 139274 (136.0 KiB)
            RX errors 0  dropped 332  overruns 0  frame 0
            TX packets 1317  bytes 184530 (180.2 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.98  netmask 255.255.255.0  broadcast 0.0.0.0
            ether 00:0c:29:47:2d:dd  txqueuelen 1000  (Ethernet)
    

3.3 节点 1 关闭 keepalived 程序

  • 节点 1

    [root@Neo_Neo ~]# systemctl stop keepalived.service
    [root@Neo_Neo ~]# systemctl status keepalived.service
    ● keepalived.service - LVS and VRRP High Availability Monitor
       Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
       Active: inactive (dead)
    
    Oct 04 05:00:21 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_1) Entering BACKUP STATE
    Oct 04 05:00:21 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_1) removing protocol VIPs.
    Oct 04 05:05:57 Neo_Neo systemd[1]: Stopping LVS and VRRP High Availability Monitor...
    Oct 04 05:05:57 Neo_Neo Keepalived[6882]: Stopping
    Oct 04 05:05:57 Neo_Neo Keepalived_healthcheckers[6883]: Stopped
    Oct 04 05:05:57 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_2) sent 0 priority
    Oct 04 05:05:57 Neo_Neo Keepalived_vrrp[6884]: VRRP_Instance(VI_2) removing protocol VIPs.
    Oct 04 05:05:58 Neo_Neo Keepalived_vrrp[6884]: Stopped
    Oct 04 05:05:58 Neo_Neo Keepalived[6882]: Stopped Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
    Oct 04 05:05:58 Neo_Neo systemd[1]: Stopped LVS and VRRP High Availability Monitor.
    [root@Neo_Neo ~]# ifconfig 
    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.11  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::20c:29ff:fe47:2ddd  prefixlen 64  scopeid 0x20<link>
            ether 00:0c:29:47:2d:dd  txqueuelen 1000  (Ethernet)
            RX packets 2234  bytes 174932 (170.8 KiB)
            RX errors 0  dropped 394  overruns 0  frame 0
            TX packets 1723  bytes 215516 (210.4 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
  • 节点 2

[root@Neo_Tang ~]# systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2019-10-04 05:00:21 EDT; 6min ago
  Process: 7151 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 7152 (keepalived)
   CGroup: /system.slice/keepalived.service
           ├─7152 /usr/sbin/keepalived -D
           ├─7153 /usr/sbin/keepalived -D
           └─7154 /usr/sbin/keepalived -D

Oct 04 05:05:59 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.98
Oct 04 05:05:59 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.98
Oct 04 05:05:59 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.98
Oct 04 05:05:59 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.98
Oct 04 05:06:04 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.98
Oct 04 05:06:04 Neo_Tang Keepalived_vrrp[7154]: VRRP_Instance(VI_2) Sending/queueing gratuitous ARPs on ens33 for 192.168.1.98
Oct 04 05:06:04 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.98
Oct 04 05:06:04 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.98
Oct 04 05:06:04 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.98
Oct 04 05:06:04 Neo_Tang Keepalived_vrrp[7154]: Sending gratuitous ARP on ens33 for 192.168.1.98
Hint: Some lines were ellipsized, use -l to show in full.
[root@Neo_Tang ~]# ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.12  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe85:7535  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:85:75:35  txqueuelen 1000  (Ethernet)
        RX packets 1630  bytes 127582 (124.5 KiB)
        RX errors 0  dropped 293  overruns 0  frame 0
        TX packets 1170  bytes 165040 (161.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.99  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 00:0c:29:85:75:35  txqueuelen 1000  (Ethernet)

ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.98  netmask 255.255.255.0  broadcast 0.0.0.0
        ether 00:0c:29:85:75:35  txqueuelen 1000  (Ethernet)

4、组播报文查看

4.1 节点 1 开启 keepalived 程序,节点 2 不开启

  • 节点 1

    [root@Neo_Neo ~]# tcpdump -i ens33 -nn host 224.0.0.58
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
    05:08:25.165382 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:26.167760 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:27.169136 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:27.790222 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:28.170171 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:28.791860 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:29.171213 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:29.793338 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:30.172254 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:30.794338 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:31.173325 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:31.796199 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:32.174182 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:32.797325 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:33.175310 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    ^C
    15 packets captured
    15 packets received by filter
    0 packets dropped by kernel
    
  • 节点 2

    [root@Neo_Tang ~]# tcpdump -i ens33 -nn host 224.0.0.58
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
    05:08:25.361480 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:26.364966 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:27.365184 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:27.986328 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:28.366438 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:28.987871 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:29.367347 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:29.989470 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:30.368538 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:30.990453 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:31.369417 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:31.992391 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:32.370463 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:32.993595 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:33.371513 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:33.994526 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:34.372621 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:08:34.995714 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:08:35.373757 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    ^C
    19 packets captured
    20 packets received by filter
    0 packets dropped by kernel
    

4.2 节点 2 开启 keepalived 程序

  • 节点 2

    [root@Neo_Tang ~]# tcpdump -i ens33 -nn host 224.0.0.58
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
    05:10:21.120094 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:10:21.483724 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:22.121715 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:10:22.484762 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:23.123623 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:10:23.123725 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:23.485640 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:24.124991 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:24.486841 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:25.126400 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:25.487686 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:26.127516 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:26.488797 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:27.128302 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:27.489766 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:28.128693 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:28.490823 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:29.129310 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:29.491843 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:30.129664 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    ^C
    20 packets captured
    21 packets received by filter
    0 packets dropped by kernel
    
  • 节点 1

    [root@Neo_Neo ~]# tcpdump -i ens33 -nn host 224.0.0.58
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
    05:10:19.920106 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:10:20.284092 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:20.921727 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:10:21.285234 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:21.923240 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:10:22.286253 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:22.925006 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 96, authtype simple, intvl 1s, length 20
    05:10:22.925554 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:23.287147 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:23.926935 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:24.288193 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:24.928262 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:25.289145 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:25.929420 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:26.290194 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:26.930122 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:27.291180 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:10:27.930636 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:10:28.292177 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    ^C
    19 packets captured
    19 packets received by filter
    0 packets dropped by kernel
    

4.3 节点 1 关闭 keepalived 程序

  • 节点 1

    [root@Neo_Neo ~]# tcpdump -i ens33 -nn host 224.0.0.58
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
    05:11:51.035490 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:51.404333 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:11:52.036377 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:52.405181 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:11:53.037237 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:53.406324 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:11:54.038293 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:54.407372 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:11:55.039426 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:55.298373 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 0, authtype simple, intvl 1s, length 20
    05:11:55.928522 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:11:56.040520 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:56.930752 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:11:57.041508 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:57.932053 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:11:58.042482 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:58.932303 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:11:59.043402 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:59.933508 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:12:00.044475 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:12:00.934160 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:12:01.045472 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:12:01.935263 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:12:02.046318 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    ^C
    24 packets captured
    24 packets received by filter
    0 packets dropped by kernel
    
  • 节点 2

    [root@Neo_Tang ~]# tcpdump -i ens33 -nn host 224.0.0.58
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on ens33, link-type EN10MB (Ethernet), capture size 262144 bytes
    05:11:53.606695 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:11:54.238398 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:54.607842 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 100, authtype simple, intvl 1s, length 20
    05:11:55.239428 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:55.498679 IP 192.168.1.11 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 0, authtype simple, intvl 1s, length 20
    05:11:56.128485 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:11:56.240530 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:57.130977 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:11:57.241553 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:58.131517 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:11:58.242522 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:11:59.132408 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:11:59.243437 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:12:00.133521 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:12:00.244555 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:12:01.134338 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:12:01.245586 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:12:02.135473 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:12:02.246429 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:12:03.136161 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:12:03.247580 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    05:12:04.137600 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 34, prio 95, authtype simple, intvl 1s, length 20
    05:12:04.248394 IP 192.168.1.12 > 224.0.0.58: VRRPv2, Advertisement, vrid 33, prio 100, authtype simple, intvl 1s, length 20
    ^C
    23 packets captured
    24 packets received by filter
    0 packets dropped by kernel
    

转载:https://blog.csdn.net/weixin_44983653/article/details/102079161
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场