Configuring A High Availability Cluster (Heartbeat) On CentOS

Do you like HowtoForge? Please consider to support us by becoming a subscriber.
Submitted by babarsaleem (Contact Author) (Forums) on Tue, 2007-10-30 11:30. :: CentOS

Configuring A High Availability Cluster (Heartbeat) On CentOS

This guide shows how you can set up a two node, high-availability HTTP cluster with heartbeat on CentOS. Both nodes use the Apache web server to serve the same content.

 

Pre-Configuration Requirements

  1. Assign hostname node01 to primary node with IP address 172.16.4.80 to eth0.
  2. Assign hostname node02 to slave node with IP address 172.16.4.81.

Note: on node01

uname -n

must return node01.

On node02

uname -n

must return node02.

172.16.4.82 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 CentOS 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

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 node01
node node02

Note: node01 and node02 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:

node01 172.16.4.82 httpd

7. Copy the /etc/ha.d/ directory from node01 to node02:

scp -r /etc/ha.d/ root@node02:/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 172.16.4.82:80

9. Copy the /etc/httpd/conf/httpd.conf file to node02:

scp /etc/httpd/conf/httpd.conf root@node02:/etc/httpd/conf/

10. Create the file index.html on both nodes (node01 & node02):

On node01:

echo "node01 apache test server" > /var/www/html/index.html

On node02:

echo "node02 apache test server" > /var/www/html/index.html

11. Now start heartbeat on the primary node01 and slave node02:

/etc/init.d/heartbeat start

12. Open web-browser and type in the URL:

http://172.16.4.82

It will show node01 apache test server.

13. Now stop the hearbeat daemon on node01:

/etc/init.d/heartbeat stop

In your browser type in the URL http://172.16.4.82 and press enter.

It will show node02 apache test server.

14. We don't need to create a virtual network interface and assign an IP address (172.16.4.82) to it. Heartbeat will do this for you, and start the service (httpd) itself. So don't worry about this.

Don't use the IP addresses 172.16.4.80 and 172.16.4.81 for services. These addresses are used by heartbeat for communication between node01 and node02. When any of them will be used for services/resources, it will disturb hearbeat and will not work. Be carefull!!!


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by rootlurker (not registered) on Tue, 2009-06-02 09:20.

Good job! Great howto's.. it's works very well.

 Many thanks...

Submitted by Carlos (not registered) on Tue, 2009-01-20 19:48.

Thanks for the tutorial, it worked really well.

Good Job.

Submitted by Jesser (not registered) on Wed, 2009-01-07 20:09.

Excelent How-to! Works fine for me!

CentOS 5.2 x86 default install with heartbeat-2.1.3-3.el5.

Thanks!

 

Submitted by Webmaster (not registered) on Fri, 2008-12-19 06:22.

Hi There,

 Everything is working but only starting HTTPd Service. I am using OpenVZ to simulate these HA. But on each node, it doesn't have eth0 interface. only venet0:0

 Any ideas?

[root@node01 ~]# netstat -untap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      28089/sendmail: acc
tcp        0      0 :::22                       :::*                        LISTEN      27998/sshd          
tcp        0      0 ::ffff:192.168.150.80:22    ::ffff:192.168.150.1:55656  ESTABLISHED 1673/0              

[root@node01 ~]# service httpd start
Starting httpd: (99)Cannot assign requested address: make_sock: could not bind to address 192.168.150.82:80
no listening sockets available, shutting down
Unable to open logs
                                                           [FAILED]
[root@node01 ~]#

Submitted by DrLove73 (not registered) on Thu, 2009-01-01 17:53.

Go to /etc/ha.d/ha.cf and use/change

"bcast eth0 eth1" to

"bcast venet0 venet1" etc.

Do not use venet0:0 or similar since heartbeat is using interfaces not IP addresses.

Submitted by lakhera2009 (registered user) on Wed, 2009-06-10 02:39.

I am facing the same issue.I try to change

bcast venet0 

Bur again the same error 

Heartbeat is running fine but it was not able to bring up the resource when i manually try to bring up the resource

 

 service httpd start
Starting httpd: (99)Cannot assign requested address: make_sock: could not bind to address 192.168.1.113:80
no listening sockets available, shutting down
Unable to open logs
                                                           [FAILED]

Any help is highly appreciated

Submitted by Anonymous (not registered) on Fri, 2008-12-12 14:59.
Don't follow this manual, its confusing and sucks.
Submitted by babarsaleem (registered user) on Tue, 2008-07-22 12:33.
1st accept my appoligies for replying  late. and then let me thank you for appreciating this work. Both statements have same meanings to hearbeat, perhaps i don't know why error generated.
Submitted by limbo (registered user) on Wed, 2008-04-30 23:22.

Firstly, this was a great tutorial, thanks. I had trouble starting the heartbeat service using this node directive syntax in the ha.cf file

node node01
node node02

this however worked for me

node node01 node02

I am using centos 5.1 and heartbeat v2.1.3 (this might have changed since v2.1.2??) and more info on the node directive is here: http://linux-ha.org/ha.cf/NodeDirective

Submitted by raducu (not registered) on Fri, 2009-01-09 13:27.
This article is really great. I followed the instruction and everything worked smoothly on centos 5.2/ Thank you very much.
Submitted by Adam (not registered) on Thu, 2009-01-22 17:53.

the haresources file has been replaced with a XML-based cluster-wide configuration file in heartbeat v2.

 Take a look here how to properly setup heartbeat.

http://www.linux-ha.org/v2/Examples/Simple

Submitted by Krishna (not registered) on Sat, 2009-05-02 13:37.

Dear All,

I have done exactly same entries in my ha.cf file, but when I run uname -n command it does not show me both of the nodes ? Any idea how to correct it. Please help ?