Configure HA (high availability) in Centos 6 Using Heartbeat

Linux-HA
Assalamualaikum,

This article will explain how to configuration failover/failback using Heartbeat (http://linux-ha.org/wiki/Heartbeat) in Centos 6.

Below are my server setup. Both systems using CentOS 6.7 64bit.

# Server 1
Hostname   : node01
Domain     : None (localhost)
IP Address : 192.168.88.10

# Server 2
Hostname   : node02
Domain     : None (localhost)
IP Address : 192.168.88.11

# Alias IP for online failover
IP Address : 192.168.88.12

# Configure Network

First, we must configure network on CentOS. Assuming name of your network interface is eth0. Do the following configuration to all nodes (adjust on node02).

#vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
HWADDR=08:00:27:02:C0:1F
TYPE=Ethernet
UUID=cb89f421-fff6-497f-9dcc-008ec7e94621
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.88.10
GATEWAY=192.168.88.1
NETMASK=255.255.255.0

Then, restart network service and setup for automatic boot both nodes (node01 and node02)
#service network restart
#chkconfig network on

# Disable Selinux & Firewall

Open file /etc/sysconfig/selinux and change SELINUX=enforcing become SELINUX=disabled. Also disable some service such as iptables and ip6tables. Do on both nodes.
#setenforce 0
#service iptables stop
#service ip6tables stop
#chkconfig iptables off
#chkconfig ip6tables off

# Configure hostname

Open file /etc/hosts and configure (both nodes) as follows

#node01
127.0.0.1       localhost
192.168.88.10   node01
192.168.88.11   node02

#node02
127.0.0.1       localhost
192.168.88.10   node01
192.168.88.11   node02

Do the following command as root and open file /etc/sysconfig/network to change hostname

On node01
#hostname node01
#vi /etc/sysconfig/network

Change HOSTNAME so that like below :

NETWORKING=yes
HOSTNAME=node01
GATEWAY=192.168.88.1

On node02
#hostname node02
#vi /etc/sysconfig/network

Change HOSTNAME so that like below :

NETWORKING=yes
HOSTNAME=node02
GATEWAY=192.168.88.1

# Update repos and install packages Heartbeat.

Do the following command on all nodes
#yum update
#yum install epel-release
#yum -y install heartbeat

If you cannot get epel repo, please use this repo and install : http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

# Configure Heartbeat

Create a file /etc/ha.d/ha.cf
#vi /etc/ha.d/ha.cf

fill with the following line

#Configured by Hanief
keepalive 2
warntime 5
deadtime 15
initdead 90
udpport 694
auto_failback on
ucast eth0 192.168.88.11
logfile /var/log/ha-log
node node01 node02

Note: eth0 is interface on your system. If your system using eth1 for interface name, please change eth0 to the eth1. 192.168.88.11 is IP Address of node02.

Create a file /etc/ha.d/authkeys
#vi /etc/ha.d/authkeys
Fill with the following line

#Configured by Hanief
auth 2
2 crc

Change permission authkeys
#chmod 0600 /etc/ha.d/authkeys

Create a file /etc/ha.d/haresources
#vi /etc/ha.d/haresources

fill with the following line

#Configured by Hanief
node01 IPaddr::192.168.88.12/24/eth0:0

Note: node01 will become as a master server. 192.168.88.12 is an alias IP for testing online/failover

# Copy those files from node01 to node02

We will copy all 3 files into node02 using SCP
#cd /etc/ha.d/
#scp authkeys ha.cf haresources root@192.168.88.11:/etc/ha.d/

Change ha.cf file on node02 (run the following command on node02
#vi /etc/ha.d/ha.cf

change line ucast eth0 192.168.88.11 so that become

ucast eth0 192.168.88.10

Note: 192.168.88.10 is IP Address of node01

Start Heartbeat & configure automatic startup at boot. Do this to both nodes.
#service heartbeat start
#chkconfig heartbeat on

## TEST OUR HA ##

After your start service heartbeat on all nodes, you will see an alias IP on node01. Please check with command ifconfig. For testing failover, please stop service heartbeat on node01 (service heartbeat stop). Please check your IP on node02 with command ifconfig. You will see an alias IP on node02 (an alias IP that has been taken by node02). For testing failback, please start again service heartbeat on node01 (service heartbeat start). An alias IP will automatically taken by node01.

# Test HA with Apache Web Server

Please install Apache on all nodes
#yum install httpd

Create an index.html on DocumentRoot node01
#vi /var/www/html/index.html

Fill with the following example

This is NODE01

Save and restart service Apache
#service httpd restart

Please try to access node01 via browser. You will see a text This is NODE01

Create an index.html on DocumentRoot Node02
#vi /var/www/html/index.html

Fill with the following example

This is NODE02

Save and restart service Apache
#service httpd restart

Please try to access node02 via browser. You will see a text This is NODE02

## Integrate Apache with Heartbeat ##

Please change file /etc/ha.d/haresources on all nodes
#vi /etc/ha.d/haresources

node01 IPaddr::192.168.88.12/24/eth0:0 httpd

Stop service Apache and configure automatic off at boot both nodes (Service Apache will be handled by Heartbeat)
#service httpd stop
#chkconfig httpd off

Please try to access an alias IP from browser. You will see a text This is NODE01. Please try to stop Heartbeat service on node01 and refresh browser. You will see a text This is NODE02 (all services handled by Heartbeat on node01 will be taken by node02). For failback, please start again Heartbeat service on node01 (all services handled by Heartbeat on node02 will be taken again by node01)

You could also experiment with other services for online failover such as Samba, MySQL, MariaDB etc. The Heartbeat application only configure failover/failback, not data synchronize.

Good luck and hopefully it’s useful.

Thanks,

Wassalam..

Advertisements
This entry was posted in Linux and tagged , , , , . Bookmark the permalink.