Centos High Availability Cluster with OpenVZ, DRBD and Heartbeat – Part 2

DRBD installation with OpenVZ, plese follow the link below.

Centos High Availability Cluster with OpenVZ, DRBD and Heartbeat – Part 1

1.  Download repository.

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

2. Install HeartBeat

yum install heartbeat

3. Create the Heartbeat configuration file ha.cf and copy it to /etc/ha.d/ha.cf on both nodes.

# vi /etc/ha.d/ha.cf

debugfile
logfile /var/log/ha-log
logfacility local0
node masternode
node slavenode
keepalive 1
deadtime 10
warntime 5
initdead 60
udpport 694
bcast em2
auto_failback on

4. Create the Heartbeat configuration file haresources and copy it to /etc/ha.d/haresources on both nodes

# vi /etc/ha.d/haresources

masternode drbddisk::clusterdb Filesystem::/dev/drbd0::/vz::ext4 openvz

5. Create the Heartbeat configuration file authkeys and copy it to /etc/ha.d/authkeys on both nodes.

#vi /etc/ha.d/authkeys

auth 1
1 crc

6. Change the permission

chmod 600 /etc/ha.d/authkeys

7. Start heartbeat service.

/etc/init.d/heartbeat start

8. Add heartbeat on system boot.

chkconfig –add heartbeat

chkconfig heartbeat on

9.  Openvz Startup script for OpenVZ

# vi /etc/init.d/openvz

######Code Start Here ##########

#!/bin/bash
#
# openvz        Startup script for OpenVZ
#

start() {
/etc/init.d/vz start > /dev/null 2>&1
RETVAL=$?
/root/live-switchover/cluster_unfreeze.sh
return $RETVAL
}
stop() {
/etc/init.d/vz stop > /dev/null 2>&1
RETVAL=$?
return $RETVAL
}
status() {
/etc/init.d/vz status > /dev/null 2>&1
RETVAL=$?
return $RETVAL
}

# See how we were called.
case “$1″ in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo $”Usage: openvz {start|stop|status}”
exit 1
esac

exit $RETVAL

######Code End Here ##########

10. Make openvz script executable.

chmod +x /etc/init.d/openvz

11. Cluster freeze script.

#vi /root/live-switchover/cluster_freeze.sh

######Code Start Here ##########

#!/bin/bash
#Script by Thomas Kappelmueller
#Version 1.0
#LIVESWITCH_PATH=’/vz/cluster/liveswitch’

if [ -f $LIVESWITCH_PATH ]
then
rm -f $LIVESWITCH_PATH
fi

RUNNING_VE=$(vzlist -1)

for I in $RUNNING_VE
do
BOOTLINE=$(cat /etc/sysconfig/vz-scripts/$I.conf | grep -i “^onboot”)
if [ $I != 1 -a “$BOOTLINE” = “ONBOOT=”yes”” ]
then
vzctl chkpnt $I

if [ $? -eq 0 ]
then
vzctl set $I –onboot no –save
echo $I >> $LIVESWITCH_PATH
fi
fi
done

exit 0

######Code End Here ##########

12.  Make cluster_freeze.sh executable.

chmod +x /root/live-switchover/cluster_freeze.sh

13.  Cluster unfreeze script.

#vi /root/live-switchover/cluster_unfreeze.sh

######Code Start Here ##########

#!/bin/bash
#Script by Thomas Kappelmueller
#Version 1.0

LIVESWITCH_PATH=’/vz/cluster/liveswitch’

if [ -f $LIVESWITCH_PATH ]
then
FROZEN_VE=$(cat $LIVESWITCH_PATH)
else
exit 1
fi

for I in $FROZEN_VE
do
vzctl restore $I

if [ $? != 0 ]
then
vzctl start $I
fi

vzctl set $I –onboot yes –save
done

rm -f $LIVESWITCH_PATH

exit 0

######Code End Here ##########

14. Make cluster unfreeze script executable.

chmod +x /root/live-switchover/cluster_unfreeze.sh

15. Live switchover script.

#vi /root/live-switchover/live_switchover.sh

######Code Start Here ##########

#!/bin/bash
#Script by Thomas Kappelmueller
#Version 1.0

ps -eaf | grep ‘vzctl enter’ | grep -v ‘grep’ > /dev/null
if [ $? -eq 0 ]
then
echo ‘vzctl enter is active. please finish before live switchover.’
exit 1
fi
ps -eaf | grep ‘vzctl exec’ | grep -v ‘grep’ > /dev/null
if [ $? -eq 0 ]
then
echo ‘vzctl exec is active. please finish before live switchover.’
exit 1
fi
echo “Freezing VEs…”
/root/live-switchover/cluster_freeze.sh
echo “Starting Switchover…”
/usr/lib64/heartbeat/hb_standby

######Code End Here ##########

16. Make live_switchover.sh executable.

chmod +x /root/live-switchover/live_switchover.sh

17. Start OpenVZ script.

/etc/init.d/openvz start

18. Do the testing. Restart the masternode or your primary server. If the /vz will automatically mounted in the secondary node then it works.

Leave a Reply