Configuring Load Balancer or Reverse Proxy Using ANSIBLE-Playbook on RHEL 8.
In this Post we are going to see that How We can configure Load Balancer or Reverse Proxy on the top of RHEL 8 using Ansible Playbook.
Designed for multi-tier deployments since day one, Ansible models your IT infrastructure by describing how all of your systems inter-relate, rather than just managing one system at a time.
It uses no agents and no additional custom security infrastructure, so it’s easy to deploy — and most importantly, it uses a very simple language (YAML, in the form of Ansible Playbooks) that allow you to describe your automation jobs in a way that approaches plain English.
Load Balancer :
A load balancer is a device that acts as a reverse proxy and distributes network or application traffic across a number of servers. Load balancers are used to increase capacity (concurrent users) and reliability of applications. They improve the overall performance of applications by decreasing the burden on servers associated with managing and maintaining application and network sessions, as well as by performing application-specific tasks.
Now Let’s start the Configuration..
I am assuming that you haven’t install Ansible in your Machine or Instance. So Let’s start from the very basic from installing Ansible in your Machine.
For installing Ansible on your machine type command pip3 install ansible, why pip3 because Ansible is developed in Python.
After running this command on your machine you will be able to see an success message that ansible is installed successfully on your machine. After installing ansible create an inventory, that contains the Ips of your machine in which you want to configure Load Balancer.
In my case the name of the inventory file is myhosts.txt which contains two groups one group is for the configuration of Load Balancer and in my case that group is [mylb] and second one is for configuring webserver which is [myweb]. See the image above that gives you clarity about the inventory file.
After creating an inventory, Now you have to tell the Ansible about your inventory file so for that go to your Ansible’s configuration file vim /etc/ansible/ansible.cfg and write some lines of code on that as shown on the image below in which you have to tell ansible that where is your inventory file exists in my case the inventory file is located in /etc/myhosts.txt.
For Configuring Load Balancer on RHEL 8 we have to install haproxy in our Controller node by using a command called yum install haproxy
After running this command haproxy is now installed in your machine.
After doing these steps now we are ready for writing our Ansible-Playbook.
I am assuming that you have ample knowledge of Ansible Playbooks. So the image given below will configure haproxy for us.
So this is our playbook which we are going to use for configuring Load Balancer or haproxy.
After writing the playbook now you have to make some changes in the configuration file of haproxy and the configuration file is located at /etc/haproxy/haproxy.cfg.
Now comes the very important part of this task, and that task is to set the configuration file. Now first you have to create a file named haproxy.cfg in your same directory where your playbook is located, and the content of this file is same as the content of original haproxy.cfg which is located at /etc/haproxy/haproxy.cfg only with some small changes in it and this small change is shown in the image below..
Only you have to change the backend app section and write these codes in it.
Now you are all set and ready to run your Playbook, Now type the command ansible-playbook lb.yml
This shows that without any error our playbook runs successfully and the Load Balancer is configured to.
Now go to your Browser and type the Ip of your Controller node which is in my case is 192.168.43.51:5000 and along with the Ip you have to write :5000 because by default haproxy or load balancer works on the port no 5000, and now after pasting the Ip on the browser you will be able to see these pages..
This is our 1st page
This is our 2nd page
You can see real time load balancing that and when u refresh the page it will again change the IP . and same output will come for client .
That’s All We Have Successfully Configured the Load Balancer ..!!
For Further Queries Or Suggestions Feel Free to Connect with me LinkedIn..
Aditya Kumar - Bokaro Steel City, Jharkhand, India | Professional Profile | LinkedIn
View Aditya Kumar's professional profile on LinkedIn. LinkedIn is the world's largest business network, helping…
Thank you Everyone For Reading ..!!