Manual way or using Ad hoc command Configuration of Load balancer & webserver using Ansible Automation in given link: Load-Balancer-manual
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
In ansible master node created 2 playbooks One for Loadbalancer and One for Webserver & One jinja template file and one webpage.
Step-1: [In master node 1st create Webpage(index.php): This webpage index.php is deploy to webserver which can client access from browser]
cat > index.php
Step-2: [Create Inventory, In Inventory made two groups "Web" group for webserver nodes & "lb" group for LoadBalancer node]
vim /etc/ansible/hosts
We can check ansible list of hosts using following Command:
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 ansible-playbook:
-
Task install Httpd package,
-
Task is Install php package which is because my Webpage in the form of '.php',
-
Taskis Deploy Webpage index.php to destination "/var/www/html/",
-
Task for start httpd service.
vim webserver.yml
ansible-playbook webserver.yml
Now for this, create jinja file "pratik.cfg.j2" which pass registration information to LoadBalancer playbook "lb":
vim pratik.cfg.j2
- 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 number as 8080.
Create Load balancer Playbook "lb.yml", add lb group where only one instance for lb IP:-18.206.228.124
In this playbook:-
-
task for install haproxy package It is loadBalancer that i used,
-
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"
-
task for Start haproxy service
vim lb.yml
- 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.
Run Load balancer "lb.yml" playbook , This do load balncer configuration on lb group:
ansible-playbook lb.yml
Check on Google or Browser Publich IP load balancer : port no. that bind:
Example:- http://18.206.228.124:8080
- Note:
Load balancer node Inbound rules ->> All trafic , Anywhere ( remove Firewall )