Configure Web Server and Load Balancer using Ansible in Redhat Linux OS
A computer which gives service to host the website for real world is known as web server , i have configured apache software on OS for use as web server .
Apache web server is run on port number 80 , it can be changed . Root directory of apache webserver is “/var/www/html”
In apache client authentication is done by webserver , for configure authentication through webserver first of all need to edit file “/etc/httpd/conf/httpd.conf”
After edit file run below command , this command will update data base for username
htpasswd /etc/www.passwd username
After add user to database create file “.htaccess” in root directory of web server as :
After done all the process restart webserver using below command
systemctl restart httpd
Load balancer: Load balancer balance the traffic of webservers or applications . It transfer the traffic among servers so that single point of failure is avoided.
Haproxy is free open source software that provides a high availability load balancer and proxy server for tcp and http based application , that spreads requests across multiple servers.
For configure web server and load balancer created ansible playbook
- hosts: mywebtasks:
- command: "ls -l /dvd"
when: x.rc != 0
description: "This is dvd1 for package"
gpgcheck: no - yum_repository:
description: "This is dvd2 for package"
- name: "install web server"
state: present - name: "install php"
src: "index.php" - replace:
regexp: "AllowOverride None"
replace: "AllowOverride AuthConfig" - copy:
dest: "/var/www/html/.htaccess" - package:
name: "python36" - pip:
enabled: yes - firewalld:
immediate: yes- hosts: mylbtasks:
- name: "install load balancer"
name: "haproxy" - template:
dest: "/etc/haproxy/haproxy.cfg" - service:
state: restarted - firewalld:
use below github link for get full code
For configure load balancer and update backend server in /etc/haproxy/haproxy.cfg file use jinja technique as
After creating playbook run below cmd
After running playbook load balancer and webserver are configured automatically
Use url as https://ip_of_load_balancer:5000
clap, if you like this . give any suggestion if required. your suggestion will be appreciated.