keepalived + LVS DR to build highly available load balancing

This article refers to the blog: https://blog.csdn.net/Ki8Qzvka6Gz4n450m/article/details/79119665 The
original blog is very detailed and correct, and the re-recording is only for easy search and construction

1. Brief description of the environment
real server1: 192.168.50.207 ----------- httpd server
real server2: 192.168.50.235 ----------- httpd server
director server1: 192.168.50.232- ------- lvs dr server + keepalived server
director server2: 192.168.50.231 ----- lvs dr server + keepalived server
test server: 192.168.50.208

Second, build
1 real server1 and real server2 server settings:
execute the following script
[root @ localhost lvs_dir] #cat lvs_dr_rs.sh
#! / Bin / bash
vip = 192.168.50.252
ifconfig lo: 0 $ vip broadcast $ vip netmask 255.255. 255.255 up
route add -host $ vip lo: 0
echo "1"> / proc / sys / net / ipv4 / conf / lo / arp_ignore
echo "2"> / proc / sys / net / ipv4 / conf / lo / arp_announce
echo "1"> / proc / sys / net / ipv4 / conf / all / arp_ignore
echo "2"> / proc / sys / net / ipv4 / conf / all / arp_announce
Note: httpd installation and settings are omitted, refer to the previous blog

  1. Director server1 server settings:
    [root @ localhost keepalived] # cat /etc/keepalived/keepalived.conf
    ! Configuration File for keepalived

global_defs {
notification_email {br/>[email protected]
}
notification_email_from keepalived@232
smtp_server 192.168.50.232
smtp_connect_timeout 30
router_id 232
! vrrp_skip_check_adv_addr
! vrrp_strict
! vrrp_garp_interval 0
! vrrp_gna_interval 0
}

vrrp_instance VI_1 {
state MASTER
interface ens160
virtual_router_id 111
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.50.252
}
}

virtual_server 192.168.50.252 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP

real_server 192.168.50.235 80 {
    weight 1
    TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
    }
}

real_server 192.168.50.207 80 {
    weight 1
    TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
    }
}

}

[root@localhost keepalived]# echo 1 > /proc/sys/net/ipv4/ip_forward

  1. The construction of director server2 is similar,
    only need to slightly modify the content of keepalived configuration file
    state MASTER-> state BACKUP
    priority 100-> priority 90

  2. Start the keepalved service (director server1 and director server2)
    [root @ localhost keepalived] # systemctl start keepalived

3. Test
1 Test load balancing (on 208):
[root @ localhost ~] # curl 192.168.50.252:80
235
[root @ localhost ~] # curl 192.168.50.252:80
207
[root @ localhost ~] # curl 192.168. 50.252: 80
235
[root @ localhost ~] # curl 192.168.50.252:80
207
2. Test the single point of failure of the real server:
turn off the httpd service on 235, and then test on 208:
[root @ localhost ~] # curl 192.168.50.252:80
207
[root @ localhost ~] # curl 192.168.50.252:80
207
3. Test the high availability of the director
Turn off the keepalived of the 231 server, or turn off the network card, etc., and then test
[root @ localhost] on 208 ~] # curl 192.168.50.252:80
235
[root @ localhost ~] # curl 192.168.50.252:80
207
[root @ localhost ~] # curl 192.168.50.252:80
235
[root@localhost ~]# curl 192.168.50.252:80
207

Guess you like

Origin blog.51cto.com/291268154/2489147
Recommended