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

Ansible Playbook:

- hosts: mywebtasks:
- command: "ls -l /dvd"
register: x
ignore_errors: yes
- file:
state: directory
path: /dvd
when: x.rc != 0
- mount:
path: "/dvd"
src: "/dev/cdrom"
state: mounted
fstype: "iso9660"
- yum_repository:
name: "mydvd1"
description: "This is dvd1 for package"
baseurl: "/dvd/AppStream"
gpgcheck: no
- yum_repository:
name: "mydvd2"
description: "This is dvd2 for package"
baseurl: "/dvd/BaseOS"
gpgcheck: no
- name: "install web server"
package:
name: "httpd"
state: present
- name: "install php"
package:
name: "php"
state: present
- copy:
dest: "/var/www/html/index.php"
src: "index.php"
- replace:
path: "/etc/httpd/conf/httpd.conf"
regexp: "AllowOverride None"
replace: "AllowOverride AuthConfig"
- copy:
src: ".htaccess"
dest: "/var/www/html/.htaccess"
- package:
name: "python36"
- pip:
name: "passlib"
- htpasswd:
path: "/etc/www.passwd"
name: "dhiru"
password: "qwerty"
- service:
name: "httpd"
state: restarted
enabled: yes
- firewalld:
port: "80/tcp"
permanent: yes
state: enabled
immediate: yes
- hosts: mylbtasks:
- name: "install load balancer"
package:
name: "haproxy"
- template:
src: "haproxy.cfg.j2"
dest: "/etc/haproxy/haproxy.cfg"
- service:
name: "haproxy"
state: restarted
- firewalld:
port: "5000/tcp"
permanent: yes
state: enabled
immediate: yes

use below github link for get full code

https://github.com/firsttalk26/task12

For configure load balancer and update backend server in /etc/haproxy/haproxy.cfg file use jinja technique as

After creating playbook run below cmd

ansible-playbook lb_web_config.yml

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.

--

--

--

enthusiastic for new technologies

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Scala cheat sheet for Kotlin developers

Thought Experiment: Patching up B-Trees for performance

Become a PRO on How to Use SAGE 50 With This Comprehensive Video Training.

{UPDATE} Kids bubble learning games Hack Free Resources Generator

Remove Duplicates From Sorted Array (Leetcode Problem #26)

Quarter 3: COMPLETE

Why Bother with Automated Testing?

Raise the bar on - Network Performance

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhiraj Kumar

Dhiraj Kumar

enthusiastic for new technologies

More from Medium

Fixing some problems starting Minikube with VirtualBox on Mac

Docker: how to work with Grafana and influxdb

WinRM — Remote Management of Windows

Deploying Jenkins CI/CD to Docker

Jenkins running after docker compose up