Updated on 2024-05-17 GMT+08:00

LVS Automatically Switching to the Primary Node After the Node Is Recovered

Objectives

When the keepalived service on the primary LVS node is faulty (for example, the keepalived service is disabled), the standby LVS node takes over services.

Prerequisites

The LVS primary and standby cluster have been correctly configured.

Test Methods

  1. After the standby takes over services, the VIP is on the standby node by default. Run the following command on the standby node:

    ip addr

    The following information is displayed:

    [root@lvs-slave ~]# ip addr
    eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 52:54:00:68:dc:b6 brd ff:ff:ff:ff:ff:ff
        inet 192.168.0.234/27 brd 182.148.15.255 scope global eth0
        inet 192.168.0.27/32 scope global eth0
        inet6 fe80::5054:ff:fe68:dcb6/64 scope link
           valid_lft forever preferred_lft forever
  2. Run the following command on the primary node to enable the keepalived service:

    service keepalived start

  3. The VIP is assigned to the primary node. Run the following command on the primary node:

    ip addr

    The following information is displayed:

    [root@lvs-master ~]# ip addr
    eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 52:54:00:68:dc:b6 brd ff:ff:ff:ff:ff:ff
        inet 192.168.0.157/27 brd 182.148.15.255 scope global eth0
        inet 192.168.0.27/32 scope global eth0
        inet6 fe80::5054:ff:fe68:dcb6/64 scope link
           valid_lft forever preferred_lft forever

    Run the following command on the standby node to verify that the VIP information does not exist:

    ip addr

    The following information is displayed:

    [root@lvs-slave ~]# ip addr
    eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 52:54:00:68:dc:b6 brd ff:ff:ff:ff:ff:ff
        inet 192.168.0.234/27 brd 182.148.15.255 scope global eth0
        inet6 fe80::5054:ff:fe68:dcb6/64 scope link
           valid_lft forever preferred_lft forever