我们可以使用 opensips 或 kamailio 作为 sip 负载均衡器,并根据资源的可用性以多种方式提供高可用性服务。我写了一个分步指南here
安装 openSIPS:
按照this guide 安装openSIPS 2.4 并使用以下配置编辑opensips.cfg。
如果您没有配置高可用性并仅在 openSIPS 上本地托管 mysql 数据库,那么您可能希望使用 localhost 或 127.0.0.1
还可以更改数据库凭据和 SIP 监听地址。
vi /etc/opensips/opensips.cfg
log_level=4
sip_warning=0
log_stderror=no
log_facility=LOG_LOCAL2
log_name="opensips"
debug_mode=yes
children=4
dns_try_ipv6=no
auto_aliases=no
#advertised_address="12.135.59.0"
mhomed=1
listen=udp:10.128.0.1:5060
mpath="/usr/lib64/opensips/modules"
loadmodule "db_mysql.so"
loadmodule "signaling.so"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "uri.so"
loadmodule "dialog.so"
loadmodule "maxfwd.so"
loadmodule "textops.so"
loadmodule "mi_fifo.so"
loadmodule "dispatcher.so"
loadmodule "load_balancer.so"
loadmodule "sipmsgops.so"
loadmodule "proto_udp.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("dialog", "db_mode", 1)
#change database credentials below
#if this is the only openSIPS node in network and you are using HighAvailability use mysql database host as localhost or 127.0.0.1
modparam("dialog", "db_url", "mysql://abc:123@11.11.11.11/opensips") modparam("rr", "enable_double_rr", 0)
modparam("rr", "append_fromtag", 1)
modparam("tm", "fr_timer", 2)
#change database credentials below
modparam("dispatcher", "db_url", "mysql://abc:123@11.11.11.11/opensips")
modparam("dispatcher", "ds_ping_method", "OPTIONS")
modparam("dispatcher", "ds_ping_interval", 5)
modparam("dispatcher", "ds_probing_threshhold", 2)
modparam("dispatcher", "ds_probing_mode", 1)
modparam("load_balancer", "db_url", "mysql://abc:123@11.11.11.11/opensips")
modparam("load_balancer", "probing_method", "OPTIONS")
modparam("load_balancer", "probing_interval", 5)
route{
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
if (!has_totag()) {
record_route();
}
else {
loose_route();
t_relay();
exit;
}
if (is_method("CANCEL")) {
if (t_check_trans())
t_relay();
exit;
}
if (is_method("INVITE")) {
if (!load_balance("1","pstn","1")) {
log("sreekanth invite method\n");
send_reply("503","Service Unavailable");
exit;
}
}
else if (is_method("REGISTER")) {
if (!ds_select_dst("1", "4")) {
send_reply("503","Service Unavailable");
exit;
}
}
else {
send_reply("405","Method Not Allowed");
exit;
}
if (!t_relay()) {
sl_reply_error();
}
}
现在我们需要在opensips数据库的负载均衡和调度表中插入条目
插入opensips.load_balancer(id,group_id,dst_uri,resources,probe_mode,description)值('1','1','sip: 10.10.10.5','vm=100;conf=100;transc=100;pstn=500','1','FS1');
插入opensips.load_balancer(id,group_id,dst_uri,resources,probe_mode,description)值('2','1','sip: 10.10.10.4 ','vm=100;conf=100;transc=100;pstn=500', '1','FS2');
并在调度表中插入记录。
插入到opensips.dispatcher(id,setid,destination,socket,state,weight,priority,description1) ('1', '1','sip:10.10.10.5:5060','','0', '1', '1','','FS1');
插入到opensips.dispatcher (id, setid, destination, socket, state, weight, priority, id2) ('1', '1','sip:10.10.10.4:5060','','0', '1', '1','','FS2');
配置 Freeswitch:
在 freeswitch /etc/freeswitch/vars.xml 中将域更改为 opensips 域名。并重新加载freeswitch