Tuesday, July 27, 2010

High Availability Cluster On CentOS (Heartbeat)

Pre-Configuration Requirements
##################################
Assign hostname node01 to primary node with IP address 192.168.10.50
Assign hostname node02 to slave node with IP address 192.168.10.51
Assume 192.168.10.52 is the virtual IP address that will be used for our Apache webserver.


Install Heartbeat 
yum install heartbeat-devel
######################################
Now we have to configure heartbeat on node01 and node02
Main files
1, authkeys
2, ha.cf
3, haresources
Just copy all the files from
cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/
Configure heartbeat
vi /etc/ha.d/authkeys
Then add the following lines
auth 2
2 sha1  test-ha
change the permission
chmo 600 /etc/ha.d/authkeys
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 node01
node node02
:wq!
#######################
vi /etc/ha.d/haresources
Then add the following
node01 192.168.10.52 httpd
:wq!
Copy the /etc/ha.d/ directory from node01 to node02 with scp
scp -r /etc/ha.d/*  node02:/etc/ha.d/
#################################
Now edit httpd.conf
vi /etc/httpd/conf/httpd.conf
add this line
Listen 192.168.10.52:80
:wq!
scp httpd.conf node02:/etc/httpd/conf/
now create some test html file on both slave and master
start heartbeat on both system
/etc/init.d/heartbeat start
and then open browser and type http://192.168.10.52/
will b able to see node01 test page
and stop heartbeat on node01 and  refresh the browser you will be able to see node02 test page
############################################################################