HTTP Cluster with heartbeat


Setup a two node high availability HTTP cluster with heartbeat. Both nodes use the Apache Web Server to serve the same content.

Pre-Configuration Requirement

  • Assign hostname NODE1 to Primary node with IP Address to eth0.
  • Assign hostname NODE2 to Slave node with IP Address to eth0.

On Node1

uname -n

must return NODE1.

On Node2

uname -n

must return NODE2. is the virtual IP address that will be used for Apache webserver. (i.e. Apache would listen to IP Address.)


  • Download and install heartbeat package.

yum install heartbeat

or download packages :




  • Now we need to configure heartbeat on our two node cluster.We will deal with three files and they are :



  • In case your /etc/ha.d is empty you need to copy the files above said files to /etc/ha.d directory. In my case I would 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/authkeys /etc/ha.d/

cp /usr/share/doc/heartbeat-2.1.2/authkeys /etc/ha.d/

  • First we would deal with authkeys file. We will use authentication method 2 (sha 1). For this we will make changes in the authkeys file.

vi /etc/ha.d/authkeys

and add following lines

auth 2

2 sha1 test-ha

change the permission of th authkeys file :

chmod 600 /etc/ha.d/authkeys

  • Now important file Add following lines in the file :

vi /etc/ha.d/

logfile /var/log/ha-log

logfacility local0

keepalive 2

deadtime 30

initdead 120

bcast eth0

udpport 694

auto_failback on

node NODE1

node NODE2

Note : NODE1 and NODE2 are the output generated by command uname -n on both system

  • Now update haresources file. This file contains information about resources which we want highly enable. In our case we want webserver(apache(httpd)) highly available.

vi /etc/ha.d/haresources

NODE1 httpd

  • Copy /etc/ha.d directory from NODE1 to NODE2

scp -r /etc/ha.d root@NODE2:/etc

  • As we want httpd highly enabled lets start configuring httpd

vi /etc/httpd/conf/httpd.conf


  • Copy /etc/httpd/conf/httpd.conf to NODE2

scp -r /etc/httpd/conf/httpd.conf root@NODE2:/etc/httpd/conf/

  • Create index files on both Nodes (NODE1 and NODE2)

on NODE1 :

vi /var/www/html/index.html


on NODE2 :

vi /var/www/html/index.html


  • Now start heartbeat on primary(NODE1) and slave(NODE2) Nodes./etc/init.d/heartbeat start
  • OPen web browser and type URL

It will show NODE1 web page

  • Now stop heartbeat deamon on NODE1

/etc/init.d/heartbeat stop

OPen web browser and type URL and press enter.

It will show NODE2 web page.

  • We don’t need to create a virtual network interface and assign an IP address to it. Heartbeat will do¬† this for you and start httpd service itself. So don’t worry about this.

Don’t use IP address and for services. These IP address are used by heartbeat for communication between NODE1 and NODE2. When any of them will be used for other services/resources, it will distrub heartbeat and will not work .


This entry was posted in Apache. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *