A load balancer is a device that distributes the traffic across a cluster of servers.
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
Post a Comment