Ultra Monkey Asterisk
Ultra Monkey Asterisk
Tutorial
Load-Balancing Asterisk Servers with
UltraMonkey
The following tutorial will guide you in installing a enterprise Asterisk deployment which you
can scale up to many 10’000 concurrent calls. I assume that you have Linux, mySQL, Apache2
and general network know-how. We deployed this kind of architecture in various live
environments without any issues.
This is the setup that we normally use to deploy high-end Asterisk systems.
We are not discussing the setup of Asterisk Real Time Database, Nagios and MySQL cluster in
this tutorial.
Enable LVS
In this first step you need to enable IPVS on the load balancing servers (directors). IPVS stands for IP
Virtual Server and implements transport-layer load balancing inside the Linux kernel, so called Layer-4
switching.
Then you need to load the new modules / drivers into the kernel.
modprobe ip_vs_dh
modprobe ip_vs_ftp
modprobe ip_vs
modprobe ip_vs_lblc
modprobe ip_vs_lblcr
modprobe ip_vs_lc
modprobe ip_vs_nq
modprobe ip_vs_rr
modprobe ip_vs_sed
modprobe ip_vs_sh
modprobe ip_vs_wlc
modprobe ip_vs_wrr
If you get errors during this process you most probably you kernel wasnot compile with IPVS support.
You need to compile a new kernel or install a kernel image with IPVS support.
If you install Debian 4 (Netinstall) you will have no problems and your kernel will support IPVS.
Ultra Monkey is a project to create load balanced and highly available services on a local area network
using Open Source components on the Linux operating system; the Ultra Monkey package provides
heartbeat (used by the two load balancers to monitor each other and check if the other node is still
alive) and ldirectord, the actual load balancer.
UltraMonkey is a project to build load balanced and high available services on a local area network using
100% open source components on the Linux operating system. UltraMonkey installs heartbeat (used to
build high availability between your two load balancer with constant monitoring if the other node is still
alive) and ldirector, the actual load balancer.
You need to adjust your sources.list to be able to install UltraMonkey with apt
vi /etc/apt/sources.list
apt-get update
During the Ultra Monkey installation you will be asked a few question. Answer as follows:
The load balancers must be able to route traffic to the Asterisk servers. Therefore we must
enable packet forwarding on the load balancers. Add the following lines to /etc/sysctl.conf:
vi /etc/sysctl.conf
Then modify the kernel parameter during runtime with the following command:
sysctl –p
Now we have to create three configuration files for heartbeat. They must be identical on LB1 and LB2
vi /etc/ha.d/ha.cf
logfacility local0
bcast eth0 # Linux
mcast eth0 225.0.0.1 694 1 0
auto_failback off
node loadb1
node loadb2
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
uname –n
In our sample here we broadcast the heartbeat over the eth0 interface. You could also use a dedicated
eth for the heartbeat if you add/use a additional network card on both load balancers. It is also possible
to do the heartbeat over a serial cable (null modem cable) between the two servers.
Now you need to configure the haresources file which defines the virtual or floating IP address for your
load balancers as well as it starts the necessary services on the load balancers.
loadb1 \
ldirectord::ldirectord.cf \
LVSSyncDaemonSwap::master \
IPaddr2::192.168.0.105/24/eth0/192.168.0.255
Important: This file must be exactly the same on both machines. It defines:
The first word (loadb1) is the result of uname –n on the LB1 server.
Now you need to setup the authentication between the two load balancers.
vi /etc/ha.d/authkeys
auth 3
3 md5 somerandomstring
somerandomstring is your password which the two heartbeat daemons on loadb1 and loadb2 use to
authenticate against each other. Use your own password here.
The /etc/ha.d/authkeys file must be readable by root only, therefore you do this:
As you know by now ldirectord is the actual load balancer application. You are going to configure your
two load balancers (LB1 andLB2 in an active/passive setup, which means we have one active load
balancer, and the other one is a hot-standby and becomes active if the active one fails. To make that
work, you must create the ldirectord configuration file /etc/ha.d/ldirectord.cf which again must be
identical on LB1 and LB2.
vi /etc/ha.d/ldirectord.cf
checktimeout=10
checkinterval=2
autoreload=no
quiescent=yes
logfile="/var/log/ldirectord.log"
virtual=190.255.200.17:506
real=190.255.200.21:5060 gate
real=190.255.200.22:5060 gate
real=190.255.200.23:5060 gate
service=sip
scheduler=rr
persistent=600
protocol=udp
checktype=connect
In the virtual line we enter our virtual / floating IP address, and in the real lines we list the IP addresses
of our Asterisk servers. The other parameter you can find on http://linux.die.net/man/8/ldirectord
Let’s create the system startup link for heartbeat and remove those of ldirectord because ldirectord we
want to start by the heartbeat daemon.
Great Job! You can fire your load balancer up for the first time.
/etc/init.d/ldirectord stop
/etc/init.d/heartbeat start
Let’s see if the load balancers working as expected. LB1 should have the virtual IP assigned and
ldirectord running, LB2 should not have the virtual IP assigned as well as ldiretord should not be running.
ip addr sh eth0
Now you need to check if ldirectord is running on LB1 and stopped on LB2
Output on LB1:
Output on LB2:
Now we want to see the routing output tables of LB1 and LB2.
ipvsadm -L –n
Output on LB1:
Output on LB2:
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
Output on LB1:
master running
(ipvs_syncmaster pid: 1591)
Output on LB2:
master stopped
If all this tests are successful you can now configure the Asterisk Servers.
vi /etc/sysctl.conf
# Enable configuration of arp_ignore option
net.ipv4.conf.all.arp_ignore = 1
# When making an ARP request sent through eth0 Always use an address that
# is configured on eth0 as the source address of the ARP request. If this
# is not set, and packets are being sent out eth0 for an address that is
on
# lo, and an arp request is required, then the address on lo will be used.
# As the source IP address of arp requests is entered into the ARP cache
on
# the destination, it has the effect of announcing this address. This is
# not desirable in this case as adresses on lo on the real-servers should
# be announced only by the linux-director.
net.ipv4.conf.eth0.arp_announce = 2
sysctl –p
vi /etc/network/interfaces
auto lo:0
iface lo:0 inet static
address 190.255.200.17
netmask 255.255.255.255
pre-up sysctl -p > /dev/null
ifup lo:0
That’s it you can now point your IP phone to the load balancers virtual IP.
In our case 190.255.200.17
Make sure you add the port to the register server parameter in your IP phone.
Like: 190.255.200.17:5060