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 10.10.10.1 to eth0.
- Assign hostname NODE2 to Slave node with IP Address 10.10.10.2 to eth0.
On Node1
uname -n
must return NODE1.
On Node2
uname -n
must return NODE2.
10.10.10.3 is the virtual IP address that will be used for Apache webserver. (i.e. Apache would listen to 10.10.10.3 IP Address.)
Configuration
- Download and install heartbeat package.
yum install heartbeat
or download packages :
heartbeat-2.08
heartbeat-pils-2.08
heartbeat-stonith-2.08
- Now we need to configure heartbeat on our two node cluster.We will deal with three files and they are :
authkeys
ha.cf
haresources
- 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 ha.cf. Add following lines in the ha.cf file :
vi /etc/ha.d/ha.cf
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 10.10.10.3 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
Listen 10.10.10.3:80
- 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
HTTP fron NODE1
on NODE2 :
vi /var/www/html/index.html
HTTP fron NODE2
- Now start heartbeat on primary(NODE1) and slave(NODE2) Nodes./etc/init.d/heartbeat start
- OPen web browser and type URL
http://10.10.10.3
It will show NODE1 web page
- Now stop heartbeat deamon on NODE1
/etc/init.d/heartbeat stop
OPen web browser and type URL
http://10.10.10.3 and press enter.
It will show NODE2 web page.
- We don’t need to create a virtual network interface and assign an IP address 10.10.10.3 to it. Heartbeat will do this for you and start httpd service itself. So don’t worry about this.
Don’t use IP address 10.10.10.1 and 10.10.10.2 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 .