Day 29: HAProxy Implementation Details

HAProxy is a load balancer that can do both HTTP load balancing and TCP load balancing. We shall be using it for TCP load balancing as discussed in the previous post. In this post, we shall look into few implementation details of the load balancer and start off with how to install it:

For installation, follow this procedure:
sudo apt show haproxy
sudo add-apt-repository ppa:vbernat/haproxy-1.7
sudo apt update
sudo apt install -y haproxy
The above commands will help you install the software. Now, its time to program what we need. There are three programmable components of HAProxy - ACL, Frontend and Backend. The below diagram would give a better understanding of the same.

HAproxy load balancing 
Now, we need to configure the load balancer to act as an L4 load balancer. To do the same, we need to add code to an already existing configuration file. We can achieve the same through the below command and code:

sudo nano /etc/haproxy/haproxy.cfg

A file would be displayed, append the below code to it:
frontend http_front
   bind *:80
   stats uri /haproxy?stats
   default_backend http_back

backend http_back
   balance roundrobin
   server <server1 name> <private IP 1>:80 check
   server <server2 name> <private IP 2>:80 check
The above is an example of the code we shall be using. We can observe that the lb algorithm used in the above code is round robin. We shall be using something called source that will do IP hashing, thus ensuring that requests from one client always end up going to the same server. 

Few other properties provided by HAProxy, we shall be using sometime next week or so:
  • MaxCDN - it is essentially a CDN service that ensures that no one server is overloaded with traffic. It acts like a middle man which uses OverShield to protect HAProxy servers as a second level point of failure between clients and servers.
  • Health check - HAProxy also provides a service where programmers can come to know if any server is down. It just sends a TCP packet and waits for response on particular ports. Depending on whether the response comes back, it can be deteted if a server is alive or not.
  • stick table - additionally used to maintain the server and client mappings. We might use it in the future in our project to either maintain IP hashing or to dynamically change the IP hashing when a fail-over happens.
  • ACL - access control lists are a set of IF like conditions. If the conditions are met, we can perfoerm actions on the packets. In the future, when we implement detection algorithm on the load balancer, we can use ACL to directly drop few attack packets thus protecting our controller distributed architcture even before they can be attacked.
There are many such interesting features provided by HAProxy. Today I found these many, if I find more, will keep you updated on the same!!!
In tomorrow's post, we shall try implementing all of this on the netowrk that we have built with 8 hosts and 3 zodiac fx switches and all as mentioned in my Day 26 post.

Refer to previous and next posts here.

Author: Shravanya
Co-author: Swati

Comments

Popular posts from this blog

Day 12: Master Slave SDN Controller Architecture

Day 50: Tcpreplay and tcpliveplay approach

Day 10: Mininet Simulation of a basic distributed SDN controller architeture