Asterisk Clustering with DRBD/Heartbeat

Today a friend of mine asked me if I have got any manual for an Asterisk HA setup, so I decided to write this post to share with everyone else.

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.

Scenario:


IP Address Configuration

Primary IP-PBX:
eth0 10.8.0.91
eth1 192.168.2.1 

Secondary IP-PBX:
eth0 10.8.0.92
eth1 192.168.2.2 

Floating IP Address : 10.8.0.90
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;
}
net
{
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;
 address    192.168.2.1:7789;
    flexible-meta-disk  internal;
  }
  on slave.ippbx {
  device    /dev/drbd0;
  disk      /dev/sda4;
  address   192.168.2.2:7789;
  meta-disk internal;
  }
}
 Step3 ) Edit the file /etc/drbdlinks.conf
#usebindmount(1)
mountpoint('/drbd')
link('/var/spool/asterisk')
link('/var/www')
link('/var/lib/asterisk')
link('/var/lib/munin')
link('/var/lib/mysql')
link('/var/lib/php5')
link('/etc/asterisk')
link('/etc/apache2')
link('/etc/munin')
link('/etc/mysql')
link('/etc/php5')
link('/usr/lib/asterisk')
link('/var/log/asterisk')
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
/var/spool/asterisk
/var/www
/var/lib/asterisk
/var/lib/munin
/var/lib/mysql
/var/lib/php5
/etc/asterisk
/etc/apache2
/etc/munin
/etc/mysql
/etc/php5
/usr/lib/asterisk
/var/log/asterisk
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 10.8.0.90/24/eth0 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/ha.cf

        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 192.168.43.12
	auto_failback on
	#stonith_host *     baytech 10.0.0.3 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

You may also like

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *