Load Balancer Live Demo

System DesignReliability & Scaling

Topic: Load Balancer Live Demo

Presenter: 猴子


Sign Up Form:

QRCode

System Design Summary

We will demo L4 load balancer today

We will use VIP, lvs-1, tomcat1, tomcat2

We will change the kernel of the destination machine

There will be loopback device to support VIP

Change the kernel

cd /proc/sys/net/ipv4/conf

All, default, ens33, lo, viror0

All kernel parameters are mapped to a file

On machine of tomcat 1 and tomcat 2, map the RIP (real IP)

We need to change ens33/arp_ignore and ens33/arp_announce in order to hide VIP address

echo 1 > arp_ignore

echo 2 > arp_announce

Do the same for all/arp_ignore and all/arp_announce

On machine of tomcat 1 and tomcat 2 map the VIP (virtual IP)

Map VIP to loopback device

On machine of load balancer, we bind the VIP

Ifconfig

On machine of load balancer, there is 1 network card but 2 IP addresses

Start apache servers on real server

Configure each apache servers to return a static page, one says server1 another server2

Start apache servers

Visited the real servers to confirm we can retrieve web pages from real IP

Now configure lvs load balancer

Configure round robin for incoming packets

ipvsadm -A -t 192.168.1.250:80 -s rr

Configure the outgoing packets to go to different real servers

ipvsadm -a -t 192.168.1.250:80 -r 192.168.1.1.12 -g

ipvsadm -a -t 192.168.1.250:80 -r 192.168.1.1.13 -g

Now curl webpage from VIP 192.168.1.250

Confirmed it’s requesting real servers in round-robin fashion

load balancer looks up from 192.168.1.12 to MAC address.

Load balancer sends the packet to this MAC address with 192.168.1.250 as destination IP address

Stop one HTTPD server

When we curl 192.168.1.250 and half the requests will get “connection refused”

High availability

L4 load balancer LVS is a single point of failure

Master and backup

There can be multiple backups

A backup monitors the health of the master as well as of the real machines

The master sends heartbeat

A backup does not have a VIP

Set up keepalived on master and backups

It monitors the health of the real servers

/etc/keepalived/keepalived.conf

Virtual_server - persistent timeout

Start keepalived

The master will broadcast that it is alive

keepalived: will use the a HTTP request to check the health of real servers

it will auto configure the load balancer, based on the health of real servers

Test the backup mechanism

Shutdown the network card of the main server

The backup comes up after detection that the main server is down. keepalived

Bringing back up the original master, the original master will become master again.

Easier to test the network configuration using curl than browser.

Test taking down real server

Now take down a real server. the configuration of LB is automatically changed to exclude the down server.

Configure for HTTPS

Keepalived can use SSL to test the health of the real servers

Summary

User -> DNS -> L4 LB -> L7 LB -> tomcat real servers

Drawing tool: processon.com

Every deeper layer has more features, but is slower

API gateway is one type of L7 balancer