Setup High-Availability Load Balancer with ‘HAProxy’ to Control Web Server Traffic..

Use Ansible playbook to Configure Reverse Proxy i.e. Haproxy and update it’s configuration file automatically on each time new Managed node (Configured With Apache Webserver) join the inventory.

Setup High-Availability Load Balancer with ‘HAProxy’ to Control Web Server Traffic

🤩So guys this is my new article which give you some high level idea about ANSIBLE , HAProxy , Apache Webserver & php.

I am confident to tell you , you will definitely learn something new from this article . 🔥🔥

I am going to discuss about Load Balancer concept in depth.

Starting this article from the scratch.

TASK DESCRIPTION

Use Ansible playbook to Configure Reverse Proxy i.e. Haproxy and update it’s configuration file automatically on each time new Managed node (Configured With Apache Webserver) join the inventory.

ANSIBLE

HAProxy

Learn more about HAProxy then walk with this Article👉 http://www.haproxy.org/

Apache Web Server

PHP

→ Step 1 : Install & Configure the ansible.

So now the question is how do we install the ansible in our RHEL 8. So for the installation process we will use python module to install the ansible tool.

To install the ansible we use this command

So after the installation we have to configure the ansible to use it & before that we have to define the managed node that means which system gonna we will use as a remote system. So for that we have to create a file inside the /root/ folder ( to define the hosts )with the ip.txt . So we use the command to create a host like.

In My case Load Balancer ip is 192.168.43.159

& Webserver1 ip’s is 192.168.42.111

Webserver2 ip’s is 192.168.42.111

After creating the hosts file we will create the configuration file for ansible because without configuration any software we can not use it properly & we can not use our hosts to work on it.

To configure the ansible first of we create a directory inside the /etc/ansible folder , after that we have to create the file with the name of ansible.cfg to use this file as a configuration file & we have to write the inventory name ( that will be the host file where we write our remote system IP ) inside that file. Then we have to pass the SSH Key authentication , So we have to make false this option so that there will no problem while doing the authentication.

write this code inside the file .

After we have to install the SSH pass with help of yum command , we use the command like :

After that we have to check that our ansible command is working or not properly simply means which version is install . Use below mentioned command:

So with the help of this command we can find that our ansible file is successfully configured & command is working properly.

Now we can check how many hosts we have with the help of below mentioned command:

It shows outputs a list of matching hosts; does not execute anything else .

After checking the hosts name we have to check that there is proper connection established between the controller node & managed node or not . So we can ping the managed node from our controller node to check the connectivity . Command will be like

It shows ping : pong means CN is pinging to all MN.

So after checking this connection we have to write the code for the entire deployment of the docker with the help of ansible.

→ Step 2 : Write the ansible playbook for Reverse Proxy i.e, HAProxy.

So to deploy the entire setup we can use the command line or ansible-playbook option , but through the command line it is difficult for us to deploy the entire setup , so we use the ansible-playbook option for this task.

But here you first know what is Ansible-playbook…

What is Ansible-playbook ?

An Ansible playbook is an organized unit of scripts that defines work for a server configuration managed by the automation tool Ansible.

A playbook is a configuration file written in YAML that provides instructions for what needs to be done in order to bring a managed node into the desired state. Playbooks are meant to be simple, human-readable, and self-documenting. They are also idempotent, meaning that a playbook can be run on a system at any time without having a negative effect upon it. If a playbook is run on a system that’s already properly configured and in its desired state, then that system should still be properly configured after a playbook run.

So Now we write the code for the entire deployment. first we have to define the host name & then multiple task.

In my case I will create file /root/ansible-ws/haproxy location

We have to update it’s configuration file automatically on each time new Managed node join the inventory.

So HAProxy configuration file look like this 👇

Now it`s time to run our Ansible-playbook

After successfully run Ansible-playbook .

Now it`s time to check via Browser our Load Balancer is work or not .

So you can see that our Task will run successfully

* LINKEDIN PROFILE LINK :- https://www.linkedin.com/in/jatin-lodhi

* MEDIUM PROFILE LINK :- https://jatinlodhi.medium.com/

THANKS FOR EVERYONE TO READ THIS ARTICLE !!🤗

Thanks, Everyone for reading. That’s all… Signing Off… 😊

I am an IT Enthusiast, who is passionate about exploring/learn all the latest technologies from research perspective.