FreeSWITCH折腾笔记8——使用OpenSIPS进行负载均衡
精选 原创
ligen119©著作权
文章标签OpenSIPSFreeSWITCHkeepalived负载均衡文章分类负载均衡服务器阅读数10000+
通过OpenSIPS对FreeSWITCH进行负载均衡网络上的文章很多,但都是基于老版本的OpenSIPS,目前最新的OpenSIPS LTS版是2.4,如果使用老版本配置文件,OpenSIPS是运行不起来(当然通过一番修改后还是可以运行起来的)。笔者经过一番折腾,成功实现了OpenSIPS 2.4版本对FreeSWITCH的负载均衡,这里将折腾的注意项及最终的配置记下来,以免下次真的要用时又重新折腾。笔者对OpenSIPS不是很熟悉,可能有些地方有纰漏,欢迎各位网友指正。
一、环境介绍:
OpenSIPS OS:debian 8
OpenSIPS Version:2.4 LTS
OpenSIPS IP:172.16.100.30/31
OpenSIPS HA:keepalived
OpenSIPS VIP:172.16.100.32
OpenSIPS domain:sofia.superpipi.cn
FreeSWITCH OS:debian 8
FreeSWITCH Version:1.81
FreeSWITCH IP:172.16.100.10/11
DB:Mysql 5.7
注:OpenSIPS的高可用,采用keepalived进行VIP切换实现,目前未添加OpenSIPS的可用性检测脚本,仅作VIP切换。
二、组网介绍:
本次试验采用以下组网结构,两个节点OpenSIPS采用keepalived进行VIP切换,两个节点FreeSWITCH实现负荷分担,OpenSIPS和FreeSWITCH均连接到MySQL(注:FreeSWITCH连接MySQL数据库,需提取channels建表SQL并将字段长度改小,然后手工创建channels表)。在路由器(笔者使用的路由器有Dnsmasq功能)上将域名sofia.superpipi.cn解析到OpenSIPS的VIP(172.16.100.32),SIP分机注册时通过域名sofia.superpipi.cn进行注册。至于为何要通过域名注册,这是因为FreeSWITCH默认的域名是其本地的IP,若注册的域非FreeSWITCH本地IP,则可能导致注册不上同时也无法通话,通过修改FreeSWITCH的域名称可以实现。如果将FreeSWITCH域名修改为OpenSIPS的VIP,那么VIP只有一个,FreeSWITCH就只能有一个域了,而指向OpenSIPS的VIP的域名可以是多个,这样就可以实现FreeSWITCH多域。至于FreeSWITCH为何要多个域,主要是方便权限管控,在实际生产中意义重大。
三、安装及基础配置:
3.1、安装和配置keepalived
3.1.1、安装keepalived
keepalived安装直接通过apt安装即可
apt-get install keepalived
- 1.
3.1.2、修改keepalived配置:
编辑/etc/keepalived/keepalived.conf,将两个节点分别按以下配置修改。
- 01节点keepalived配置:
! Configuration File for keepalived
global_defs {
notification_email {
acassen
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 172.16.100.251
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
garp_master_delay 10
smtp_alert
virtual_router_id 53
priority 200
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 915119
}
virtual_ipaddress {
172.16.100.32/24
172.16.100.32/24 label eth0:1
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 02节点keepalived配置:
! Configuration File for keepalived
global_defs {
notification_email {
acassen
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 172.16.100.251
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
garp_master_delay 10
smtp_alert
virtual_router_id 53
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 915119
}
virtual_ipaddress {
172.16.100.32/24
172.16.100.32/24 label eth0:1
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
3.2、安装和配置OpenSIPS
3.2.1、安装OpenSIPS
笔者安装OpenSIPS是通过官方deb包直接安装的,执行步骤如下:
- 添加源:
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 049AD65B
echo "deb http://apt.opensips.org jessie 2.4-releases" >/etc/apt/sources.list.d/opensips.list
- 1.
- 2.
- 更新源和安装OpenSIPS
apt-get update && apt-get install opensips
- 1.
3.2.2、配置OpenSIPS
- 创建数据库
编辑/etc/opensips/opensipsctlrc将以下项去注释并按实际情况修改,或直接通过echo追加到/etc/opensips/opensipsctlrc
echo "SIP_DOMAIN=sofia.superpipi.cn" >> /etc/opensips/opensipsctlrc
echo "DBENGINE=MYSQL" >> /etc/opensips/opensipsctlrc
echo "DBPORT=3306" >> /etc/opensips/opensipsctlrc
echo "DBHOST=172.16.100.15" >> /etc/opensips/opensipsctlrc
echo "DBNAME=opensips" >> /etc/opensips/opensipsctlrc
echo "DBRWUSER=opensips" >> /etc/opensips/opensipsctlrc
echo "DBRWPW="ligen119"" >> /etc/opensips/opensipsctlrc
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
执行创建数据库工具(注:如数据库不在本机,需授权root用户远程访问权限)
/usr/sbin/opensipsdbctl create
- 1.
运行以上命令后会提示输入root密码,输入root密码后提示输入数据库字符集(吐槽一下不能选utf8),这里输入gbk(后续可能需要存储中文),其后按向导进行数据库创建。
- 配置启动参数
启动参数编辑不是必须,如果生产应用建议还是将内存参数做相应的扩大。
编辑/etc/default/opensips将以下项去注释并按实际情况修改,或直接通过echo追加到/etc/default/opensips
echo "RUN_OPENSIPS=yes" >>/etc/default/opensips
echo "USER=opensips" >>/etc/default/opensips
echo "GROUP=opensips" >>/etc/default/opensips
echo "S_MEMORY=512" >>/etc/default/opensips
echo "P_MEMORY=32" >>/etc/default/opensips
echo "DUMP_CORE=yes" >>/etc/default/opensips
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 配置文件
编辑/etc/opensips/opensips.cfg,清空原配置文件,将以下内容插入配置文件。(本配置文件基本是参考freeswitch官方wiki的配置文件)
log_level=1 #老版本日志级别参数为debug,级别范围1-4,建议生产上设置为1,为3或者4时将产生大量日志,磁盘空间很快就不够了
sip_warning=0
log_stderror=no
log_facility=LOG_LOCAL0
log_name="opensips"
debug_mode=no
children=4
dns_try_ipv6=no
auto_aliases=no
listen=udp:172.16.100.30:5062 #另外一个节点设置为udp:172.16.100.31:5062,取本地IP,不添加该监听项则备用节点无法与负载节点握手,导致备用节点将调度列表的负载节点设置为不可用
listen=udp:172.16.100.32:5060
mpath="/usr/lib/x86_64-linux-gnu/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)
modparam("dialog", "db_url", "mysql://opensips:ligen119@172.16.100.15/opensips")
modparam("rr", "enable_double_rr", 1)
modparam("rr", "append_fromtag", 1)
modparam("tm", "fr_timer", 2)
modparam("dispatcher", "db_url", "mysql://opensips:ligen119@172.16.100.15/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://opensips:ligen119@172.16.100.15/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")) {
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();
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 添加负载节点
在数据库添加两个负载节点信息
INSERT INTO </span>opensips<span class="token punctuation">
.</span>load_balancer<span class="token punctuation">
(</span>id<span class="token punctuation">
, </span>group_id<span class="token punctuation">
, </span>dst_uri<span class="token punctuation">
, </span>resources<span class="token punctuation">
, </span>probe_mode<span class="token punctuation">
, </span>description<span class="token punctuation">
) VALUES ('1', '1', 'sip:172.16.100.10', 'vm=100;conf=100;transc=100;pstn=500', '1', 'FS1');
INSERT INTO </span>opensips<span class="token punctuation">
.</span>load_balancer<span class="token punctuation">
(</span>id<span class="token punctuation">
, </span>group_id<span class="token punctuation">
, </span>dst_uri<span class="token punctuation">
, </span>resources<span class="token punctuation">
, </span>probe_mode<span class="token punctuation">
, </span>description<span class="token punctuation">
) VALUES ('2', '1', 'sip:172.16.100.11', 'vm=100;conf=100;transc=100;pstn=500', '1', 'FS2');
- 1.
- 2.
- 允许绑定非本机IP
执行以下命令使OpenSIPS能监听在本机IP,当VIP飘过来时OpenSIPS服务即可用
echo 'net.ipv4.ip_nonlocal_bind=1' >> /etc/sysctl.conf
- 1.
- 将日志输出到指定文件
在/etc/rsyslog.conf追加keepalived和OpenSIPS日志输出配置。(注:OpenSIPS配置文件中log_stderror和debug_mode需设置成no,否则可能不能输出单独日志)
echo "local0.* /var/log/opensips.log" >>/etc/rsyslog.conf
echo "local1.* /var/log/keepalived.log" >>/etc/rsyslog.conf
- 1.
- 2.
3.2.3、开始OpenSIPS
- 重启rsyslog、keepalived、OpenSIPS
service rsyslog restart
service keepalived restart
service opensips restart
- 1.
- 2.
- 3.
- 添加FreeSWITCH到调度列表
执行以下命令将两个节点添加到调度列表,(这里添加调度器的命令和1.7版本是有区别的)
opensipsctl dispatcher addgw 1 sip:172.16.100.10 5060 0 50 'FS1' '节点1'
opensipsctl dispatcher addgw 1 sip:172.16.100.11 5060 0 50 'FS2' '节点2'
- 1.
- 2.
添加调度列表成功后,在两个FreeSWITCH的控制通过sofia profile sofia.superpipi.cn siptrace on命令打开sip消息跟踪即可看到两个OpenSIPS节点不停在跟FreeSWITCH通过”OPTIONS“消息进行握手,如下:
------------------------------------------------------------------------
recv 349 bytes from udp/[172.16.100.31]:5062 at 21:41:43.502417:
------------------------------------------------------------------------
OPTIONS sip:172.16.100.10 SIP/2.0
Via: SIP/2.0/UDP 172.16.100.31:5062;branch=z9hG4bK2fe7.7ea62cf7.0
To: sip:172.16.100.10
From: <sip:dispatcher@localhost>;tag=5f8cfd923bd21a2d7f298654cd327b22-8a62
CSeq: 14 OPTIONS
Call-ID: 2d922c18059b1edd-1681@172.16.100.31
Max-Forwards: 70
Content-Length: 0
User-Agent: OpenSIPS (2.4.2 (x86_64/linux))
------------------------------------------------------------------------
send 735 bytes to udp/[172.16.100.31]:5062 at 21:41:43.503285:
------------------------------------------------------------------------
SIP/2.0 200 OK
Via: SIP/2.0/UDP 172.16.100.31:5062;branch=z9hG4bK2fe7.7ea62cf7.0
From: <sip:dispatcher@localhost>;tag=5f8cfd923bd21a2d7f298654cd327b22-8a62
To: <sip:172.16.100.10>;tag=t2y6pUXm66tQH
Call-ID: 2d922c18059b1edd-1681@172.16.100.31
CSeq: 14 OPTIONS
Contact: <sip:172.16.100.10>
User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
Accept: application/sdp
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Content-Length: 0
------------------------------------------------------------------------
recv 349 bytes from udp/[172.16.100.30]:5062 at 21:41:45.769168:
------------------------------------------------------------------------
OPTIONS sip:172.16.100.10 SIP/2.0
Via: SIP/2.0/UDP 172.16.100.30:5062;branch=z9hG4bKbace.ec1b06f.0
To: sip:172.16.100.10
From: <sip:dispatcher@localhost>;tag=45af385df62c8fa46b1bdd54b7adb556-4f80
CSeq: 14 OPTIONS
Call-ID: 735a40b173b81153-37063@172.16.100.32
Max-Forwards: 70
Content-Length: 0
User-Agent: OpenSIPS (2.4.2 (x86_64/linux))
------------------------------------------------------------------------
send 735 bytes to udp/[172.16.100.30]:5062 at 21:41:45.770861:
------------------------------------------------------------------------
SIP/2.0 200 OK
Via: SIP/2.0/UDP 172.16.100.30:5062;branch=z9hG4bKbace.ec1b06f.0
From: <sip:dispatcher@localhost>;tag=45af385df62c8fa46b1bdd54b7adb556-4f80
To: <sip:172.16.100.10>;tag=UBrZrper3FHaD
Call-ID: 735a40b173b81153-37063@172.16.100.32
CSeq: 14 OPTIONS
Contact: <sip:172.16.100.10>
User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
Accept: application/sdp
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Content-Length: 0
------------------------------------------------------------------------
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
四、FreeSWITCH配置和验证
4.1、域名修改
因话机注册时是通过域名注册,因此需要修改FreeSWITCH的域为注册的域名。
编辑../conf/vars.xml,将domain设置为sofia.superpipi.cn。(注:如FreeSWITCH使用多域,则参照多域的方式进行修改,参考:https://www.cnblogs.com/lzpong/p/8573372.html)
<X-PRE-PROCESS cmd="set" data="domain=sofia.superpipi.cn"/>
- 1.
修改后需重启FreeSWITCH才能生效
4.2、注册验证
笔者分别使用eyeBeam、Linphone、eSpace SoftPhone三种软电话和一个Fanvil X5硬电话进行注册测试,均可注册成功。
在freeswitch所在服务器执行fs_cli -x “sofia status profile sofia.superpipi.cn reg”
结果如下:
root@debian:~# fs_cli -x "sofia status profile sofia.superpipi.cn reg"
Registrations:
=================================================================================================
Call-ID: 19024618511954-772266364347@172.16.100.110
User: 1004@sofia.superpipi.cn
Contact: "1004" <sip:1004@172.16.100.110:6060>
Agent: Fanvil X5 1.3.256.1566
Status: Registered(UDP)(unknown) EXP(2018-09-23 22:14:29) EXPSECS(2228)
Ping-Status: Reachable
Ping-Time: 0.00
Host: debian
IP: 172.16.100.32
Port: 5060
Auth-User: 1004
Auth-Realm: sofia.superpipi.cn
MWI-Account: 1004@sofia.superpipi.cn
Call-ID: YTFjZjBmZDZjNWEyZGQwNTgxMTEzZDcwMTAwNDdiZDQ.
User: 1000@sofia.superpipi.cn
Contact: "1000" <sip:1000@172.16.100.251:51540;rinstance=f8dca36459b0bdec>
Agent: eyeBeam release 1011d stamp 40820
Status: Registered(UDP)(unknown) EXP(2018-09-23 22:35:27) EXPSECS(3486)
Ping-Status: Reachable
Ping-Time: 0.00
Host: debian
IP: 172.16.100.32
Port: 5060
Auth-User: 1000
Auth-Realm: sofia.superpipi.cn
MWI-Account: 1000@sofia.superpipi.cn
Call-ID: SdnqWECcxy
User: 1002@sofia.superpipi.cn
Contact: "" <sip:1002@172.16.100.251:64242;transport=udp>
Agent: Linphone Desktop/4.1.1 (belle-sip/1.6.3)
Status: Registered(UDP)(unknown) EXP(2018-09-23 21:47:38) EXPSECS(617)
Ping-Status: Reachable
Ping-Time: 0.00
Host: debian
IP: 172.16.100.32
Port: 5060
Auth-User: 1002
Auth-Realm: sofia.superpipi.cn
MWI-Account: 1002@sofia.superpipi.cn
Call-ID: NzBhNzg3NTY2NWExZmE0M2ZiODdlZGIwYmY1NGVmY2Y.
User: 1003@sofia.superpipi.cn
Contact: "" <sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c>
Agent: HUAWEI OpenEye v3.1
Status: Registered(UDP)(unknown) EXP(2018-09-23 21:42:52) EXPSECS(331)
Ping-Status: Reachable
Ping-Time: 0.00
Host: debian
IP: 172.16.100.32
Port: 5060
Auth-User: 1003
Auth-Realm: sofia.superpipi.cn
MWI-Account: 1003@sofia.superpipi.cn
Total items returned: 4
=================================================================================================
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
4.3、通话验证
- 使用分机1000拨通1003
172.16.100.10(FS1)节点收到分机1000发来的”INVITE”消息,并向分机1003发起”INVITE”消息,消息跟踪如下(注:删除了SDP和省略部分消息):
recv 1431 bytes from udp/[172.16.100.32]:5060 at 21:48:29.481716:
------------------------------------------------------------------------
INVITE sip:1003@sofia.superpipi.cn SIP/2.0
Record-Route: <sip:172.16.100.32;lr;ftag=f104f441;did=83f.44ccd293>
Via: SIP/2.0/UDP 172.16.100.32:5060;branch=z9hG4bKc6fd.c55828d7.0
Via: SIP/2.0/UDP 172.16.100.251:51540;received=172.16.100.251;branch=z9hG4bK-d87543-8651904ed85c056f-1--d87543-;rport=51540
Max-Forwards: 69
Contact: <sip:1000@172.16.100.251:51540>
To: "1003"<sip:1003@sofia.superpipi.cn>
From: "1000"<sip:1000@sofia.superpipi.cn>;tag=f104f441
Call-ID: NDkyOTM1YWI4YzhiMGY4MWI0ZDMwYmQzNThjYjE2NzQ.
CSeq: 2 INVITE
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
Content-Type: application/sdp
Proxy-Authorization: Digest username="1000",realm="sofia.superpipi.cn",nonce="e9c8201d-3c8a-461b-a86c-4719edc9cae3",uri="sip:1003@sofia.superpipi.cn",response="07eca040fed8f8ecfb7392671af7cc20",cnonce="44bb05f0c983e2e22b491a7bc82f0ab6",nc=00000001,qop=auth,algorithm=MD5
User-Agent: eyeBeam release 1011d stamp 40820
Content-Length: 442
------------------------------------------------------------------------
send 354 bytes to udp/[172.16.100.32]:5060 at 21:48:29.502215:
------------------------------------------------------------------------
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 172.16.100.32:5060;branch=z9hG4bKc6fd.c55828d7.0
From: "1000"<sip:1000@sofia.superpipi.cn>;tag=f104f441
To: "1003"<sip:1003@sofia.superpipi.cn>
Call-ID: NDkyOTM1YWI4YzhiMGY4MWI0ZDMwYmQzNThjYjE2NzQ.
CSeq: 2 INVITE
User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
Content-Length: 0
------------------------------------------------------------------------
send 1272 bytes to udp/[172.16.100.251]:5060 at 21:48:30.575115:
------------------------------------------------------------------------
INVITE sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c SIP/2.0
Via: SIP/2.0/UDP 172.16.100.10;rport;branch=z9hG4bKg7X53ye14956r
Max-Forwards: 68
From: "Extension 1000" <sip:1000@sofia.superpipi.cn>;tag=9e7rDt1XcyNZc
To: <sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c>
Call-ID: 326006cf-39da-1237-4983-000c2953a0b0
CSeq: 128519191 INVITE
Contact: <sip:mod_sofia@172.16.100.10:5060>
User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 246
X-FS-Support: update_display,send_info
Remote-Party-ID: "Extension 1000" <sip:1000@sofia.superpipi.cn>;party=calling;screen=yes;privacy=off
------------------------------------------------------------------------
recv 318 bytes from udp/[172.16.100.251]:5060 at 21:48:30.634089:
------------------------------------------------------------------------
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 172.16.100.10;rport=5060;branch=z9hG4bKg7X53ye14956r
To: <sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c>
From: "Extension 1000" <sip:1000@sofia.superpipi.cn>;tag=9e7rDt1XcyNZc
Call-ID: 326006cf-39da-1237-4983-000c2953a0b0
CSeq: 128519191 INVITE
Content-Length: 0
------------------------------------------------------------------------
recv 399 bytes from udp/[172.16.100.251]:5060 at 21:48:30.634221:
------------------------------------------------------------------------
SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 172.16.100.10;rport=5060;branch=z9hG4bKg7X53ye14956r
Contact: <sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c>
To: <sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c>;tag=77eb678a
From: "Extension 1000"<sip:1000@sofia.superpipi.cn>;tag=9e7rDt1XcyNZc
Call-ID: 326006cf-39da-1237-4983-000c2953a0b0
CSeq: 128519191 INVITE
Content-Length: 0
------------------------------------------------------------------------
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 使用分机1002拨打1004
在1000与1003通话状态下,使用分机1002拨打1004,172.16.100.11(FS2)节点收到分机1002发来的”INVITE”消息,并向分机1004发起”INVITE”消息,消息跟踪如下(注:删除了SDP和省略部分消息):
recv 1935 bytes from udp/[172.16.100.32]:5060 at 21:54:32.072291:
------------------------------------------------------------------------
INVITE sip:1004@sofia.superpipi.cn SIP/2.0
Record-Route: <sip:172.16.100.32;lr;ftag=0HIj01pcT;did=cdf.8df222c6>
Via: SIP/2.0/UDP 172.16.100.32:5060;branch=z9hG4bKc54a.a53a6847.0
Via: SIP/2.0/UDP 172.16.100.251:64242;received=172.16.100.251;branch=z9hG4bK.m5Jiasf70;rport=64242
From: <sip:1002@sofia.superpipi.cn>;tag=0HIj01pcT
To: sip:1004@sofia.superpipi.cn
CSeq: 21 INVITE
Call-ID: LJD8EMDXo0
Max-Forwards: 69
Supported: replaces, outbound
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, UPDATE
Content-Type: application/sdp
Content-Length: 898
Contact: <sip:1002@172.16.100.251:64242;transport=udp>;+sip.instance="<urn:uuid:bcb91990-4d9b-47ea-8ba8-3af172d27fce>"
User-Agent: Linphone Desktop/4.1.1 (belle-sip/1.6.3)
Proxy-Authorization: Digest realm="sofia.superpipi.cn", nonce="771a93e4-504d-410e-b5ca-4b927a297b61", algorithm=MD5, username="1002", uri="sip:1004@sofia.superpipi.cn", response="ed40318d6162ef2a623f8f3049995a99", cnonce="3zQAEkGGvoZhNjcE", nc=00000001, qop=auth
------------------------------------------------------------------------
send 308 bytes to udp/[172.16.100.32]:5060 at 21:54:32.098044:
------------------------------------------------------------------------
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 172.16.100.32:5060;branch=z9hG4bKc54a.a53a6847.0
From: <sip:1002@sofia.superpipi.cn>;tag=0HIj01pcT
To: sip:1004@sofia.superpipi.cn
Call-ID: LJD8EMDXo0
CSeq: 21 INVITE
User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
Content-Length: 0
------------------------------------------------------------------------
send 1427 bytes to udp/[172.16.100.110]:6060 at 21:54:33.154929:
------------------------------------------------------------------------
INVITE sip:1004@172.16.100.110:6060 SIP/2.0
Via: SIP/2.0/UDP 172.16.100.11;rport;branch=z9hG4bKecU1j8vy36H9r
Max-Forwards: 68
From: "Extension 1002" <sip:1002@sofia.superpipi.cn>;tag=v4c83jm6gtF0H
To: <sip:1004@172.16.100.110:6060>
Call-ID: 0a7d51fd-39db-1237-2d8d-000c29916959
CSeq: 128519372 INVITE
Contact: <sip:mod_sofia@172.16.100.11:5060>
User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 455
X-FS-Support: update_display,send_info
Remote-Party-ID: "Extension 1002" <sip:1002@sofia.superpipi.cn>;party=calling;screen=yes;privacy=off
------------------------------------------------------------------------
recv 378 bytes from udp/[172.16.100.110]:6060 at 21:54:33.338614:
------------------------------------------------------------------------
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 172.16.100.11;rport=5060;branch=z9hG4bKecU1j8vy36H9r
From: "Extension 1002" <sip:1002@sofia.superpipi.cn>;tag=v4c83jm6gtF0H
To: <sip:1004@172.16.100.110:6060>
Call-ID: 0a7d51fd-39db-1237-2d8d-000c29916959
CSeq: 128519372 INVITE
Allow: INVITE, ACK, OPTIONS, BYE, CANCEL, REFER, NOTIFY, INFO, PRACK, UPDATE, MESSAGE
Content-Length: 0
------------------------------------------------------------------------
recv 349 bytes from udp/[172.16.100.31]:5062 at 21:54:33.541289:
------------------------------------------------------------------------
OPTIONS sip:172.16.100.11 SIP/2.0
Via: SIP/2.0/UDP 172.16.100.31:5062;branch=z9hG4bKe86c.f1b595f2.0
To: sip:172.16.100.11
From: <sip:dispatcher@localhost>;tag=5f8cfd923bd21a2d7f298654cd327b22-a1e0
CSeq: 14 OPTIONS
Call-ID: 2d922c18059b1ee6-1684@172.16.100.32
Max-Forwards: 70
Content-Length: 0
User-Agent: OpenSIPS (2.4.2 (x86_64/linux))
------------------------------------------------------------------------
send 735 bytes to udp/[172.16.100.31]:5062 at 21:54:33.542155:
------------------------------------------------------------------------
SIP/2.0 200 OK
Via: SIP/2.0/UDP 172.16.100.31:5062;branch=z9hG4bKe86c.f1b595f2.0
From: <sip:dispatcher@localhost>;tag=5f8cfd923bd21a2d7f298654cd327b22-a1e0
To: <sip:172.16.100.11>;tag=XD605D59D35jD
Call-ID: 2d922c18059b1ee6-1684@172.16.100.32
CSeq: 14 OPTIONS
Contact: <sip:172.16.100.11>
User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
Accept: application/sdp
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
Content-Length: 0
------------------------------------------------------------------------
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
五、后记
OpenSIPS通过keepalived进行主备切换高可用,再对FreeSWITCH进行负载均衡的试验算是完成,但还有一些地方需要进一部完善,比如sip消息中的From: <sip:dispatcher@localhost>,还有官方提到的来电的IP地址只能记录到OpenSIPS的IP问题,还有OpenSIPS代理媒体的问题,还有OpenSIPS可用性检测脚本等。
总之,在生产应用FreeSWITCH,高可用方案是必须要考虑的,上一篇折腾笔记已经介绍了通过keepalived进行FreeSWITCH主备切换的高可用,这里再把负载均衡的高可用方式折腾一番。也许你会问:为何不采用官方的”Corosync+Pacemaker“方式进行主备切换的高可用,主要是因为我对keepalived较熟悉一点,同时”keepalived+检测脚本“的切换效率也是很高的。
转载请注明:SuperIT » FreeSWITCH折腾笔记8——使用OpenSIPS进行负载均衡