Upload
henry
View
1.031
Download
2
Embed Size (px)
DESCRIPTION
Ultra Monkey Asterisk
Citation preview
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 1
www.intuitinnovations.com Dr. Daniel Krahenbuhl
TutorialLoad-Balancing Asterisk Servers with
UltraMonkey
Author: Dr. Daniel Krahenbuhl (CEO Intuit Innovations)Date: 15. March 2009
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 2
www.intuitinnovations.com Dr. Daniel Krahenbuhl
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.
The tutorial only covers the server’s in “green” color.
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.
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 3
www.intuitinnovations.com Dr. Daniel Krahenbuhl
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.
echo ip_vs_dh >> /etc/modulesecho ip_vs_ftp >> /etc/modulesecho ip_vs >> /etc/modulesecho ip_vs_lblc >> /etc/modulesecho ip_vs_lblcr >> /etc/modulesecho ip_vs_lc >> /etc/modulesecho ip_vs_nq >> /etc/modulesecho ip_vs_rr >> /etc/modulesecho ip_vs_sed >> /etc/modulesecho ip_vs_sh >> /etc/modulesecho ip_vs_wlc >> /etc/modulesecho ip_vs_wrr >> /etc/modules
Then you need to load the new modules / drivers into the kernel.
modprobe ip_vs_dhmodprobe ip_vs_ftpmodprobe ip_vsmodprobe ip_vs_lblcmodprobe ip_vs_lblcrmodprobe ip_vs_lcmodprobe ip_vs_nqmodprobe ip_vs_rrmodprobe ip_vs_sedmodprobe ip_vs_shmodprobe ip_vs_wlcmodprobe 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.
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 4
www.intuitinnovations.com Dr. Daniel Krahenbuhl
2.Install UltraMonkey on the Load Balancers (on both load balancers)
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
add this two lines at the end of the file
deb http://www.ultramonkey.org/download/3/ sarge maindeb-src http://www.ultramonkey.org/download/3 sarge main
Now you need to update your sources
apt-get update
and then we can install UltraMonkey
apt-get install ultramonkey
If you see this warning like this
You can ignore it! Smile.
¦ libsensors3 not functional ¦ ¦ ¦ ¦ It appears that your kernel is not compiled with sensors support. As a ¦ ¦ result, libsensors3 will not be functional on your system. ¦ ¦ ¦ ¦ If you want to enable it, have a look at "I2C Hardware Sensors Chip ¦
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 5
www.intuitinnovations.com Dr. Daniel Krahenbuhl
During the Ultra Monkey installation you will be asked a few question. Answer as follows:
Do you want to automatically load IPVS rules on boot?<-- No
Select a daemon method.<-- none
1. Enable Packet Forwarding on the Load-Balancers (LB1 & LB2)
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
2. Configure heartbeat And ldirectord
Now we have to create three configuration files for heartbeat. They must be identical on LB1 and LB2
vi /etc/ha.d/ha.cf
Important: As node we must use the output of
uname –n
# Enables packet forwardingnet.ipv4.ip_forward = 1
logfacility local0bcast eth0 # Linuxmcast eth0 225.0.0.1 694 1 0auto_failback offnode loadb1node loadb2respawn hacluster /usr/lib/heartbeat/ipfailapiauth ipfail gid=haclient uid=hacluster
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 6
www.intuitinnovations.com Dr. Daniel Krahenbuhl
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.
Important: This file must be exactly the same on both machines. It defines:
Who is the master (in our case loadb1) The floating IP (192.168.0.105) And starts the ldirectord (load balancing software)
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
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:
chmod 600 /etc/ha.d/authkeys
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.
loadb1 \ ldirectord::ldirectord.cf \ LVSSyncDaemonSwap::master \ IPaddr2::192.168.0.105/24/eth0/192.168.0.255
auth 33 md5 somerandomstring
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 7
www.intuitinnovations.com Dr. Daniel Krahenbuhl
vi /etc/ha.d/ldirectord.cf
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.
update-rc.d heartbeat start 75 2 3 4 5 . stop 05 0 1 6 .update-rc.d -f ldirectord remove
Great Job! You can fire your load balancer up for the first time.
/etc/init.d/ldirectord stop/etc/init.d/heartbeat start
checktimeout=10checkinterval=2autoreload=noquiescent=yeslogfile="/var/log/ldirectord.log"
virtual=190.255.200.17:506
real=190.255.200.21:5060 gatereal=190.255.200.22:5060 gatereal=190.255.200.23:5060 gateservice=sipscheduler=rrpersistent=600protocol=udpchecktype=connect
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 8
www.intuitinnovations.com Dr. Daniel Krahenbuhl
3. Test the Load Balancers (LB1 & LB2)
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
LB1 should show this:
LB2 should show this:
Now you need to check if ldirectord is running on LB1 and stopped on LB2
ldirectord ldirectord.cf status
Output on LB1:
Output on LB2:
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:16:3e:40:18:e5 brd ff:ff:ff:ff:ff:ff inet 190.255.200.15/24 brd 192.168.0.255 scope global eth0 inet 190.255.200.17/24 brd 192.168.0.255 scope global secondary eth0
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:16:3e:50:e3:3a brd ff:ff:ff:ff:ff:ff inet 190.255.200.16/24 brd 192.168.0.255 scope global eth0
ldirectord for /etc/ha.d/ldirectord.cf is running with pid: 2345
ldirectord is stopped for /etc/ha.d/ldirectord.cf
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 9
www.intuitinnovations.com Dr. Daniel Krahenbuhl
Now we want to see the routing output tables of LB1 and LB2.
ipvsadm -L –n
Output on LB1:
Output on LB2:
Now we want to check the master / slave status.
/etc/ha.d/resource.d/LVSSyncDaemonSwap master status
Output on LB1:
Output on LB2:
If all this tests are successful you can now configure the Asterisk Servers.
IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn
UDP 190.255.200.17:5060 rr persistent 600 -> 190.255.200.21:5060 Route 1 0 0 -> 190.255.200.22:5060 Route 1 0 0 -> 190.255.200.23:5060 Route 1 0 0
IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn
master stopped
master running(ipvs_syncmaster pid: 1591)
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 10
www.intuitinnovations.com Dr. Daniel Krahenbuhl
4. Configure the Asterisk servers (AS1, AS2,AS3)
First we need to install iproute on all Asterisk servers.
apt-get install iproute
Change the following in /etc/sysctl.conf:
vi /etc/sysctl.conf
Then run this:
sysctl –p
# Enable configuration of arp_ignore optionnet.ipv4.conf.all.arp_ignore = 1
# When an arp request is received on eth0, only respond if that address is# configured on eth0. In particular, do not respond if the address is# configured on lonet.ipv4.conf.eth0.arp_ignore = 1
# Ditto for eth1, add for all ARPing interfaces#net.ipv4.conf.eth1.arp_ignore = 1
# Enable configuration of arp_announce optionnet.ipv4.conf.all.arp_announce = 2
# 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
# Ditto for eth1, add for all ARPing interfaces#net.ipv4.conf.eth1.arp_announce = 2
Tutorial Asterisk Load-Balancing with UltraMonkey P a g e | 11
www.intuitinnovations.com Dr. Daniel Krahenbuhl
Then you need to modify the /etc/network/interfaces.
vi /etc/network/interfaces
Then bring up lo:0
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
auto lo:0iface lo:0 inet static address 190.255.200.17 netmask 255.255.255.255 pre-up sysctl -p > /dev/null