Professional Documents
Culture Documents
(21-22) TP HTTPLoadBalancer Haproxy
(21-22) TP HTTPLoadBalancer Haproxy
Balancer
Esprit 21-22
1
Goal
Harpy is a free and open-source Linux application used for load balancing network traffic.
This document will guide you through deploying it for both simple web applications and
large, complex web sites.
Don’t forget to make Haproy Server, webserver01 and webserver02 through the same LAN
segment
192.168.162.134
192.168.162.128
192.168.162.135
Pre-requisites
You need 3 machines centos 7:
Haproxy Server @ip 192.168.162.128/24 (if you have httpd daemon you should stop it)
Webserver 1(@ip 192.168.162.134/24)
webserver 2(@ip 192.168.162.135/24)
Also you should have a website in each one of your backends servers.(review TP1)
Everyone works according to their own addresses
2
# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.org
# vi /etc/haproxy/haproxy.cfg
Define the front-end and back-end sections: Add the following configuration to the
file to define the front-end and back-end sections:
frontend esprit1_frontend
bind *:80
mode http
default_backend esprit1_backend
backend esprit1_backend
mode http
balance roundrobin
server backup1 192.168.162.135:80 check
server backup2 192.168.162.134:80 check
You also need to make few changes in configuration file as per your system configuration.
mode <value> # ‘http’ for http site and ‘tcp’ for https site
balance <value> # Type of load balancing like ‘source’, ’roundrobin’ etc.
Step 4 – VERIFYING
1. The most interesting thing is that we have to configure our
firewall in order to be able to access our site from another machine (do this for all 4
machines)
#firewall-cmd --list-all
#firewall-cmd --add-service=http --permanent
#firewall-cmd –reload
2. The two servers that host the site must have the same name of site .I chose
www.esprit1.com. Also, don't forget to change in the file
/etc/httpd/conf/httpd.conf
3
Changing Line 95 ServerName www.esprit1.com:80
Also at the bottom of this file
<VirtualHost 192.168.162.134:80>
ServerAdmin webmaster@esprit1.com
DocumentRoot /var/www/esprit1.com
ServerName www.esprit1.com
ErrorLog logs/www.esprit1.com-error_log
CustomLog logs/www.esprit1.com-access_log common
</VirtualHost>
DO THE SAME THING ON THE OTHER BACKUP SERVER BUT
WITH HIS @
3. It's also very important to modify /etc/hosts of my two backup servers "I changed only the
host file of these two servers" I show you my file /etc/hosts
I added this for the first server
192.168.162.134 www.esprit1.com
Also for the other server
192.168.162.135 www.esprit1.com
Required Test
Make sure all works fine and you can access the website from the ip@ frontend server !!
4
5