Sunday, September 28, 2014

HA-HeartBeat on Raspberry PI

High Availability HeartBeat is a clustering daemon. It allows to setup virtual IP addresses on network interfaces in order to provide redundancy in service availability. (It can also be used to automatically start/stop services)
In this post, we take a look at the basic HA usage, with two nodes.
In the above figure we have two nodes (raspberry PI with archlinux). Each node runs one HeartBeat instance and communicates (send keepalive) with the other node.

Lets take a look on the installation process.
To successfully install HeartBeat, we need to install two packages (either from AUR repository, or build them from source):
  • ha-glue
  • ha-heartbeat
To install ha-glue we need to add group and user first:
  • groupadd -r -g 666 haclient
  • useradd -r -g haclient -u 666 -d /var/lib/heartbeat/cores/hacluster -s /sbin/nologin -c "cluster user" hacluster
For ha-heartbeat to compile at current version (ha-heartbeat 3.0.5-2) we had to comment out following lines in ucast.c file:
--- lib/plugins/HBcomm/ucast.c.old  2014-09-28 18:28:40.187832720 +0200
+++ lib/plugins/HBcomm/ucast.c    2014-09-28 15:23:31.870568289 +0200
@@ -464,9 +464,9 @@
 #if defined(SO_BINDTODEVICE)
        struct ifreq i;
 #endif
-#if defined(SO_REUSEPORT)
-       int i = 1;
-#endif
+//#if defined(SO_REUSEPORT)
+//     int i = 1;
+//#endif
 
        UCASTASSERT(mp);
        ei = (struct ip_private*)mp->pd;

Then we have to install some resource agent to manage HeartBeats resources. I've installed ha-resourceagent but not on the raspberry, because I was unable to compile it. So from another machine (x86_64) where the compilation and installation was successful I've copied /etc/ha.d/shellfuncs
and /usr/lib/ocf to both raspberry PI.

HEARTBEAT Configuration:
Basically all we need are 3 configuration files placed in /etc/ha.d/ folder.
Sample configuration files can be found in documentation:  /usr/share/doc/heartbeat/

authkeys:
auth 2
2 sha1 HI!heartbeat
This file handles authorization of keepalive packets.

ha.cf:
logfacility     local0
keepalive 2
udpport 694
ucast eth0 172.16.0.3 # ip address where will be keepalive sent
auto_failback on
node    RPi-P  # list of all nodes
node    RPi-T
You may need to enable UDP port 694 on iptables.

haresources:
RPi-T   IPaddr2::172.16.0.20/24/eth0 # RPi-T is from uname -n, this is the default node for this resource
RPi-T   IPaddr2::172.16.0.21/24/eth0
RPi-P   IPaddr2::172.16.0.22/24/eth0
RPi-P   IPaddr2::172.16.0.23/24/eth0

NOTE: haresources must be the same on all nodes.

After startup of HeartBeat on both nodes, we will have following state on eth0 interfaces:
RPi-T ~ # ip addr
4: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:33:39:e0 brd ff:ff:ff:ff:ff:ff
    inet 172.16.0.3/24 brd 172.16.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 172.16.0.20/24 brd 172.16.0.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet 172.16.0.21/24 brd 172.16.0.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
RPi-P ~ # ip addr
4: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:f7:a4:96 brd ff:ff:ff:ff:ff:ff
    inet 172.16.0.5/24 brd 172.16.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 172.16.0.22/24 brd 172.16.0.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet 172.16.0.23/24 brd 172.16.0.255 scope global secondary eth0
       valid_lft forever preferred_lft forever

No comments:

Post a Comment