Skip to content

Creating HAProxy Load Balancer and Register Backend to LB (/etc/haproxy/haproxy.cfg) on the top of AWS Cloud.

Notifications You must be signed in to change notification settings

Pratikshinde55/LoadBalancer-HAProxy-AWS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 

Repository files navigation

Load-Balancer Set-up on the AWS Cloud using HAproxy LB:

Screenshot 2024-02-28 193427

Load balancer distribute workload and improve website and application performance.

load balancer distribute incomming application traffic across multiple backend(target).load balancer also called as Frontend or reverse proxy.

Haproxy:-

HAproxy is one of the product of load balancer, HAproxy is a high-performance, open source load balancer & reverse proxy for HTTP and TCP .

  • Set-up:

For Loadbalancer setup I launched 4 AWS EC2 Instances One Instance make Load Balancer(Frontend),and remaining three make Backend, In my case named as Backend-1 (ip-172-31-44-4) ,Backend-2 (ip-172-31-33-138),Backend-3(ip-172-31-40-19).

Screenshot 2024-02-28 193350 Screenshot 2024-02-28 175417

Step:1- [Backend Configuration(Web server)]

On three Backend instances, configure following same set-up as it is on each backend nodes:

  1. Install httpd php software(Apache):

    yum install httpd php -y
    
  2. DocumentRoot for "Apache server is /var/www/htmt" Create here one code folder which is access for client. here put Webpage named as index.php:

    cd /var/www/html
    

Create index.html Webpage:

vim index.php

code:-

 <pre>
 <?php

      print_r($_SERVER);

 ?>
 </pre>
  1. Start the httpd service:

    systemctl enable httpd --now
    

Screenshot 2024-02-28 190802

Step:2- [Load Balancer configuration]

  1. Install HAproxy load balancer in frontend instance.

    yum install haproxy -y
    
  2. Registration of Backend to Load Balancer, HAproxy config file "/etc/haproxy/haproxy.cfg" where add backend node and also add port number which can helps to client to access the Application. for this do follow setup:

    vim /etc/haproxy/haproxy.cfg
    

ADD this code in config file:

Screenshot 2024-02-28 190246

  • Note:

here we use Round Robin Algorithm that work as client will connect to web server through Load balancer , 1st connect to web 1 then web 2 and next web 3 then again go to 1. here also bind the port no. as 8080 .

  1. Start HAproxy service and check status:

     systemctl restart haproxy
    
     systemctl start haproxy
    
     systemctl status haproxy
    
  2. Check HAproxy config file is valid or not:

    haproxy -f haproxy.cfg -c

Step:3- [Access LoadBalancer from Browser]

Now loadbalancer configuration is done.

Load Balancer(Frontend) instance change Inbound rule - allow all traffic Anywhere

Check Load balancer on browser:

Public IP of LB + port no. (http://65.0.18.65:8080)

Also on local command prompt -->>(curl http://65.0.18.65:8080)

Screenshot 2024-02-28 190614 Screenshot 2024-02-28 190525 Screenshot 2024-02-28 190456

About

Creating HAProxy Load Balancer and Register Backend to LB (/etc/haproxy/haproxy.cfg) on the top of AWS Cloud.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published