freeswitch-1.10.1负载均衡之opensips-2.4.6

1. 安装mysql依赖库
    apt-get install libmysql++-dev

2. 下载openSIPS
    https://opensips.org/pub/opensips/2.4.6/opensips-2.4.6.tar.gz

3. 编译及安装openSIPS
    make all include_modules="db_mysql"
    make include_modules="db_mysql" prefix=/opt/opensips install

4. 修改opensipsctlrc
    DBENGINE=MYSQL
    DBPORT=3306
    DBHOST=192.168.129.172
    DBNAME=opensips
    DBRWUSER=opensips   ——对于mysql-5.7.X,该值可以是opensips;但mysql-8.x版本需要在mysql中创建相应的用户才可,该处用户为myroot
    DBRWPW="gs123456" —— opensips数据库的密码
    DBROOTUSER="myroot"

5. 创建openSIPS数据库
    opensipsdbctl create

6. 配置呼叫负载均衡
    /*!
        probe_mode该字段启动负载均衡服务器的保活功能,如果其中一个进行宕机,则opensips不会再向其路由呼叫
        vm:表示最大支持100路VoiceMail
        conf:表示最大支持100路会议室
        transc:表示最大支持100路转码
        pstn:表示最大支持500路普通呼叫(PSTN呼叫)
    */
    insert into load_balancer (group_id, dst_uri, resources, probe_mode, description) values (1,'sip:192.168.129.8', 'vm=100;conf=100;transc=100;pstn=500', 2, 'FS1');
    insert into load_balancer (group_id, dst_uri, resources, probe_mode, description) values (1,'sip:192.168.129.164', 'vm=100;conf=100;transc=100;pstn=500', 2, 'FS2');
 

7. 编辑配置文件opensips.cfg
    log_level=0
    log_stderror=no
    log_facility=LOG_LOCAL0

    children=1

    children=4

    dns_try_ipv6=no

    auto_aliases=no

    listen=udp:192.168.129.124:5060

    ####### Modules Section ########
    mpath="/opt/opensips/lib64/opensips/modules/"

    ## connect mysql database ## 
    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 "proto_udp.so"

    ## load balancer register request ##
    loadmodule "dispatcher.so"

    ## load balancer call(invite) ##
    loadmodule "load_balancer.so"

    loadmodule "sipmsgops.so"

    # ----------------- setting module-specific parameters ---------------

    modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
    modparam("mi_fifo", "fifo_mode", 0666)

    modparam("dialog", "db_mode", 1)
    modparam("dialog", "db_url", "mysql://opensips:[email protected]/opensips")

    modparam("rr", "enable_double_rr", 1)
    modparam("rr", "append_fromtag", 1)

    modparam("tm", "fr_timer", 2)
    modparam("dispatcher", "db_url", "mysql://opensips:[email protected]/opensips")

    # modparam("dispatcher", "ds_ping_method", "OPTIONS")
    # modparam("dispatcher", "ds_ping_interval", 60)
    # modparam("dispatcher", "ds_probing_threshhold", 2)
    # modparam("dispatcher", "ds_probing_mode", 1)

    ####### keepalive for load balancer destination, options or info etc. ######
    modparam("load_balancer", "probing_interval", 5)
    modparam("load_balancer", "probing_method", "OPTIONS")
    modparam("load_balancer", "db_url", "mysql://opensips:[email protected]/opensips")

    ####### Routing Logic ########
    route {
        if (!mf_process_maxfwd_header("10")) {
            sl_send_reply("483","Too Many Hops");
            exit;
        }

        if (!has_totag()) {
            # initial request
            record_route();
        } else {
            # sequential request - obey the indicated route
            loose_route();
            t_relay();
            exit;
        }

        # handle cancel and re-transmissions
        if (is_method("CANCEL")) {
            if (t_check_trans())
                t_relay();
            exit;
        }

        # from now on we have only the initial requests

        # select the node that'll handle the call (load balanced)
        # the method used is different for invite/register requests
        # unknown methods are rejected here
        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;
        }

        # route the request
        if (!t_relay()) {
            sl_reply_error();
        }
    }

8. 配置dispatcher(register)路由表
    opensipsctl dispatcher addgw 1 sip:192.168.129.8 '' 0 'FS1' 'Outbound Gateway1'
    opensipsctl dispatcher addgw 1 sip:192.168.129.164 '' 0 'FS2' 'Outbound Gateway2'

9. openSIPS LB控制命令opensipsctl
    opensipsctl fifo lb_list   ——列出当前opensips LB状态信息
    opensipsctl fifo lb_reload ——重载opensips LB配置信息

 

注:此处笔者在Windows上使用的MySQL为:mysql-5.7.28-winx64,具体安装过程可参考:https://blog.csdn.net/xie__peng/article/details/103191116

 

你可能感兴趣的:(freeswitch)