通过OpenSIPS对FreeSWITCH进行负载均衡网络上的文章很多,但都是基于老版本的OpenSIPS,目前最新的OpenSIPS LTS版是2.4,如果使用老版本配置文件,OpenSIPS是运行不起来(当然通过一番修改后还是可以运行起来的)。笔者经过一番折腾,成功实现了OpenSIPS 2.4版本对FreeSWITCH的负载均衡。

 

一、环境介绍:

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

 

3.1.2、修改keepalived配置:

编辑/etc/keepalived/keepalived.conf,将两个节点分别按以下配置修改。

01节点keepalived配置:

  1.  
    ! Configuration File for keepalived
  2.  
    global_defs {
  3.  
    notification_email {
  4.  
    acassen
  5.  
    }
  6.  
    notification_email_from Alexandre.Cassen@firewall.loc
  7.  
    smtp_server 172.16.100.251
  8.  
    smtp_connect_timeout 30
  9.  
    router_id LVS_DEVEL
  10.  
    }
  11.  
    vrrp_instance VI_1 {
  12.  
    state BACKUP
  13.  
    interface eth0
  14.  
    garp_master_delay 10
  15.  
    smtp_alert
  16.  
    virtual_router_id 53
  17.  
    priority 200
  18.  
    nopreempt
  19.  
    advert_int 1
  20.  
    authentication {
  21.  
    auth_type PASS
  22.  
    auth_pass 915119
  23.  
    }
  24.  
    virtual_ipaddress {
  25.  
    172.16.100.32/24
  26.  
    172.16.100.32/24 label eth0:1
  27.  
    }
  28.  
    }

 

  • 02节点keepalived配置:

  1.  
    ! Configuration File for keepalived
  2.  
    global_defs {
  3.  
    notification_email {
  4.  
    acassen
  5.  
    }
  6.  
    notification_email_from Alexandre.Cassen@firewall.loc
  7.  
    smtp_server 172.16.100.251
  8.  
    smtp_connect_timeout 30
  9.  
    router_id LVS_DEVEL
  10.  
    }
  11.  
    vrrp_instance VI_1 {
  12.  
    state BACKUP
  13.  
    interface eth0
  14.  
    garp_master_delay 10
  15.  
    smtp_alert
  16.  
    virtual_router_id 53
  17.  
    priority 100
  18.  
    advert_int 1
  19.  
    authentication {
  20.  
    auth_type PASS
  21.  
    auth_pass 915119
  22.  
    }
  23.  
    virtual_ipaddress {
  24.  
    172.16.100.32/24
  25.  
    172.16.100.32/24 label eth0:1
  26.  
    }
  27.  
    }

 

3.2、安装和配置OpenSIPS

 

3.2.1、安装OpenSIPS

笔者安装OpenSIPS是通过官方deb包直接安装的,执行步骤如下:

  • 添加源:

  1.  
    apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 049AD65B
  2.  
    echo “deb http://apt.opensips.org jessie 2.4-releases” >/etc/apt/sources.list.d/opensips.list
  • 更新源和安装OpenSIPS

    apt-get update && apt-get install opensips

    3.2.2、配置OpenSIPS

  • 创建数据库

  • 编辑/etc/opensips/opensipsctlrc将以下项去注释并按实际情况修改,或直接通过echo追加到/etc/opensips/opensipsctlrc

     

    1.  
      echo “SIP_DOMAIN=sofia.superpipi.cn” >> /etc/opensips/opensipsctlrc
    2.  
      echo “DBENGINE=MYSQL” >> /etc/opensips/opensipsctlrc
    3.  
      echo “DBPORT=3306” >> /etc/opensips/opensipsctlrc
    4.  
      echo “DBHOST=172.16.100.15” >> /etc/opensips/opensipsctlrc
    5.  
      echo “DBNAME=opensips” >> /etc/opensips/opensipsctlrc
    6.  
      echo “DBRWUSER=opensips” >> /etc/opensips/opensipsctlrc
    7.  
      echo “DBRWPW=”ligen119“” >> /etc/opensips/opensipsctlrc

    执行创建数据库工具(注:如数据库不在本机,需授权root用户远程访问权限

    /usr/sbin/opensipsdbctl create

    运行以上命令后会提示输入root密码,输入root密码后提示输入数据库字符集(吐槽一下不能选utf8),这里输入gbk(后续可能需要存储中文),其后按向导进行数据库创建。

  • 配置启动参数

  • 启动参数编辑不是必须,如果生产应用建议还是将内存参数做相应的扩大。

    编辑/etc/default/opensips将以下项去注释并按实际情况修改,或直接通过echo追加到/etc/default/opensips 

     

    1.  
      echo “RUN_OPENSIPS=yes” >>/etc/default/opensips
    2.  
      echo “USER=opensips” >>/etc/default/opensips
    3.  
      echo “GROUP=opensips” >>/etc/default/opensips
    4.  
      echo “S_MEMORY=512” >>/etc/default/opensips
    5.  
      echo “P_MEMORY=32” >>/etc/default/opensips
    6.  
      echo “DUMP_CORE=yes” >>/etc/default/opensips

     

  • 配置文件

  • 编辑/etc/opensips/opensips.cfg,清空原配置文件,将以下内容插入配置文件。(本配置文件基本是参考freeswitch官方wiki的配置文件

    1.  
      log_level=1 #老版本日志级别参数为debug,级别范围1-4,建议生产上设置为1,为3或者4时将产生大量日志,磁盘空间很快就不够了
    2.  
      sip_warning=0
    3.  
      log_stderror=no
    4.  
      log_facility=LOG_LOCAL0
    5.  
      log_name=“opensips”
    6.  
      debug_mode=no
    7.  
      children=4
    8.  
      dns_try_ipv6=no
    9.  
      auto_aliases=no
    10.  
      listen=udp:172.16.100.30:5062 #另外一个节点设置为udp:172.16.100.31:5062,取本地IP,不添加该监听项则备用节点无法与负载节点握手,导致备用节点将调度列表的负载节点设置为不可用
    11.  
      listen=udp:172.16.100.32:5060
    12.  
      mpath=“/usr/lib/x86_64-linux-gnu/opensips/modules/”
    13.  
       
    14.  
      loadmodule “db_mysql.so”
    15.  
      loadmodule “signaling.so”
    16.  
      loadmodule “sl.so”
    17.  
      loadmodule “tm.so”
    18.  
      loadmodule “rr.so”
    19.  
      loadmodule “uri.so”
    20.  
      loadmodule “dialog.so”
    21.  
      loadmodule “maxfwd.so”
    22.  
      loadmodule “textops.so”
    23.  
      loadmodule “mi_fifo.so”
    24.  
      loadmodule “dispatcher.so”
    25.  
      loadmodule “load_balancer.so”
    26.  
      loadmodule “sipmsgops.so”
    27.  
      loadmodule “proto_udp.so”
    28.  
      modparam(“mi_fifo”, “fifo_name”, “/tmp/opensips_fifo”)
    29.  
      modparam(“dialog”, “db_mode”, 1)
    30.  
      modparam(“dialog”, “db_url”, “mysql://opensips:ligen119@172.16.100.15/opensips”)
    31.  
      modparam(“rr”, “enable_double_rr”, 1)
    32.  
      modparam(“rr”, “append_fromtag”, 1)
    33.  
      modparam(“tm”, “fr_timer”, 2)
    34.  
      modparam(“dispatcher”, “db_url”, “mysql://opensips:ligen119@172.16.100.15/opensips”)
    35.  
      modparam(“dispatcher”, “ds_ping_method”, “OPTIONS”)
    36.  
      modparam(“dispatcher”, “ds_ping_interval”, 5)
    37.  
      modparam(“dispatcher”, “ds_probing_threshhold”, 2)
    38.  
      modparam(“dispatcher”, “ds_probing_mode”, 1)
    39.  
      modparam(“load_balancer”, “db_url”, “mysql://opensips:ligen119@172.16.100.15/opensips”)
    40.  
      modparam(“load_balancer”, “probing_method”, “OPTIONS”)
    41.  
      modparam(“load_balancer”, “probing_interval”, 5)
    42.  
      route{
    43.  
       
    44.  
      if (!mf_process_maxfwd_header(“10”)) {
    45.  
      sl_send_reply(“483”,“Too Many Hops”);
    46.  
      exit;
    47.  
      }
    48.  
       
    49.  
      if (!has_totag()) {
    50.  
      record_route();
    51.  
      }
    52.  
      else {
    53.  
      loose_route();
    54.  
      t_relay();
    55.  
      exit;
    56.  
      }
    57.  
      if (is_method(“CANCEL”)) {
    58.  
      if ( t_check_trans() )
    59.  
      t_relay();
    60.  
      exit;
    61.  
      }
    62.  
      if (is_method(“INVITE”)) {
    63.  
      if (!load_balance(“1”,“pstn”,“1”)) {
    64.  
      send_reply(“503”,“Service Unavailable”);
    65.  
      exit;
    66.  
      }
    67.  
      }
    68.  
      else if (is_method(“REGISTER”)) {
    69.  
      if (!ds_select_dst(“1”, “4”)) {
    70.  
      send_reply(“503”,“Service Unavailable”);
    71.  
      exit;
    72.  
      }
    73.  
      }
    74.  
      else {
    75.  
      send_reply(“405”,“Method Not Allowed”);
    76.  
      exit;
    77.  
      }
    78.  
      if (!t_relay()) {
    79.  
      sl_reply_error();
    80.  
      }
    81.  
      }

     

    添加负载节点

在数据库添加两个负载节点信息

  1.  
    INSERT INTO `opensips`.`load_balancer` (`id`, `group_id`, `dst_uri`, `resources`, `probe_mode`, `description`) VALUES (‘1’, ‘1’, ‘sip:172.16.100.10’, ‘vm=100;conf=100;transc=100;pstn=500’, ‘1’, ‘FS1’);
  2.  
    INSERT INTO `opensips`.`load_balancer` (`id`, `group_id`, `dst_uri`, `resources`, `probe_mode`, `description`) VALUES (‘2’, ‘1’, ‘sip:172.16.100.11’, ‘vm=100;conf=100;transc=100;pstn=500’, ‘1’, ‘FS2’);
  • 允许绑定非本机IP

执行以下命令使OpenSIPS能监听在本机IP,当VIP飘过来时OpenSIPS服务即可用

echo 'net.ipv4.ip_nonlocal_bind=1' >> /etc/sysctl.conf
  • 将日志输出到指定文件

在/etc/rsyslog.conf追加keepalived和OpenSIPS日志输出配置。(注:OpenSIPS配置文件中log_stderror和debug_mode需设置成no,否则可能不能输出单独日志

  1.  
    echo “local0.* /var/log/opensips.log” >>/etc/rsyslog.conf
  2.  
    echo “local1.* /var/log/keepalived.log” >>/etc/rsyslog.conf

3.2.3、开始OpenSIPS

  • 重启rsyslog、keepalived、OpenSIPS

  1.  
    service rsyslog restart
  2.  
    service keepalived restart
  3.  
    service opensips restart
  • 添加FreeSWITCH到调度列表

执行以下命令将两个节点添加到调度列表,(这里添加调度器的命令和1.7版本是有区别的

 

  1.  
    opensipsctl dispatcher addgw 1 sip:172.16.100.10 5060 0 50 ‘FS1′ ‘节点1′
  2.  
    opensipsctl dispatcher addgw 1 sip:172.16.100.11 5060 0 50 ‘FS2′ ‘节点2′

添加调度列表成功后,在两个FreeSWITCH的控制通过sofia profile sofia.superpipi.cn siptrace on命令打开sip消息跟踪即可看到两个OpenSIPS节点不停在跟FreeSWITCH通过”OPTIONS“消息进行握手,如下:

 

  1.  
    ————————————————————————
  2.  
    recv 349 bytes from udp/[172.16.100.31]:5062 at 21:41:43.502417:
  3.  
    ————————————————————————
  4.  
    OPTIONS sip:172.16.100.10 SIP/2.0
  5.  
    Via: SIP/2.0/UDP 172.16.100.31:5062;branch=z9hG4bK2fe7.7ea62cf7.0
  6.  
    To: sip:172.16.100.10
  7.  
    From: <sip:dispatcher@localhost>;tag=5f8cfd923bd21a2d7f298654cd327b22-8a62
  8.  
    CSeq: 14 OPTIONS
  9.  
    Call-ID: 2d922c18059b1edd-1681@172.16.100.31
  10.  
    Max-Forwards: 70
  11.  
    Content-Length: 0
  12.  
    User-Agent: OpenSIPS (2.4.2 (x86_64/linux))
  13.  
     
  14.  
    ————————————————————————
  15.  
    send 735 bytes to udp/[172.16.100.31]:5062 at 21:41:43.503285:
  16.  
    ————————————————————————
  17.  
    SIP/2.0 200 OK
  18.  
    Via: SIP/2.0/UDP 172.16.100.31:5062;branch=z9hG4bK2fe7.7ea62cf7.0
  19.  
    From: <sip:dispatcher@localhost>;tag=5f8cfd923bd21a2d7f298654cd327b22-8a62
  20.  
    To: <sip:172.16.100.10>;tag=t2y6pUXm66tQH
  21.  
    Call-ID: 2d922c18059b1edd-1681@172.16.100.31
  22.  
    CSeq: 14 OPTIONS
  23.  
    Contact: <sip:172.16.100.10>
  24.  
    User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
  25.  
    Accept: application/sdp
  26.  
    Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
  27.  
    Supported: timer, path, replaces
  28.  
    Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
  29.  
    Content-Length: 0
  30.  
     
  31.  
    ————————————————————————
  32.  
    recv 349 bytes from udp/[172.16.100.30]:5062 at 21:41:45.769168:
  33.  
    ————————————————————————
  34.  
    OPTIONS sip:172.16.100.10 SIP/2.0
  35.  
    Via: SIP/2.0/UDP 172.16.100.30:5062;branch=z9hG4bKbace.ec1b06f.0
  36.  
    To: sip:172.16.100.10
  37.  
    From: <sip:dispatcher@localhost>;tag=45af385df62c8fa46b1bdd54b7adb556-4f80
  38.  
    CSeq: 14 OPTIONS
  39.  
    Call-ID: 735a40b173b81153-37063@172.16.100.32
  40.  
    Max-Forwards: 70
  41.  
    Content-Length: 0
  42.  
    User-Agent: OpenSIPS (2.4.2 (x86_64/linux))
  43.  
     
  44.  
    ————————————————————————
  45.  
    send 735 bytes to udp/[172.16.100.30]:5062 at 21:41:45.770861:
  46.  
    ————————————————————————
  47.  
    SIP/2.0 200 OK
  48.  
    Via: SIP/2.0/UDP 172.16.100.30:5062;branch=z9hG4bKbace.ec1b06f.0
  49.  
    From: <sip:dispatcher@localhost>;tag=45af385df62c8fa46b1bdd54b7adb556-4f80
  50.  
    To: <sip:172.16.100.10>;tag=UBrZrper3FHaD
  51.  
    Call-ID: 735a40b173b81153-37063@172.16.100.32
  52.  
    CSeq: 14 OPTIONS
  53.  
    Contact: <sip:172.16.100.10>
  54.  
    User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
  55.  
    Accept: application/sdp
  56.  
    Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
  57.  
    Supported: timer, path, replaces
  58.  
    Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
  59.  
    Content-Length: 0
  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"/>

修改后需重启FreeSWITCH才能生效

4.2、注册验证

笔者分别使用eyeBeam、Linphone、eSpace SoftPhone三种软电话和一个Fanvil X5硬电话进行注册测试,均可注册成功。

在freeswitch所在服务器执行fs_cli -x “sofia status profile sofia.superpipi.cn reg”

结果如下:

 

  1.  
    root@debian:~# fs_cli -x “sofia status profile sofia.superpipi.cn reg”
  2.  
    Registrations:
  3.  
    =================================================================================================
  4.  
    Call-ID: 19024618511954-772266364347@172.16.100.110
  5.  
    User: 1004@sofia.superpipi.cn
  6.  
    Contact: “1004” <sip:1004@172.16.100.110:6060>
  7.  
    Agent: Fanvil X5 1.3.256.1566
  8.  
    Status: Registered(UDP)(unknown) EXP(2018-09-23 22:14:29) EXPSECS(2228)
  9.  
    Ping-Status: Reachable
  10.  
    Ping-Time: 0.00
  11.  
    Host: debian
  12.  
    IP: 172.16.100.32
  13.  
    Port: 5060
  14.  
    Auth-User: 1004
  15.  
    Auth-Realm: sofia.superpipi.cn
  16.  
    MWI-Account: 1004@sofia.superpipi.cn
  17.  
    Call-ID: YTFjZjBmZDZjNWEyZGQwNTgxMTEzZDcwMTAwNDdiZDQ.
  18.  
    User: 1000@sofia.superpipi.cn
  19.  
    Contact: “1000” <sip:1000@172.16.100.251:51540;rinstance=f8dca36459b0bdec>
  20.  
    Agent: eyeBeam release 1011d stamp 40820
  21.  
    Status: Registered(UDP)(unknown) EXP(2018-09-23 22:35:27) EXPSECS(3486)
  22.  
    Ping-Status: Reachable
  23.  
    Ping-Time: 0.00
  24.  
    Host: debian
  25.  
    IP: 172.16.100.32
  26.  
    Port: 5060
  27.  
    Auth-User: 1000
  28.  
    Auth-Realm: sofia.superpipi.cn
  29.  
    MWI-Account: 1000@sofia.superpipi.cn
  30.  
    Call-ID: SdnqWECcxy
  31.  
    User: 1002@sofia.superpipi.cn
  32.  
    Contact: “” <sip:1002@172.16.100.251:64242;transport=udp>
  33.  
    Agent: Linphone Desktop/4.1.1 (belle-sip/1.6.3)
  34.  
    Status: Registered(UDP)(unknown) EXP(2018-09-23 21:47:38) EXPSECS(617)
  35.  
    Ping-Status: Reachable
  36.  
    Ping-Time: 0.00
  37.  
    Host: debian
  38.  
    IP: 172.16.100.32
  39.  
    Port: 5060
  40.  
    Auth-User: 1002
  41.  
    Auth-Realm: sofia.superpipi.cn
  42.  
    MWI-Account: 1002@sofia.superpipi.cn
  43.  
    Call-ID: NzBhNzg3NTY2NWExZmE0M2ZiODdlZGIwYmY1NGVmY2Y.
  44.  
    User: 1003@sofia.superpipi.cn
  45.  
    Contact: “” <sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c>
  46.  
    Agent: HUAWEI OpenEye v3.1
  47.  
    Status: Registered(UDP)(unknown) EXP(2018-09-23 21:42:52) EXPSECS(331)
  48.  
    Ping-Status: Reachable
  49.  
    Ping-Time: 0.00
  50.  
    Host: debian
  51.  
    IP: 172.16.100.32
  52.  
    Port: 5060
  53.  
    Auth-User: 1003
  54.  
    Auth-Realm: sofia.superpipi.cn
  55.  
    MWI-Account: 1003@sofia.superpipi.cn
  56.  
    Total items returned: 4
  57.  
    =================================================================================================

 

4.3、通话验证

  • 使用分机1000拨通1003

172.16.100.10(FS1)节点收到分机1000发来的”INVITE”消息,并向分机1003发起”INVITE”消息,消息跟踪如下(注:删除了SDP和省略部分消息):

 

  1.  
    recv 1431 bytes from udp/[172.16.100.32]:5060 at 21:48:29.481716:
  2.  
    ————————————————————————
  3.  
    INVITE sip:1003@sofia.superpipi.cn SIP/2.0
  4.  
    Record-Route: <sip:172.16.100.32;lr;ftag=f104f441;did=83f.44ccd293>
  5.  
    Via: SIP/2.0/UDP 172.16.100.32:5060;branch=z9hG4bKc6fd.c55828d7.0
  6.  
    Via: SIP/2.0/UDP 172.16.100.251:51540;received=172.16.100.251;branch=z9hG4bK-d87543-8651904ed85c056f-1–d87543-;rport=51540
  7.  
    Max-Forwards: 69
  8.  
    Contact: <sip:1000@172.16.100.251:51540>
  9.  
    To: “1003”<sip:1003@sofia.superpipi.cn>
  10.  
    From: “1000”<sip:1000@sofia.superpipi.cn>;tag=f104f441
  11.  
    Call-ID: NDkyOTM1YWI4YzhiMGY4MWI0ZDMwYmQzNThjYjE2NzQ.
  12.  
    CSeq: 2 INVITE
  13.  
    Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO
  14.  
    Content-Type: application/sdp
  15.  
    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
  16.  
    User-Agent: eyeBeam release 1011d stamp 40820
  17.  
    Content-Length: 442
  18.  
     
  19.  
    ————————————————————————
  20.  
    send 354 bytes to udp/[172.16.100.32]:5060 at 21:48:29.502215:
  21.  
    ————————————————————————
  22.  
    SIP/2.0 100 Trying
  23.  
    Via: SIP/2.0/UDP 172.16.100.32:5060;branch=z9hG4bKc6fd.c55828d7.0
  24.  
    From: “1000”<sip:1000@sofia.superpipi.cn>;tag=f104f441
  25.  
    To: “1003”<sip:1003@sofia.superpipi.cn>
  26.  
    Call-ID: NDkyOTM1YWI4YzhiMGY4MWI0ZDMwYmQzNThjYjE2NzQ.
  27.  
    CSeq: 2 INVITE
  28.  
    User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
  29.  
    Content-Length: 0
  30.  
     
  31.  
    ————————————————————————
  32.  
    send 1272 bytes to udp/[172.16.100.251]:5060 at 21:48:30.575115:
  33.  
    ————————————————————————
  34.  
    INVITE sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c SIP/2.0
  35.  
    Via: SIP/2.0/UDP 172.16.100.10;rport;branch=z9hG4bKg7X53ye14956r
  36.  
    Max-Forwards: 68
  37.  
    From: “Extension 1000” <sip:1000@sofia.superpipi.cn>;tag=9e7rDt1XcyNZc
  38.  
    To: <sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c>
  39.  
    Call-ID: 326006cf-39da-1237-4983-000c2953a0b0
  40.  
    CSeq: 128519191 INVITE
  41.  
    Contact: <sip:mod_sofia@172.16.100.10:5060>
  42.  
    User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
  43.  
    Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
  44.  
    Supported: timer, path, replaces
  45.  
    Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
  46.  
    Content-Type: application/sdp
  47.  
    Content-Disposition: session
  48.  
    Content-Length: 246
  49.  
    X-FS-Support: update_display,send_info
  50.  
    Remote-Party-ID: “Extension 1000” <sip:1000@sofia.superpipi.cn>;party=calling;screen=yes;privacy=off
  51.  
     
  52.  
    ————————————————————————
  53.  
    recv 318 bytes from udp/[172.16.100.251]:5060 at 21:48:30.634089:
  54.  
    ————————————————————————
  55.  
    SIP/2.0 100 Trying
  56.  
    Via: SIP/2.0/UDP 172.16.100.10;rport=5060;branch=z9hG4bKg7X53ye14956r
  57.  
    To: <sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c>
  58.  
    From: “Extension 1000” <sip:1000@sofia.superpipi.cn>;tag=9e7rDt1XcyNZc
  59.  
    Call-ID: 326006cf-39da-1237-4983-000c2953a0b0
  60.  
    CSeq: 128519191 INVITE
  61.  
    Content-Length: 0
  62.  
     
  63.  
    ————————————————————————
  64.  
    recv 399 bytes from udp/[172.16.100.251]:5060 at 21:48:30.634221:
  65.  
    ————————————————————————
  66.  
    SIP/2.0 180 Ringing
  67.  
    Via: SIP/2.0/UDP 172.16.100.10;rport=5060;branch=z9hG4bKg7X53ye14956r
  68.  
    Contact: <sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c>
  69.  
    To: <sip:1003@172.16.100.251:5060;rinstance=b0fff9289f8fbf0c>;tag=77eb678a
  70.  
    From: “Extension 1000”<sip:1000@sofia.superpipi.cn>;tag=9e7rDt1XcyNZc
  71.  
    Call-ID: 326006cf-39da-1237-4983-000c2953a0b0
  72.  
    CSeq: 128519191 INVITE
  73.  
    Content-Length: 0
  74.  
    ————————————————————————
  • 使用分机1002拨打1004

在1000与1003通话状态下,使用分机1002拨打1004,172.16.100.11(FS2)节点收到分机1002发来的”INVITE”消息,并向分机1004发起”INVITE”消息,消息跟踪如下(注:删除了SDP和省略部分消息):

  1.  
    recv 1935 bytes from udp/[172.16.100.32]:5060 at 21:54:32.072291:
  2.  
    ————————————————————————
  3.  
    INVITE sip:1004@sofia.superpipi.cn SIP/2.0
  4.  
    Record-Route: <sip:172.16.100.32;lr;ftag=0HIj01pcT;did=cdf.8df222c6>
  5.  
    Via: SIP/2.0/UDP 172.16.100.32:5060;branch=z9hG4bKc54a.a53a6847.0
  6.  
    Via: SIP/2.0/UDP 172.16.100.251:64242;received=172.16.100.251;branch=z9hG4bK.m5Jiasf70;rport=64242
  7.  
    From: <sip:1002@sofia.superpipi.cn>;tag=0HIj01pcT
  8.  
    To: sip:1004@sofia.superpipi.cn
  9.  
    CSeq: 21 INVITE
  10.  
    Call-ID: LJD8EMDXo0
  11.  
    Max-Forwards: 69
  12.  
    Supported: replaces, outbound
  13.  
    Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, UPDATE
  14.  
    Content-Type: application/sdp
  15.  
    Content-Length: 898
  16.  
    Contact: <sip:1002@172.16.100.251:64242;transport=udp>;+sip.instance=”<urn:uuid:bcb91990-4d9b-47ea-8ba8-3af172d27fce>”
  17.  
    User-Agent: Linphone Desktop/4.1.1 (belle-sip/1.6.3)
  18.  
    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
  19.  
    ————————————————————————
  20.  
    send 308 bytes to udp/[172.16.100.32]:5060 at 21:54:32.098044:
  21.  
    ————————————————————————
  22.  
    SIP/2.0 100 Trying
  23.  
    Via: SIP/2.0/UDP 172.16.100.32:5060;branch=z9hG4bKc54a.a53a6847.0
  24.  
    From: <sip:1002@sofia.superpipi.cn>;tag=0HIj01pcT
  25.  
    To: sip:1004@sofia.superpipi.cn
  26.  
    Call-ID: LJD8EMDXo0
  27.  
    CSeq: 21 INVITE
  28.  
    User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
  29.  
    Content-Length: 0
  30.  
     
  31.  
    ————————————————————————
  32.  
    send 1427 bytes to udp/[172.16.100.110]:6060 at 21:54:33.154929:
  33.  
    ————————————————————————
  34.  
    INVITE sip:1004@172.16.100.110:6060 SIP/2.0
  35.  
    Via: SIP/2.0/UDP 172.16.100.11;rport;branch=z9hG4bKecU1j8vy36H9r
  36.  
    Max-Forwards: 68
  37.  
    From: “Extension 1002” <sip:1002@sofia.superpipi.cn>;tag=v4c83jm6gtF0H
  38.  
    To: <sip:1004@172.16.100.110:6060>
  39.  
    Call-ID: 0a7d51fd-39db-1237-2d8d-000c29916959
  40.  
    CSeq: 128519372 INVITE
  41.  
    Contact: <sip:mod_sofia@172.16.100.11:5060>
  42.  
    User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
  43.  
    Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
  44.  
    Supported: timer, path, replaces
  45.  
    Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
  46.  
    Content-Type: application/sdp
  47.  
    Content-Disposition: session
  48.  
    Content-Length: 455
  49.  
    X-FS-Support: update_display,send_info
  50.  
    Remote-Party-ID: “Extension 1002” <sip:1002@sofia.superpipi.cn>;party=calling;screen=yes;privacy=off
  51.  
    ————————————————————————
  52.  
    recv 378 bytes from udp/[172.16.100.110]:6060 at 21:54:33.338614:
  53.  
    ————————————————————————
  54.  
    SIP/2.0 100 Trying
  55.  
    Via: SIP/2.0/UDP 172.16.100.11;rport=5060;branch=z9hG4bKecU1j8vy36H9r
  56.  
    From: “Extension 1002” <sip:1002@sofia.superpipi.cn>;tag=v4c83jm6gtF0H
  57.  
    To: <sip:1004@172.16.100.110:6060>
  58.  
    Call-ID: 0a7d51fd-39db-1237-2d8d-000c29916959
  59.  
    CSeq: 128519372 INVITE
  60.  
    Allow: INVITE, ACK, OPTIONS, BYE, CANCEL, REFER, NOTIFY, INFO, PRACK, UPDATE, MESSAGE
  61.  
    Content-Length: 0
  62.  
     
  63.  
    ————————————————————————
  64.  
    recv 349 bytes from udp/[172.16.100.31]:5062 at 21:54:33.541289:
  65.  
    ————————————————————————
  66.  
    OPTIONS sip:172.16.100.11 SIP/2.0
  67.  
    Via: SIP/2.0/UDP 172.16.100.31:5062;branch=z9hG4bKe86c.f1b595f2.0
  68.  
    To: sip:172.16.100.11
  69.  
    From: <sip:dispatcher@localhost>;tag=5f8cfd923bd21a2d7f298654cd327b22-a1e0
  70.  
    CSeq: 14 OPTIONS
  71.  
    Call-ID: 2d922c18059b1ee6-1684@172.16.100.32
  72.  
    Max-Forwards: 70
  73.  
    Content-Length: 0
  74.  
    User-Agent: OpenSIPS (2.4.2 (x86_64/linux))
  75.  
     
  76.  
    ————————————————————————
  77.  
    send 735 bytes to udp/[172.16.100.31]:5062 at 21:54:33.542155:
  78.  
    ————————————————————————
  79.  
    SIP/2.0 200 OK
  80.  
    Via: SIP/2.0/UDP 172.16.100.31:5062;branch=z9hG4bKe86c.f1b595f2.0
  81.  
    From: <sip:dispatcher@localhost>;tag=5f8cfd923bd21a2d7f298654cd327b22-a1e0
  82.  
    To: <sip:172.16.100.11>;tag=XD605D59D35jD
  83.  
    Call-ID: 2d922c18059b1ee6-1684@172.16.100.32
  84.  
    CSeq: 14 OPTIONS
  85.  
    Contact: <sip:172.16.100.11>
  86.  
    User-Agent: FreeSWITCH-mod_sofia/1.8.1+git~20180724×××60524Z~b33bc925c5~64bit
  87.  
    Accept: application/sdp
  88.  
    Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY, PUBLISH, SUBSCRIBE
  89.  
    Supported: timer, path, replaces
  90.  
    Allow-Events: talk, hold, conference, presence, as-feature-event, dialog, line-seize, call-info, sla, include-session-description, presence.winfo, message-summary, refer
  91.  
    Content-Length: 0
  92.  
     
  93.  
    ————————————————————————

 

五、后记

OpenSIPS通过keepalived进行主备切换高可用,再对FreeSWITCH进行负载均衡的试验算是完成,但还有一些地方需要进一部完善,比如sip消息中的From: <sip:dispatcher@localhost>,还有官方提到的来电的IP地址只能记录到OpenSIPS的IP问题,还有OpenSIPS代理媒体的问题,还有OpenSIPS可用性检测脚本等。

总之,在生产应用FreeSWITCH,高可用方案是必须要考虑的,上一篇折腾笔记已经介绍了通过keepalived进行FreeSWITCH主备切换的高可用,这里再把负载均衡的高可用方式折腾一番。也许你会问:为何不采用官方的”Corosync+Pacemaker“方式进行主备切换的高可用,主要是因为我对keepalived较熟悉一点,同时”keepalived+检测脚本“的切换效率也是很高的。