Configure HAProxy Server (Load Balancer) by Ansible-role.

Today we are going to configure Httpd Web-server with the help of AWS Ec2 instance , Haproxy Load Balancer and Ansivle Roles….

So let’s Start …….

There are certain steps to configure this Web-Server.

Steps :

Step 1 : Create Httpd Web-Server Ansible role.

Step 2 : Create Haproxy Ansible role.

Step 3 : Configure the Cluster.

Cluster :

What is HAProxy ?

HAProxy (High Availability Proxy) is a TCP/HTTP load balancer and proxy server that allows a webserver to spread incoming requests across multiple endpoints. HAProxy is known as “the world’s fastest and most widely used software load balancer.” This is useful in cases where too many concurrent connections over-saturate the capability of a single server. Instead of a client connecting to a single server that processes all the requests, the client will connect to an HAProxy instance, which will use a reverse proxy to forward the request to one of the available endpoints, based on a load-balancing algorithm.

What is Apache Web Server?

Mitigating Apache Internal Dummy Connection issue | KnackForge, Your  Technology Partners

Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web. It’s widely thought that Apache gets its name from its development history and process of improvement through applied patches and modules but that was corrected back in 2000. It was revealed that the name originated from the respect of the Native American tribe for its resiliency and durability.

What is Ansible ?

Ansible 101 Getting Started. Ansible is an agentless automation that… | by  Winton Huang | Medium

Ansible is open-source software that automates software provisioning, configuration management, and application deployment. Ansible is included as part of the Fedora distribution of Linux, owned by Red Hat, and is also available for Red Hat Enterprise Linux, CentOS, OpenSUSE, SUSE Linux Enterprise, Debian, Ubuntu, Scientific Linux, and Oracle Linux via Extra Packages for Enterprise Linux (EPEL), as well as for other operating systems. Ansible is procedural rather than declarative. In ansible, we define what we want to do and ansible go through each and every step for that. Ansible uses SSH to connect to remote hosts and do the setup, no software needed to be installed beforehand on a remote host. It’s simple, powerful and flexible.

  1. defaults: contains default variables for the role. Variables in default have the lowest priority so they are easy to override.
  2. vars: contains variables for the role. Variables in vars have higher priority than variables in defaults directory.
  3. tasks: contains the main list of steps to be executed by the role.
  4. files: contains files which we want to be copied to the remote host. We don’t need to specify a path of resources stored in this directory.
  5. templates: contains file template which supports modifications from the role. We use the Jinja2 templating language for creating templates.
  6. meta: contains metadata of role like an author, support platforms, dependencies.
  7. handlers: contains handlers which can be invoked by “notify” directives and are associated with service.

Hope you got some basics of our today’s Agenda …

So , Let’s Do Our Task…!!

Step 1 :

Create Httpd Web-Server Ansible role.
ansible-galaxy init apache

Step 2 :

Create Haproxy Ansible role.
ansible-galaxy init haproxy

Step 3 :

Configure the Cluster.

First we check our network connectivity

ansible all -m ping

Now, we are going to run our Httpd server apache role.

- hosts: Load_Balancer_Server
  roles:
          - apache 

ansible-playbook httpd.yml

and now we are going to run our HAProxy server role.

- hosts: Httpd_Server
  roles:
          - apache 

ansible-playbook haproxy.yml

so in this way our setup is done, so Let’s see the result.

Result :

our web server is launched with Load Balancer.

so to see the final result means our webApp , we have to add Load Balancer ip with port number.

http://”haproxy server ip”:”listening port”

http://3.64.19.239:8080

and our backend server ips are,

pub ip – 3.84.251.201, private ip – 172.31.86.41

pub ip – 3.82.217.65 , private ip – 172.31.95.23

This is server 1 with same Load – Balancer IP.

This is Server 2 with Same Load-Balancer IP

Conclusion:

we have learned how to configure haproxy Software using the ansible roles. In this way, we can see that how easily we able to configure such a complex task using ansible roles. and this is the power of ansible roles in the configuration world.

so please read it and enjoy and get more knowledge…

Here is my Git-Hub Accout link is given so go there and download the code.

https://github.com/mtg-tech/task15

Thank You….

Leave a comment

Design a site like this with WordPress.com
Get started