LVS + Keepalive achieve high availability cluster

First, prepare two already installed LVS machine
can refer to this document quickly erected
here it must be noted, do not perform on the vip address binding, otherwise it will fail ip drift

IP address planning

CPU name IP addresses
lvs1 eth0:10.0.0.201 vip:10.0.0.3
lvs2 eth0:10.0.0.203 vip:10.0.0.3
Nx1 eth0:10.0.0.202 vip:10.0.0.3
nginx eth0:10.0.0.200 vip:10.0.0.3

Installation Keepalive

yum install -y keepalived

Keepalive modify configuration files

  • lvs1
global_defs {
   router_id LVS_01
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
     10.0.0.3/24
    }
}

virtual_server 10.0.0.3 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 3
    protocol TCP

    real_server 10.0.0.200 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 8
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }

    real_server 10.0.0.202 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 8
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
}
  • lvs2
global_defs {
   router_id LVS_02
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
     10.0.0.3/24
    }
}
virtual_server 10.0.0.3 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 3
    protocol TCP

    real_server 10.0.0.200 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 8
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }

    real_server 10.0.0.202 80 {
        weight 1
        TCP_CHECK {
        connect_timeout 8
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
}

Start keepalive

service keepalived start

Check the status of drift

  • lvs1
    Here Insert Picture Description
  • lvs2
    Here Insert Picture Description

The case of keepalived lvs1 vip been stopped at this time and then observed to float on the lvs2
Here Insert Picture Description
Here Insert Picture Description

  • And then the lvs load can be verified

Guess you like

Origin blog.csdn.net/qq_33235529/article/details/87717102