Configuring Proxy server and updating configuration file automatically using ansible playbook
First of all we know that every server has a hardcoded limit….means?
let me explain… :)
Sometimes we often encounter connection time out when we visit some server why ? because there may be lots of user visiting at a time but these results in losing costumers which is not at all good for any commercial company then what is the solution ?
then someone may say that, then we will launch one more server and then ask customers to visit there…but lets say you have millions trillions of customers so its illogical to add so many computers and as then to visit one by one.
So what MNCs do?
They launch one computer and promote it as the host for their official website and client visit there.
but actually there no webserver configured in this computer rather its set up in such a way that its takes a request from client and passes request to the backend servers on behalf of client and then reply back to the client on behalf of backend servers , so we can say that it works like a proxy so its called proxy server.
not only this it also provides extra security How?
Client never hit the original webserver they can only hit our proxy server
What is load balancer ?
A load balancer can be deployed as software or hardware to a device that distributes connections from clients between a set of servers. A load balancer acts as a ‘reverse-proxy’ to represent the application servers to the client through a virtual IP address (VIP)
What is HAProxy ?
HAProxy is a high-performance, open-source software for setting up load balancer and reverse proxy for TCP and HTTP applications.
SO here I am configuring HAproxy using ansible playbook that is setting ip load balancer.
before creating playbook we need to update inventory here [loadbl] would be for load balancer and ips in group [backend] are for load balancer.
For backend we just simply need to configure apache webservers
- Install httpd and php using package module
- copy html file using copy module
- Start service
- Enable firewall for port.
in above screenshots I have created a playbook which doesnt need any prerequisites in the host computer you can this over a newly created os.
And for load balancer :
for loadbalancer we need to first install Haproxy software , then how do we tell our proxy server about our backend servers so for this we have to add ip address of backend servers in the backend section of configuration file of HAProxy.
so configuration file is haproxy.cfg in directory /etc/haproxy
now if we have one or two backend servers its ok we can go and manually type there but in actually we may need to add 1000s of backend servers so for such cases we need a generalize solution. so for this we use “for” loop and jinja concept in source file and give port number 8080 in bind.
In jinja for “loops” we have syntax {% loop %}
here, “groups” is inbuilt variable by ansible which we have used here in the loop and {{i}} can be said as temporary variable so it will iterate for each ip.
{{% end for %}} at the end to tell that for loop ends here.
now we can go for play book for load balancers:
- Install HAProxy
- Updating configuration file of HAProxy.
- Starting HAProxy service.
and after we run this playbook
now I have simple made some changes in the html file of both the servers so that you can see that as you put url of load balancer but behind the scene it goes to both the backend server as the client requests
so here we get result what we expected
hope you all like it !!!
thankyou.. :)