Linux HA Heartbeat

From Debuntu

Jump to: navigation, search

Contents

Environment

This article is going to set up a Linux High-Availability cluster using Linux HA Heartbeat between 2 Debian Lenny host.

The configuration will be made in Heartbeatv1 mode.

The host are defined as follow:

Host name: lvs1
Host IP: 172.16.137.130/24 on eth0
Host name: lvs2
Host IP: 172.16.137.131/24 on eth0
Important.png
Failover IP
The cluster IP MUST BE in a network range which is already registered on the host

Installation

Installation is pretty straightforward and is done with APT using the following command line:

# apt-get install heartbeat

Configuration

Enabling non-local IP binding

In order to be able to bind on a IP which is not yet define on the system, we need to enable non local binding at the kernel level.

Temporarily

For testing purpose, you can use the following command:

# echo 1 > /proc/sys/net/ipv4/ip_nonlocal_bind

Permanently

To enable it permanently, you need to add to /etc/sysctl.conf :

net.ipv4.ip_nonlocal_bind = 1

and then run:

# sysctl -p

Linux HA files

There is 3 files that we will need to edit:

this file will contain the shared secret for nodes authentication within the cluster
the global cluster configuration file.
Contains info on what resources are shared and who is the default master

Authkey

/etc/ha.d/authkeys will look like:

auth 1
1 md5 heartbeatmd5

Change heartbeatmd5 by any shared secret you would like.

This file will be identical on both hosts.

Important.png
File rights
Make sure that /etc/ha.d/authkeys is only accessible by root:
# chmod 600 /etc/ha.d/authkeys

ha.cf

LVS1

On lvs1 /etc/ha.d/ha.cf will look like:

#       keepalive: how many seconds between heartbeats
keepalive 2
#       deadtime: seconds-to-declare-host-dead
deadtime 10
#       warntime: set late heartbeat warning time
warntime 5
#       initdead: set initial deadtime detection interval
initdead 120
#       udpport: specifies port for UDP communication
udpport 694
#       ucast: configures unicast Heartbeat communication
ucast eth0 172.16.137.131
logfacility  local0
#       auto_failback: set failback policy
auto_failback off
#       node: tells what machines are in the cluster
node lvs1 lvs2

LVS2

On lvs2 /etc/ha.d/ha.cf will look like:

#       keepalive: how many seconds between heartbeats
keepalive 2
#       deadtime: seconds-to-declare-host-dead
deadtime 10
#       warntime: set late heartbeat warning time
warntime 5
#       initdead: set initial deadtime detection interval
initdead 120
#       udpport: specifies port for UDP communication
udpport 694
#       ucast: configures unicast Heartbeat communication
ucast eth0 172.16.137.130
logfacility  local0
#       auto_failback: set failback policy
auto_failback off
#       node: tells what machines are in the cluster
node lvs1 lvs2
Note.png
Note
Here I have used a unicast heartbeat as there is only 2 hosts in this cluster. Multicast or broadcast can also be used, see http://www.linux-ha.org/ha.cf/

haresources

lvs1 172.16.137.135/24/eth0

Here we define that the IP 172.16.137.135/24 is will be running on eth0 and with preference for lvs1.

Idea.png
Handling more than one resource
You could associate more than one resource with a content like:
lvs1 172.16.137.135/24/eth0 192.168.1.50/24
Assuming that the network ranges are already defined in host network.

Running the service

Starting

The service can be started using:

# /etc/init.d/heartbeat start

Runtime status

You can get the status of your cluster by using the cl_status command line utility.

Here is an excerpt:

chantra@lvs1:~$ cl_status hbstatus
Heartbeat is running on this machine.
chantra@lvs1:~$ cl_status listnodes
lvs2
lvs1
chantra@lvs1:~$ cl_status nodestatus lvs1
active
chantra@lvs1:~$ cl_status nodestatus lvs2
active

References

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox
Google AdSense