Configuring High Availability Linux Cluster

This document shows how you can set up a two node, high-availability HTTP cluster with heartbeat on linux. Both nodes use the Apache web server to serve the same content.
Pre-Configuration Requirements:
1. Assign hostname host01 to primary node with IP address 192.168.0.1 to eth0.
2. Assign hostname host02 to secondry node with IP address 192.168.0.2.
Note: on host01
# uname -n
host01
On host02
uname -n
host02
192.160.2.1 is the virtual IP address that will be used for our Apache webserver (i.e., Apache will listen on that address).

Configuration:

1. Download and install the heartbeat package. In our case we are using linux so we will install heartbeat with yum:
yum install heartbeat
or download these packages:
heartbeat-2.08
heartbeat-pils-2.08
heartbeat-stonith-2.08
2. Now we have to configure heartbeat on our two node cluster. We will deal with three files. These are:
authkeys
ha.cf
haresources
3. Now moving to our configuration. But there is one more thing to do, that is to copy these files to the /etc/ha.d directory. In our case we copy these files as given below:

cp /usr/share/doc/heartbeat-2.1.2/authkeys /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.2/ha.cf /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.2/haresources /etc/ha.d/
4. Now let's start configuring heartbeat. First we will deal with the authkeys file, we will use authentication method 2 (sha1). For this we will make changes in the authkeys file as below.
vi /etc/ha.d/authkeys
Then add the following lines:
auth 2
2 sha1 test-ha
Change the permission of the authkeys file:
# chmod 600 /etc/ha.d/authkeys
5. Moving to our second file (ha.cf) which is the most important. So edit the ha.cf file with vi:
vi /etc/ha.d/ha.cf
Configuring Heartbeat High Availability Cluster On linux
Add the following lines in the ha.cf file:
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
initdead 120
bcast eth0
udpport 694
auto_failback on
node host01
node host02
Note: host01 and host02 is the output generated by
# uname -n
6. The final piece of work in our configuration is to edit the haresources file. This file contains the information about resources which we want to highly enable. In our case we want the webserver (httpd) highly available:
# vi /etc/ha.d/haresources
Add the following line:
host01 192.160.2.1 httpd
7. Copy the /etc/ha.d/ directory from host01 to host02:
# scp -r /etc/ha.d/ [email protected]:/etc/
8. As we want httpd highly enabled let's start configuring httpd:
# vi /etc/httpd/conf/httpd.conf
Add this line in httpd.conf:
Listen 192.160.2.1:80
9. Copy the /etc/httpd/conf/httpd.conf file to host02:
# scp /etc/httpd/conf/httpd.conf [email protected]:/etc/httpd/conf/
10. Create the file index.html on both nodes (host01 & host02):
On host01:
echo "host01 apache test server" > /var/www/html/index.html
On host02:
echo "host02 apache test server" > /var/www/html/index.html
11. Now start heartbeat on the primary host01 and secondary host02:
/etc/init.d/heartbeat start
12. Open web-browser and type in the URL:
It will show host01 apache test server.
13. Now stop the heartbeat daemon on host01:
# /etc/init.d/heartbeat stop
In your browser type in the URL http://192.160.2.1 and press enter.
It will show host02 apache test server.
14. We don't need to create a virtual network interface and assign an IP address (192.160.2.1) to it. Heartbeat will create this and start the service (httpd) itself.
Don't use the IP addresses 192.168.0.1 and 192.168.0.2 for services. These addresses are used by heartbeat for communication between host01 and host02. When any of them will be used for services/resources, it will disturb heartbeat and will not work. Be carefull!!!

Share this

Related Posts

Previous
Next Post »

5 comments

Write comments
Anonymous
April 29, 2011 at 10:48 AM delete

hello,

can anybody tell me the HA three node setup ??.... how can i configure it ..

BR
VS

Reply
avatar
April 30, 2011 at 12:51 AM delete

Will Post new article on this soon...! Thanks for your comments..!

Reply
avatar
Anonymous
July 15, 2012 at 8:47 AM delete

Hi Parthiban,

Thanks for sharing the best info which is useful for admin professional.

Keepup the good job.

Regards,
Anil Kumar Pinnaka

Reply
avatar

What do you think about this Article? Add your Opinion..! EmoticonEmoticon