Configuring reverse proxy with Ansible and also updating Haproxy conf file each time new node(aws instance)join inventory
This blog is Something about Configuring Reverse Proxy i.e. Haproxy and updating it’s configuration file automatically on each time new Managed node (Configured With Apache Webserver) join the inventory on AWS.
So What Haproxy actually is..?
HAProxy is free, open source software that provides a high availability load balancer and proxy server for TCP and HTTP-based applications that spreads requests across multiple servers. It is written in C and has a reputation for being fast and efficient (in terms of processor and memory usage)
🔹Firstly we have to update the Ip addresses in Inventory file of controller node on which we want to configure something
So here in this Inventory I have updated 2 Ip’s , one for Loadbalancer and another one for Backend server.
🔹Ansible Configuration file
Here we have to update both , Inventory file location and also our key to login into AWS Instance(key should be present in controller node).
🔹Checking Connectivity of Controller node with Managed nodes
#ansible -m ping all
host: lb ➯ For Loadbalancer
host: server ➯ For Backend server
➽Haproxy file configuration
🔹 Running Playbook
Now we are done with the Controller node configuration..!!
Lets check it manually on managed node.
Lets have a look of what we configured actually.
We can see that Haproxy is installed and configured here and also Haproxy services are running very fine.
Now lets check the Haproxy configuration file also.
⭐Haproxy config file⭐
Yes…here you could see that this file is dynamically updated with the Ip of the Backend server.
🔹checking on browser
Note: You can match the Ip of backend server here ⬇
Now we can add as many new instances as managed nodes to configure them as a backend servers by just updating their IP’s to the inventory file and dynamically it will update it to the configuration file of haproxy.
So let’s configure one more backend server as a apache httpd webserver with the same webpage by just adding its IP i.e 22.214.171.124 to the inventory file.
🔹Adding one new ip to inventory
Now we just have to run the playbook again and thats it.
This server is launched successfully.
Lets check whether this Backend server is updated in Haproxy file of loadbalancer or not.
🔹Checking haproxy config file
You could see both the ip’s of the both the servers are updated here dynamically.
Note: you can match the ip of newly added server from here⬇
🔹Finally ..lets check both the servers on browser
When we hit firstly to the loadbalancer we will get one of the server’s webpage ⬇
But when we hit second time to the Loadbalancer we will get another server’s webpage with the same content.
✨Loadbalancer is working very fine…✨