Skip to main content

Configuring 2 backend servers and a load balancer with HAProxy

A load balancer is a device that distributes the traffic across a cluster of servers.

In computing, load balancing improves the distribution of workloads across multiple computing resources, such as computers, a computer cluster, network links, central processing units, or disk drives.As a result, it improves responsiveness and increases the availability of applications. 

For load balancing, we need to install LAMP server on backend servers and HAProxy on the load balancer.

HAProxy is a free, open source software that provides a high availability load balancer and proxy server for TCP and HTTP based applications that spread requests across multiple servers.

Here we will make two backend servers and one load balancer.


At two backend servers enter the following commands—

$sudo apt-get install apache2
$sudo apt-get install mysql-server
$sudo apt-get install php libapache2-mod-php php-mysql
$sudo gedit /var/www/html/index.html
(Make some changes in the index.html file to observe on the load balancer)

At Load Balancer-

Step 1: Enter the IP of the backend servers on the browser of the load balancer and observe the changes made in the HTML file.If the changes are reflected than the server is working.



Step 2:
$sudo apt-get install haproxy
$haproxy –v
$sudo gedit /etc/haproxy/haproxy.cfg
Step 3: Enter the followings at the bottom of the cfg file and then save and exit—
Listen webbalance
Bind *:80
Balance round robin        //It is the algorithm’s name
Option forwardfor          //forwarding IP to the server
Option httpchk                //health check-up
Server webserver1 192.168.12.221:80 check   //IP of server1
Server webserver2 192.168.12.222:80 check   //IP of server2

Step 4: Enter load balancer’s IP address on the browser of a different system and check the working.
Step 5: In the browser enter,192.168.11.145/haproxy?stats



Comments

Popular posts from this blog

What is a Network Hub?

Hub is the most simple networking device which is used to connect all network devices on an internal network. It detects whether a device is physically connected to it or not. It is a Layer 1 device in OSI reference model and is best for small and simple local area networks. It is not intelligent because it does not filter any data. When a packet is received by one port, the data is copied to all other ports and is seen by all connected devices. It has 4/12 ports . Drawbacks of Hubs are:- Rebroadcast- Forwards packets across all ports. Creates Security concerns- Traffic could not be safeguarded. Unnecessary traffic which reduces bandwidth.   

Network Layer

Network Layer(Layer 3):  It is responsible for the source-to-destination delivery of packets across multiple links(networks).It is also responsible for structuring and managing a multi-node network, including addressing, routing, and traffic control. Functions include: Logical Addressing: IP addressing is defined at the Network Layer of the OSI model. This layer adds a header to the packet coming from the upper layer that, among other things, indicates the logical addresses of the sender and receiver. IP addressing is also known as logical addressing. Routing: When independent networks are connected together to create a large network, the connecting devices(routers/gateways) route the packets to their final destination. The decision which route/path should be followed to reach from source to destination is handled by the network layer. 

OSI Model

The OSI(Open System Interconnection) model is a layered framework to implement protocols. It consists of seven separate but related layers, each of which defines a part of the process of moving information across a network.  The International Standards Organisation(ISO) developed the Open Systems Interconnection(OSI) model .  An open system is a set of protocols that allows any two different systems to communicate regardless of their underlying architecture. The OSI model is not a protocol. It is a model for understanding and designing a network architecture that is flexible, robust and interoperable. The Seven Layers of OSI are:- 7.Application 6.Presentation 5.Session 4.Transport 3.Network 2.Data Link 1. Physical