Configure Load Balancer

Posted By : Swarnim Kashyap | 16-Mar-2022

What is Ansible?

Ansible is a software tool that is used for configuration management It intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, all task of systems administrator. Ansible is not depend on agent software and it has no additional security infrastructure, So it is easy to deploy.

How Ansible works?

In Ansible, there are two kind of nodes: the control node and managed nodes. The control node is a computer runs where we insalled  Ansible. There must be one control node. A managed node is any device or computer node which is  being managed by the control node.

Ansible works by connecting to controller nodes on a network, and then sending a small program known as  an Ansible module to that node. Ansible will executes these module over SSH and removes them when they finished. SSH keys are the most common way to access the nodes, but other forms of authentication are also supported in ansible.

What is Ansible playbooks?

A playbook is a file which is written in YAML language 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 very simple, easily human readable, and self-documenting. Ansible is also idempotent in nature which means that a playbook can be run on a system at any time without having a negative effect on it. 

A playbook can be simple, such as this:

- name: Apache server installed
hosts: webservers
become: yes

Playbooks can also be complex, with conditionals and variables. However most of the real work is done by Ansible modules, playbooks , and clear even though they can orchestrate entire networks of managed nodes.

What is HAProxy?

 

HAProxy is a open-source high-performance load balancer reverse proxy service for TCP and HTTP applications. We can use HAProxy load balancer to improve the performance of our applications and websites by distributing their workloads accordingly. HAProxy is used mostly in high traffic services such as Twitter and GitHub.

We can use Load balancers to distribute workloads across computers, networks, disk drives or CPU”s . HAProxy included in many distributions of Linux. Most of operation makes the entire integration into existing and it's architectures riskless and very easy, while still offering the possibility not to expose fragile web servers to the net, such as below :

 

What Is Apache Web Server?

Apache is a cross-platform web server,popular open-source software that is by the number. It’s keep maintained by the Apache Software Foundation.

Some high-profile companies using Apache include VMware, IBM, Cisco, Salesforce, Xerox, Adobe, VMware, General Electric, LinkedIn, Hewlett-Packard, AT&T, Facebook,Siemens, eBay, and many more. In addition to their popularity, it is also one of the oldest web servers, with its first release in 1995.

Let’s start with the practical implementation of Load Balancer:

We have require:?

1. Managed Node .

2. Target Node.

 

 

We will move this in  “cd/etc/ansible/ansible.cfg” this file tell this is my default configuration and my IP is store inn that given directory.

 

To check connectivity we will use above command given in the image: "ansible all -m ping"

 

“ vim /etc/haproxy/haproxy.cfg” 

First of all your backend will work as a Load Balancer with a mechanism called Roundrobin,and here we have to give all our webserver .In this above location we have to defined about our backend part. This is for which we use above it will help us to automatically fetch all the IP given to Target Node so that we can easily apply haproxy configuration here.

 

Here i have mentioned my entire ansible-playbook for configuring webserver and Loadbalancer by haproxy ?.

 

Here is my  index.php file in which i ask to run ifconfig command to test load balancer.

Now it’s time to run our Ansible-Playbook:

 

In the above image we have seen that our playbook is running succcessfully now its time to check that webserver that its working fine or not.

 

Yeah as we see above image that we have configure my first target node at port no: 8080 and when we will refresh the webpage we will see that it change in  IP of our second target node.?

 

Here we successfully configure.,
Thankyou

About Author

Author Image
Swarnim Kashyap

Swarnim is working as a DevOps Engineer. He is skilled in DevOps tools like Ansible, AWS,Docker, Linux and Jenkins. He believes in hard work and is always ready to face new challenges.

Request for Proposal

Name is required

Comment is required

Sending message..