Ansible playbook to Configure Reverse Proxy

Ansible playbook to Configure Reverse Proxy

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.

1)??What is Load Balancer?

Load balancing?refers to efficiently distributing incoming network traffic across a group of backend servers, also known as a?server farm?or?server pool.

Modern high?traffic websites must serve hundreds of thousands, if not millions, of concurrent requests from users or clients and return the correct text, images, video, or application data, all in a fast and reliable manner. To cost?effectively scale to meet these high volumes, modern computing best practice generally requires adding more servers.

A?load balancer?acts as the “traffic cop” sitting in front of your servers and routing client requests across all servers capable of fulfilling those requests in a manner that maximizes speed and capacity utilization and ensures that no one server is overworked, which could degrade performance. If a single server goes down, the load balancer redirects traffic to the remaining online servers. When a new server is added to the server group, the load balancer automatically starts to send requests to it.

?In this manner, a load balancer performs the following functions:

·?????Distributes client requests or network load efficiently across multiple servers.

·?????Ensures high availability and reliability by sending requests only to servers that are online.

·?????Provides the flexibility to add or subtract servers as demand dictates.

No alt text provided for this image

Benefits of Load Balancing

·???????Reduced downtime

·???????Scalable

·???????Redundancy

·???????Flexibility

·???????Efficiency

1)??What is HAProxy?

HAProxy, which stands for High Availability Proxy, is a popular open-source software TCP/HTTP Load Balancer and proxying solution which can be run on Linux, Solaris, and FreeBSD. Its most common use is to improve the performance and reliability of a server environment by distributing the workload across multiple servers (e.g., web, application, database). It is used in many high-profile environments, including GitHub, Imgur, Instagram, and Twitter.

Ansible:

Ansible?is a software tool that provides simple but powerful automation for cross-platform computer support. It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible does not depend on agent software and has no additional security infrastructure, so it's easy to deploy

No alt text provided for this image

So, you are going to design this architecture using the Automation tool Ansible.

Pre-requisite

To configure the above architecture, you have some pre-requisite which are mentioned here.

1.???Configured Ansible Controller node

2.?????4 or more than 4 Virtual machines (i.e., MN1, MN2, MN3, LB)

Step1: We have Installed the ansible in CN and setup the ansible.cfg file in /etc/ansible

No alt text provided for this image

Set the Inventory.txt

No alt text provided for this image

Check the setup using:?

 ansible all --list-hosts        
No alt text provided for this image

check that all?managed nodes?are pingable or not, Using:

ansible all -m ping        
No alt text provided for this image

Create a workspace and copy?haproxy.cfg?into the?controller node.?

No alt text provided for this image

# Binding with port 8080

Open the?haproxy.cfg?file in the controller node and bind the?port 8080.

No alt text provided for this image

Also, write the jinja code to update the?haproxy.cfg?file to perform Load Balancer Dynamically.

No alt text provided for this image

Step2: Create an?Ansible playbook?to configure the Web servers and load balancer.

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

Check the Syntax of the playbook using:

ansible-playbook --syntax-check <playbook_name>.yml        
No alt text provided for this image

Now, Run the playbook using:

 ansible-playbook <playbook_name>.yml        
No alt text provided for this image

Check the haproxy.cfg?file is updated, in LB VM using:

 Vim /etc/haproxy/haproxy.cfg        
No alt text provided for this image

You can see in the above screenshot, the?haproxy.cfg?file is updated.

Let’s check the Load Balancer is working or not.

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

It works well with two web servers.

so let's look at how to connect the load balancer to a new web server, if you want to add one or more web servers now.

Open your inventory file in CN and add the information of New OS.

No alt text provided for this image

Now, Run the playbook again using:

???? ansible-playbook <playbook_name>.yml        
No alt text provided for this image

Check the haproxy.cfg?file is updated, in LB VM using:

 Vim /etc/haproxy/haproxy.cfg        
No alt text provided for this image

Now, verify the setup.

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

Load Balancer is also working great with all the three web servers.

GitHub link:?

Thank You

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

Anudeep Nalla的更多文章

社区洞察

其他会员也浏览了