LOAD BALANCING WITH HAPROXY

LOAD BALANCING WITH HAPROXY

 Task Description

12.1 Use Ansible playbook to Configure Reverse Proxy i.e., HAproxy and update its configuration file automatically on each time new Managed node (Configured with Apache Webserver) join the inventory.

12.2 Configure the same setup as 12.1 over AWS using instance over there.

What is Ansible?

  1. Ansible is simple open-source IT engine which automates application deployment, intra service orchestration, cloud provisioning and many other IT tools.
  2. Ansible uses playbook to describe automation jobs, and playbook uses quite simple language i.e., YAML (It’s a human-readable data serialization language & is commonly used for configuration files but could be used in many applications where data is being stored) which is very easy for humans to understand, read and write. Hence the advantage is that even the IT infrastructure support guys can read and understand the playbook and debug if needed (YAML — It is in human readable form).
  3. Ansible is designed for multi-tier deployment. Ansible does not manage one system at time, it models IT infrastructure by describing all your systems are interrelated. Ansible is completely agentless which means Ansible works by connecting your nodes through SSH (by default). But if you want other method for connection like Kerberos, Ansible gives that option to you.

How Ansible Works..?

In Ansible, there are two categories of computers: the control node and managed nodes. The control node is a computer that runs Ansible. There must be at least one control node, although a backup control node may also exist. A managed node is any device being managed by the control node.

Ansible works by connecting to nodes (clients, servers, or whatever you’re configuring) on a network, and then sending a small program called an Ansible module to that node. Ansible executes these modules over SSH and removes them when finished. The only requirement for this interaction is that your Ansible control node has login access to the managed nodes. SSH keys are the most common way to provide access, but other forms of authentication are also supported.

What is HAproxy ?

HAProxy is a free, amazingly fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for extremely high traffic web sites and powers quite a number of the world’s most visited ones. Over the years it has become the de-facto standard opensource load balancer, is now shipped with most mainstream Linux distributions, and is often deployed by default in cloud platforms. Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the internet.

No alt text provided for this image

Let us start with the practical :

? Pre-Requisites:

1.Installed boto/boto3 in controller node

2.AWS account

3.Installed Ansible

4. Installed HAproxy in controller node

Here I’m checking the ansible version :

command : ansible — version

No alt text provided for this image

Now we have to go at managed node.. and check the IP of the managed node . When we can get the IP of managed node then go to the controller node and create the inventory file . After that create the configuration file by using the command.

Now we have to go at managed node.. and check the IP of the managed node . When we can get the IP of managed node then go to the controller node and create the inventory file . After that create the configuration file by using the command

Now we have to go at managed node.. and check the IP of the managed node . When we can get the IP of managed node then go to the controller node and create the inventory file . After that create the configuration file by using the command.

command : vim /etc/ansible/name_of_file.cfg

No alt text provided for this image

Now Create the inventory to all the hosts :

Command : vim file_name.txt

No alt text provided for this image

Check the connectivity between the controller node and target nodes using the following command:

Command : ansible all -m ping

Create an Ansible playbook for performing the practical using the following command add the following code in that file and save it :

Command : vim file_name.yml

No alt text provided for this image
No alt text provided for this image

Then we have to create the variable file to make it dynamic :

Command : vim var_file_name.yml

No alt text provided for this image

Create haproxy.cfg file using following command add the following code in that file and save it :

Here I am using jinja2 embedded code for dynamically fetch or register the new webserver IP with HAproxy loadbalancer.

Command : vim haproxy.cfg

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Create index.php file add the following code in the file and save it:

Command : vim index.php

No alt text provided for this image

Now, we have run the Ansible Playbook by using following command :

Command : Ansible-playbook file_name.yml

No alt text provided for this image
No alt text provided for this image

Now, let’s check the outcome by visiting the HAproxy server IP with HAproxy port number .

No alt text provided for this image
No alt text provided for this image

Here have you notice , the IP is switching even though the IP address which I am using at browser is same. This proves that the HAproxy is working fine.

Now the challenge is to configure HAproxy automatically when a new IP is added in the inventory.

So now, let’s add one more target node in the webserver group. For this, open the inventory file and add a new target node.

No alt text provided for this image

Previously, we only had 2 target nodes, but now, we have 3.

Now Let’s check the connectivity between the controller node and target nodes using the following command:

Command : ansible all -m ping

No alt text provided for this image

Let’s run the playbook and check if the HAproxy server automatically adds the new target node in its configuration file or not.

No alt text provided for this image
No alt text provided for this image

Here, as you can see, the tasks are changed for the new target node. Now, let us visit the HAproxy once again and check if it has recognized and updated its configuration file with the new target node or not.

No alt text provided for this image

From the above output , you can see that 3 IPs are switching, which means that the third target node is also automatically added in the configuration file of HAproxy.

Thanks!!

GAURAV DESHMUKH

Former SDE Intern @Raja Software Labs, Pune

3 年

Great Explanation !!!

回复

要查看或添加评论,请登录

Akanksha Bhatt的更多文章

  • Task-8 Automation with Python

    Task-8 Automation with Python

    ARTH - Task 8 ??????? Task Description?? ?? Create a Menu Using Python integrating all the concepts that have been…

  • Task-14.3

    Task-14.3

    ???????? ?????????????????????? : Create an Ansible Playbook which will dynamically load the variable file named same…

  • Task-14.2

    Task-14.2

    Ansible playbook that will retrieve new Container IP and dynamically update the inventory and Configure web-server…

  • Task-14.1

    Task-14.1

    Task description :- 14.1 Create a network Topology Setup in such a way so that System A can ping to two Systems System…

  • ARTH TASK-15

    ARTH TASK-15

    Task Description?? Create an ansible role myapache to configure Httpd WebServer. Create another ansible role…

    1 条评论
  • Neural Networks in Netflix

    Neural Networks in Netflix

    What are Neural Networks? Neural networks are a set of algorithms, they are designed to mimic the human brain, that is…

  • Restarting HTTPD Service is not idempotent in nature and also consume more resources suggest a way to rectify this challenge in Ansible Playbook.

    Restarting HTTPD Service is not idempotent in nature and also consume more resources suggest a way to rectify this challenge in Ansible Playbook.

    What is Idempotent nature in Ansible? An operation is idempotent if the result of performing it once is exactly the…

  • CONFIGURING HADOOP CLUSTER USING ANSIBLE

    CONFIGURING HADOOP CLUSTER USING ANSIBLE

    Welcome you all, in this blog I will cover how we can“ CONFIGURE HADOOP CLUSTER USING ANSIBLE” Before starting the…

    1 条评论
  • How Industries are Solving Challenges Using Ansible??

    How Industries are Solving Challenges Using Ansible??

    What Is Ansible ? ?? Ansible is a software tool that provides simple but powerful automation for cross-platform…

  • Configuration of Apache Web Server in Docker Container using Ansible

    Configuration of Apache Web Server in Docker Container using Ansible

    In this article we will perform various tasks: Configure Docker Start and enable Docker Services Pull the httpd server…

    1 条评论

社区洞察

其他会员也浏览了