Load balancers distributes network traffic across backend servers and thus enables high availability.
This article explains how to perform software-based load balancing using Pound package.
Hostname | Running OS | IP address | HTML index pages |
Poundserver | CentOS 6.2 | 192.168.56.107 | NA |
webserver1 | CentOS 6.5 | 192.168.56.119 | webserver-node-1 |
webserver2 | CentOS 6.5 | 192.168.56.120 | Webserver-node-2 |
Below shown figure is self-explanatory architectural diagram of the pound server and backend webservers.
Below pre-requsites are to be applied on all the hosts and would be skipping as I would leave it as an exercise for the reader.
1. Ensure that the DNS is configured or add the entries in /etc/hosts file.
2. Set the IP address
3. Turn off the firewall
4. SElinux should be disabled.
Installation and configurations of webservers(webserver1 and webserver2).
The default apache web service will be installed on both the backend webservers. Since the installations and configurations of the apache web service is exactly the same for both the nodes, hence will record all steps in webserver1. The same steps are to be performed on webserver2.
Install Apache web service:
[root@webserver1]# yum install httpd
[root@webserver1]#
[root@webserver1]# service httpd start
[root@webserver1]#
[root@webserver1]# chkconfig httpd on
[root@webserver1]#
Let's create an web page index.html at /var/www/html.
Repeat the same above steps for webserver2
[root@webserver1]# cat index.html
<html>
<body>
<font size="6">webserver-node-1 </font>
</body>
</html>
[root@pcmk-1 html]# cat index.html
<html>
<body>
<font size="6">webserver-node-1 </font>
</body>
</html>
[root@webserver1]#
Installation and configurations of Pound server(Poundserver)
Pound package is not part of redhat, hence it has to be downloaded from EPEL.
[root@poundserver]# cd /var/tmp
[root@poundserver tmp]# wget http://ftp.jaist.ac.jp/pub/Linux/Fedora//epel/6/i386/epel-release-6-8.noarch.rpm
[root@poundserver tmp]# rpm -ivh --aid --force epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
[root@poundserver tmp]#
[root@poundserver tmp]#yum install Pound*
[root@poundserver tmp]#
You can view the default configuration file by using command below:
[root@poundserver]#cat /etc/pound.cfg
Make the changes to the Pound configuration file as below:
I would comment the section related to HTTPS as I don't need it now.
[root@poundserver]# cat /etc/pound.cfg
#
# Default pound.cfg
#
# Pound listens on port 80 for HTTP and port 443 for HTTPS
# and distributes requests to 2 backends running on localhost.
# see pound(8) for configuration directives.
# You can enable/disable backends with poundctl(8).
#
User "pound"
Group "pound"
Control "/var/lib/pound/pound.cfg"
ListenHTTP
Address 192.168.56.107
Port 80
End
#ListenHTTPS
# Address 0.0.0.0
# Port 443
# Cert "/etc/pki/tls/certs/pound.pem"
#End
Service
BackEnd
Address 192.168.56.119
Port 80
End
BackEnd
Address 192.168.56.120
Port 80
End
End
[root@poundserver]#
Now, start the Pound service:
[root@poundserver]#service pound start
Starting Pound: starting...
[ OK ]
[root@poundserver]#
Observation:
Open a webbrowser and access URL http://192.168.56.107. It displays webservernode-1
Refresh the webpage, it will flip from webserver1 and webserver2 back and forth.
We have now configured a system where the load on the web server is being balanced between two physical servers.
No comments:
Post a Comment