Chapter 1
High Availability Proxy Servers
Definition
HAProxy stands for High Availability proxy. HAProxy or High Availability Proxy is TCP and
HTTP load balancer and proxy server software. It is a Free and open source application written
in C programming Language. HAProxy application is used as TCP/HTTP Load Balancer and for
proxy Solutions. The most common use of the HAProxy application is to distribute the workload
across multiple servers e.g., web server, database server, etc thus improving the overall
performance and reliability of server environment.
Load Balancer:
HA Proxy: can do health checks, uses load balancing algorithms, sticky session,
Nginx: Brainless (just forward request)
Architecture
HAProxy Environment Setup
HAProxy Server:
IP Address: 192.168.56.201
Hostname: HAserver
HAProxy Client:
IP Address: 192.168.56.202 , 192.168.56.206
Hostname: HAclient1, HAclient2
Installing Apache on Client Machines
#yum install httpd
verify anyone of the server whether Apache is running by accessing it via IP address in browser.
http://192.168.56.212
Installing HAProxy Server
To install HAProxy on RHEL/CentOS/Fedora run the following command.
#yum install haproxy
Enabling Logging feature and Configure HAProxy
Enable logging feature in HAProxy for future debugging. Open the main HAProxy configuration
file ‘/etc/haproxy/haproxy.cfg‘
# mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.org
#vi /etc/haproxy/haproxy.cfg
# create new
global
# for logging section
log 127.0.0.1 local2 info
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
# max per-process number of connections
maxconn 256
# process' user and group
user haproxy
group haproxy
# makes the process fork into background
daemon
defaults
# running mode
mode http #usee TCP for DB loadbalancing
# use global settings
log global
# get HTTP request log
option httplog
# timeout if backends do not reply
timeout connect 10s
# timeout on client side
timeout client 30s
# timeout on server side
timeout server 30s
# define frontend ( set any name for "http-in" section )
frontend http-in
# listen 80
bind *:80
# set default backend
default_backend backend_servers
# send X-Forwarded-For header
option forwardfor
# define backend
backend backend_servers
# balance with roundrobin
balance roundrobin
# define backend servers
server client2 192.168.56.202:80 check
server client4 192.168.56.206:80 check
Configure HAProxy Logs
Configure Rsyslog to get logs for HAProxy
#vi /etc/rsyslog.conf
# line 15,16: uncomment, lne 17: add
$ModLoad imudp
$UDPServerRun 514
$AllowedSender UDP, 127.0.0.1
# line 54: change like follows
*.info;mail.none;authpriv.none;cron.none
,local2.none
/var/log/messages
local2.* /var/log/haproxy.log
Next, we need to create a separate file ‘haproxy.conf‘ under ‘/etc/rsyslog.d/‘ directory to
configure separate log files.
# vi /etc/rsyslog.d/haproxy.conf
Append following line to the newly create file.
local2.* /var/log/haproxy.log
restart the rsyslog service to update the new changes.
# systemctl restart rsyslog
#systemctl restart haproxy
Chapter 2
Configure Clients (HA Proxy)
Logging X-Forwarded-For header
Conf File: /etc/httpd/conf/httpd.conf
ServerRoot “/etc/httpd” – configuration files are stored here. Can be changed.
Listen 80 - Port at which httpd can listen
User apache
Group apache
DocumentRoot “/var/www/html” – path to store code base or website contents
Change httpd settings on Backends to logging X-Forwarded-For header
#
vi /etc/httpd/conf/httpd.conf
# line 196: change like follows
LogFormat "
\"%{X-Forwarded-For}i\"
%l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
Modify /etc/hosts entry
Make an entry for HAProxy server in /etc/hosts file of all the clients
# echo “192.168.56.201 client1” >> /etc/hosts
Modify index.html on each client
Go to the web directory and change the index file so that we can see which of the two servers
delivered the html file
Path of httpd index file:
/usr/share/httpd/noindex/index.html
On Client 2:
# echo "<h1>httpd.client2.loadbalance.me</h1>" > /usr/share/httpd/noindex/index.html
On Client 4:
# echo "<h1>httpd.client4.loadbalance.me</h1>" > /usr/share/httpd/noindex/index.html
On All Clients
#systemctl restart httpd
Issues
Note: Make sure all servers are listening on port 80 and firewalld is not stopping connection
from other servers.
#yum install net-tools
#netstat -tulp
Chapter
NFS – Network File System
Allows user to share file and directories
Configure the NFS Server
Install packages
#yum install nfs-utils nfs-utils-lib
Create below directory to share
#mkdir /var/nfsshare
Change the permissions of the folder as follows:
#chmod -R 777 /var/nfsshare/
Start and Enable below services
#systemctl enable rpcbind
#systemctl enable nfs-server
#systemctl enable nfs-lock
#systemctl enable nfs-idmap
#systemctl start rpcbind
#systemctl start nfs-server
#systemctl start nfs-lock
#systemctl start nfs-idmap
#vi /etc/exports
/var/nfsshare 192.168.56.102(rw,sync,no_root_squash,no_all_squash)
/home 192.168.56.102(rw,sync,no_root_squash,no_all_squash)
Restart the NFS service:
#systemctl restart nfs-server
# showmount -e
Export list for testserver:
/home 192.168.56.102
/var/nfsshare 192.168.56.102
Configure the NFS Client
Install below packages
#yum install nfs-utils
Create below mount points
#mkdir -p /mnt/nfs/home
#mkdir -p /mnt/nfs/var/nfsshare
Start and Enable below services:
#systemctl enable rpcbind
#systemctl enable nfs-server
#systemctl enable nfs-lock
#systemctl enable nfs-idmap
#systemctl start rpcbind
#systemctl start nfs-server
#systemctl start nfs-lock
#systemctl start nfs-idmap
Mount the share file systems
#mount -t nfs 192.168.56.101:/home /mnt/nfs/home/
#mount -t nfs 192.168.56.101:/var/nfsshare /mnt/nfs/var/nfsshare/
For Permanent share add below entries:
#vi /etc/fstab
192.168.56.101:/home /mnt/nfs/home nfs defaults 0 0
192.168.56.102:/var/nfsshare /mnt/nfs/var/nfsshare nfs defaults 0 0