[asterisk-users] Load balancing SIP extensions.
Yehavi Bourvine +972-8-9489444
YEHAVI at VMS.HUJI.AC.IL
Sun Feb 24 06:14:00 CST 2008
Hello,
Here is how I do this. The prerequisits are:
- MySQL to hold the extensions realtime database. MySQL is synchronized
among all servers using the Master/slave replication model.
- The phones are spread by some external algorithm over the Asterisk servers
(statefull load balancer, statically defined in the config file of the
phone, etc.).
The idea is to locate on which server the destination phone is registered and
redirect the call to it. For this:
/etc/asterisk/asterisk.conf has the parameter "sysname" set to its IP address
(you can use also a DNS name, but I want to be independent of name
resolution). This causes the server to set the field "regserver" to be
saved in the MySQL database to the IP address of the server.
/etc/asterisk/extensions: The logic to check whether the value of "regsever"
is different from "sysname" and if so - redirect the call. The code
fragments are (I am using AEL):
To get the regserver from the database:
MYSQL(Query resID ${connid} SELECT regserver from sip_users where
name='${EXTEN}');
MYSQL(Fetch FetchId ${resID} RegServer);
MYSQL(Clear ${resID});
so now RegServer contains the server where the phone is registered. Next:
if(("${DEVSTATE(SIP/${EXTEN})}" == "UNAVAILABLE") ||
("${DEVSTATE(SIP/${EXTEN})}" == "INVALID")) {
if("${SYSTEMNAME}" != "${RegServer}") {
Transfer(SIP/${EXTEN}@${RegServer});
return;
};
};
I check for the device state so in case the phone has double registration
(primary and backup server) it will be processed localy.
Regards, __Yehavi:
More information about the asterisk-users
mailing list