Monday, May 14, 2007

Linux High Availablity CLUSTER

Hardware configuration that I used for making a cluster:

clusternode1: Intel P4 2.66 GHz., 256 MB RAM, Two ethernet adapters.
clusternode2: Intel P4 2.4 GHz., 512 MB RAM, Two ethernet adapters.

I assigned clusternode1 which I will be calling CN1's eth0 with an IP 10.31.15.221 and clusternode2 which I will be calling CN2's eth0 with 10.31.15.222. I have kept 10.31.15.223 reserved for later use as we will be using this IP as our cluster IP, which of course will be a virtual IP :)

Now I assign eth1 interface for the 2 CNs i.e. CN1's eth1: 192.168.0.1 and CN2's eth1: 192.168.0.2.

The eth1 interface will be used for heartheat check and will be having its seperate network which will not be talking to the LAN in any way, where as the eth0 will be connected to the LAN.

Installation:

Prerequisites:

The following packages are required before we can start with the installation for the heartbeat application:
(Note: you will require to check the versions compatible with you current operating system and install as per your operating system recommendations, the versions mentioned below are the ones that were compatible with the OS I was using and they need not be the same)
  • perl-Authen-SASL-2.08
  • perl-Convert-ASN1-0.18
  • perl-Crypt-SSLeay-0.51
  • perl-Digest-HMAC-1.01
  • perl-Digest-SHA1-2.01
  • perl-IO-Socket-SSL-0.96
  • perl-ldap-0.3202
  • perl-Mail-IMAPClient-2.2.9
  • perl-Net-DNS-0.31-3
  • perl-Net-SSLeay-1.22-2
  • perl-Parse-RecDescent-1.94
  • perl-XML-NamespaceSupport-1.08
  • perl-XML-SAX-0.12

We will now require to install the following packages:
  • heartbeat
  • heartbeat-ldirectord
  • heartbeat-pils
  • heartbeat-stonith
For Fedora:
# yum install heartbeat
#
yum install heartbeat pils stonith ldirectord

For Debian/Ubuntu:
# apt-get install heartbeat pils stonith ldirectord

For RHEL-compatible:
RPMs are available for download at:
i386: http://mirror.centos.org/centos/4/extras/i386/RPMS/
x86_64: http://mirror.centos.org/centos/4/extras/x86_64/RPMS/

For Gentoo:
#
emerge heartbeat


Configuration of Heartbeat and Apache:

Post installation, edit /etc/ha.d/authkeys and add the following two lines:

auth 1
1 crc

Also, edit the /etc/ha.d/ha.cf to include the following lines:

debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
deadtime 5 # how long before the host is declared down
udpport 694 # UDP port used for broadcasting
bcast eth1 # interfaces to broadcast heartbeats
auto_failback on
node CN1 # Defining which machine is a part of cluster
node CN2 # Defining which machine is a part of cluster

Now edit the /etc/ha.d/ha.cf/haresources which will look like:

mycluster 10.31.15.223 httpd # here, mycluster is the clustername that will appear when I issue uname -n.

After which, start/restart httpd:

# /etc/ha.d/httpd start
OR
# /etc/init.d/httpd

When done with the configuration of CN1, you can copy the files to CN2. In /etc/ha.d/rc.d you will find the script called ip-request which will do the job of assigning the ip address etc.
now start /etc/rc.d/init.d/heartbeat on both machines.

Install a different index page on the machines to be served by the http server, using below commands.

echo hello world from CN1 > index.html

echo hello world from CN2 > index.html

Note: Ensure that on both nodes, httpd does not start when the OS boots

Testing the failover cluster:

Ensure that you are able to browse the page http://10.31.15.223 and it shows “index.html” of CN1.

Now, shut down or remove both the network cables of clusternode1 and try to browse the page http://10.31.15.223 and it should show the “index.html” of CN2. You can also verify the IP 10.31.15.223 assigned to CN2 by using ifconfig command or also by reading the log file /var/log/ha-debug.

To keep a synchronization you can setup a cronjob to copy the data from CN1 of /var/www/html to CN2 /var/www/html. I would recommend using rsync for this ;))