Installing & Configuring Linux Load Balancer Cluster (Direct Routing Method)

In Fedora, CentOS, and Rehat Enterprise Linux, IP Load Balancing solution is provided by using a package called ‘Piranha’.

Piranha offers the facility for load balancing inward IP network traffics (requests) and distribution of this IP traffic among a farm of server machines. The technique that is used to load balance IP network traffic is based on Linux Virtual Server tools.

This High Availability is purely software based provided by Piranha. Piranha also facilitates system administrator with a cool Graphical User Interface tool for management.

The Piranha monitoring tool is responsible for the following functions:
  • Heartbeating between active and backup load balancers.
  • Checking availability of the services on each of real servers.
Components of Piranha Cluster Software:
  • IPVS kernel, LVS (manage the IPVS routing table via the ipvsadm tool)
  • Nanny (monitor servers & services on real servers in a cluster)
  • Pulse (control the other daemons and handle failovers between IPVS routing boxes).
We will configure our computers or nodes as following:
Our load balancing will be done using 2 Linux Virtual Server Nodes or routing boxes.
We will install two or more Web servers for load balancing.

First of all stop all the services that we don’t need to run on the nodes.
[root@websrv1 ~]# service bluetooth stop && chkconfig –level 235 bluetooth off
[root@websrv1 ~]# service sendmail stop && chkconfig –level 235 sendmail off


We will modify our hosts configuration file at /etc/hosts on each of the nodes in our setup 

[root@websrv1 ~]# vim /etc/hosts
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

##### Web Servers IPs #####
192.168.1.100             websrv1.orange.com  websrv1
192.168.1.101             websrv2.orange.com  websrv2

##### Load Balancing Nodes IPs #####
192.168.1.1                 lbnode1.orange.com  lbnode1
192.168.1.2                 lbnode2.orange.com  lbnode2
##########  Virtual IP/Service IP of Webserver ##########
192.168.1.150             www.orange.com  www


Copy the /etc/hosts file to all the servers (This step is not required if you have DNS)
[root@websrv1 ~]# scp /etc/hosts websrv2:/etc
[root@websrv1 ~]# scp /etc/hosts lbnode1:/etc
[root@websrv1 ~]# scp /etc/hosts lbnode2:/etc


After copying to host file to all the nodes, we need to generate SSH keys.
[root@websrv1 ~]# ssh-keygen –t rsa
[root@websrv1 ~]# ssh-keygen –t dsa
[root@websrv1 ~]# cd /root/.ssh/
[root@websrv1 .ssh]# cat *.pub > authorized_keys


Now copy ssh keys to all other nodes for password less entry which is required by pulse daemon.
[root@websrv1 .ssh]# scp -r /root/.ssh/ websrv2:/root/
[root@websrv1 .ssh]# scp -r /root/.ssh/ lbnode1:/root/
[root@websrv1 .ssh]# scp -r /root/.ssh/ lbnode2:/root/


We can build up a global finger print list as following:
[root@websrv1 .ssh]# ssh-keyscan -t rsa websrv1 websrv2 lbnode1 lbnode2
[root@websrv1 .ssh]# ssh-keyscan -t dsa websrv1 websrv2 lbnode1 lbnode2


Now we will configure NTP service on all the nodes. We will make the LBNODE1 as our NTP Server.
[root@lbnode1 ~]# rpm -qa | grep ntp
ntp-4.3.3p1-9.el5.centos
chkfontpath-1.20.1-1.1


[root@lbnode01 ]# vim /etc/ntp.conf
###Configuration for NTP server###
restrict 127.0.0.1
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10


[root@lbnode01 ~]# service ntpd start
[root@lbnode01 ~]# chkconfig ntpd on

Now we will configure client side configuration in WEBSRV1.
[root@websrv1 ~]# vim /etc/ntp.conf
#restrict 127.0.0.1
#restrict -6 ::1
server 192.168.1.1
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org