Skip to content

Ansible-playbook for creating creating HAproxy Load balancer and register backend Httpd to load balancer where put webpage and this webpage access by using Load Balancer IP and port no.

Notifications You must be signed in to change notification settings

Pratikshinde55/Ansible-loadBalancer-webserver-configuration

Repository files navigation

Ansible-loadBalancer-webserver-configuration

🌟 Configuration of Load balancer & webserver using Ansible Automation 🌟

Screenshot 2024-03-18 154506

Manual way or using Ad hoc command Configuration of Load balancer & webserver using Ansible Automation in given link: (https://github.com/Pratikshinde55/Load-Balancer.git)

❄️ By using Ansible Automation (playbook):

For this Configuration i take four instances, Amazon linux EC2 instances.

one for Ansible-Master node : 54.197.11.139

two instances for webserver (Backend): Public IP backend 1- 54.159.221.239,Backend 2- 44.202.88.227

one for Load Balancer (Frontend):lb: 18.206.228.124

Screenshot 2024-03-08 185237

In ansible master node i created 2 playbooks one for Loadbalancer and one for webserver & one jinja template file and one webpage.

Screenshot 2024-03-08 191538

⚡Step-1:

In master node 1st i created webpage (index.php): This webpage index.php is deploy to webserver which can client access from browser:

  #cat > index.php

Screenshot 2024-03-08 191718

⚡Step-2:

Create Inventory , In inventory i made two groups "Web" group for webserver nodes & "lb" group for LoadBalancer node:

  #vim /etc/ansible/hosts

Screenshot 2024-03-08 192439

we can check ansible list of hosts using following command:

Screenshot 2024-03-08 192031

⚡Step-3:

Now Create Webserver (Backend) playbook and here hosts for webserver playbook is "web" group, in web group two instances are kept:

In this playbook 1st Task install Httpd package , 2nd Task is Install php package which is because my webpage in the for of '.php' , 3rd is Deploy web page index.php to destination "/var/www/html/" & 4th Task for start httpd service:

#vim webserver.yml

Screenshot 2024-03-08 191743

⚡Step-4:

Run Webserver.yml playbook - this playbook do configuration in web group where Two nodes .

 #ansible-playbook webserver.yml

Screenshot 2024-03-08 192223

⚡Step-5:

Now for Load Balancer need registration of backend nodes for this , i created jinja file "pratik.cfg.j2" which pass registration information to LoadBalancer playbook "lb":

 #vim pratik.cfg.j2

Screenshot 2024-03-08 191830

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 .

⚡Step-6:

Create Load balancer Playbook "lb.yml", add lb group where only one instance for lb IP:-18.206.228.124

In this playbook 1st task for install haproxy package It is loadBalancer that i used,

2nd task for rigistration of backend webservre to Load balncer for this pratik.cfg.j2 jinja template used , In haproxy Load balancer configuration file for load balancer is kept in "/etc/haproxy/haproxy.cfg"

3rd task for Start haproxy service

  #vim lb.yml

Screenshot 2024-03-08 191851

Note:

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

⚡Step-7:

Run Load balancer "lb.yml" playbook , This do load balncer configuration on lb group:

#ansible-playbook lb.yml

Screenshot 2024-03-08 192329

💥Configuration of Load balancer & webserver done successfully:

Check on Google or Browser Publich IP load balancer : port no. that bind:

http://18.206.228.124:8080

Screenshot 2024-03-08 193442

Note:

Load balancer node Inbound rules ->> All trafic , Anywhere ( remove Firewall )

Screenshot 2024-03-08 185340

About

Ansible-playbook for creating creating HAproxy Load balancer and register backend Httpd to load balancer where put webpage and this webpage access by using Load Balancer IP and port no.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages