Asterisk Clustering with DRBD/Heartbeat

In this manual, we are using DRBD with Heartbeat on Debian. Feel free to try it on any other linux distro (make sure to do the proper adjustments). Please don’t use the configuration samples here in any production environment, unless you have had it completely tested in your lab.


IP Address Configuration

Primary IP-PBX:

Secondary IP-PBX:

Floating IP Address :
Hostname Configuration:
Primary IP-PBX: master.ippbx
Secondary IP-PBX : slave.ippbx

2) Configuration

2.1) Partition

During the linux setup, do a manual hard disk partitioning. Make sure you create 4 partitions as below: /root: 10 GB (ext3, sda1) swap: 4 GB (swap, sda2) /  : 50 GB (ext3, sda3) /drbd:  size = the remaining (ext3, sda4)

2.2) DRBD Installation and Configuration


DRBD is the tool for clustering. It handles the cyncronization of the shared partition (/drbd) between the nodes in the cluster. In other words, the exact data and configurations on the primary machine, will reside on the secondary machine as well. To install DRBD run:Step 1 ) Install the debian packages: 
apt-get install linux-headers-$(uname -r) drbd8-utils drbdlinks heartbeat nfs-kernel-server -y
Step 2) Edit /etc/drbd.conf
global {
 dialog-refresh 5; # 5 seconds
usage-count yes;
common {
  syncer { rate 120M; }
resource shared {
protocol C;
handlers {
pri-on-incon-degr "echo o > /proc/sysrq-trigger ; halt -f";
pri-lost-after-sb "echo o > /proc/sysrq-trigger ; halt -f";
local-io-error "echo o > /proc/sysrq-trigger ; halt -f";
#outdate-peer "/usr/lib/heartbeat/drbd-peer-outdater";
startup {
wfc-timeout  60;
degr-wfc-timeout 120;    # 2 minutes.
disk {
on-io-error   detach;
fencing resource-and-stonith;
after-sb-0pri discard-younger-primary;
after-sb-1pri consensus;
after-sb-2pri disconnect;
rr-conflict call-pri-lost;
   syncer {
	rate 120M;

 on master.ippbx {
 device     /dev/drbd0;
 disk       /dev/sda4;
    flexible-meta-disk  internal;
  on slave.ippbx {
  device    /dev/drbd0;
  disk      /dev/sda4;
  meta-disk internal;
 Step3 ) Edit the file /etc/drbdlinks.conf
Step 4) run the following on both nodes
drbdadm create-md shared
Step 5) Start DRBD on both nodes
# /etc/init.d/drbd start
Step 6) 
# drbdadm -- --overwrite-data-of-peer primary shared
# mkfs -t ext3 /dev/drbd0
# mount /dev/drbd0 /share
Step 7) Backup the Configuration
 # nano /tmp/folder.list
Step 8) tar the config folders and move to /drbd
# (cd / && tar cfp - `cat /tmp/folder.list`) | (cd /drbd && tar xfp -)
# drbdlinks start

2.3) Heartbeat Installation and Configuration

Heartbeat is the failover application. As the name implies, it monitors the status of the active server just like a watchdog and in case the active server fail, it will swing over to the passive. Here is how to do the configuration:

Step 1) Install the debian package

# apt-get install heartbeat

Step2) Remove the startup services

update-rc.d -f fonulator remove (if there is any)
update-rc.d -f mysql remove
update-rc.d -f apache2 remove
update-rc.d -f munin-node remove
update-rc.d -f dahdi remove
update-rc.d -f amportal remove
update-rc.d -f amportal-init remove

Step3) Edit the fie: /etc/ha.d/haresources

master.ippbx drbddisk::r0 Filesystem::/dev/drbd0::/drbd::ext3 drbdlinks drbdlinks apache2 munin-node mysql dahdi asterisk

Step4) Edit /etc/ha.d/authkeys

 auth 1
1 crc

Step5) chomd

 chmod 600 /etc/ha.d/authkeys

Step6) Edit /etc/ha.d/

        logfacility     local0
	debugfile /var/log/ha-debug
	logfile /var/log/ha-log
	#logfacility     local7
	#use_syslog     yes
	keepalive 2
	deadtime 20
	warntime 10
	initdead 70
	udpport 694
	#baud   19200
	#serial /dev/ttyS0      # Linux
	bcast   eth1            # Linux
	#ucast eth1
	auto_failback on
	#stonith_host *     baytech mylogin mysecretpassword
	#stonith_host ken3  rps10 /dev/ttyS1 kathy 0
	#stonith_host kathy rps10 /dev/ttyS1 ken3 0
	#set kernel "nowayout=0" for that
	#watchdog /dev/watchdog
	node    master.ippbx slave.ippbx

Step7) Restart Heartbeat

 # /etc/init.d/heartbeat restart


No comments yet.

Leave a Reply