0、安装
(1)安装rtpproxy
yum install rtpproxy
使用:
rtpproxy -A 172.29.50.9 -F -l 192.168.1.100 -m 32004 -M 40000 -s udp:192.168.1.100:1111 -d DBUG LOG_LOCAL解释:
rtpproxy启动
./rtpproxy -A 110.172.192.68 -l 0.0.0.0 -s udp:localhost:7890 -n tcp:localhost:7890 -F -d DBUG -m 50002 -M 50020 -d log_level:log_facility
参数解释如下:
-A 本机外网地址
-l 本机内网侦听地址
-s 本机侦听opensips通知端口
-n 超时通知接收端口
-F 不检查是否为超级用户模式
-d 调试消息输出级别
-m rtp最小端口
-M rtp最大端口
-d log_level为日志级别,值如下
DBUG INFO WARN ERR CRIT
log_facility为日志输出到哪,利用的系统日志
{"LOG_AUTH", LOG_AUTH},
{"LOG_CRON", LOG_CRON},
{"LOG_DAEMON", LOG_DAEMON},
{"LOG_KERN", LOG_KERN},
{"LOG_LOCAL0", LOG_LOCAL0},
{"LOG_LOCAL1", LOG_LOCAL1},
{"LOG_LOCAL2", LOG_LOCAL2},
{"LOG_LOCAL3", LOG_LOCAL3},
{"LOG_LOCAL4", LOG_LOCAL4},
{"LOG_LOCAL5", LOG_LOCAL5},
{"LOG_LOCAL6", LOG_LOCAL6},
{"LOG_LOCAL7", LOG_LOCAL7},
{"LOG_LPR", LOG_LPR},
{"LOG_MAIL", LOG_MAIL},
{"LOG_NEWS", LOG_NEWS},
{"LOG_USER", LOG_USER},
{"LOG_UUCP", LOG_UUCP},
#if !defined(__solaris__) && !defined(__sun) && !defined(__svr4__)
{"LOG_AUTHPRIV", LOG_AUTHPRIV},
{"LOG_FTP", LOG_FTP},
{"LOG_SYSLOG", LOG_SYSLOG},
#endif
{NULL, 0}
(2)安装mediaproxy
wget http://download.ag-projects.com/MediaProxy/mediaproxy-2.6.1.tar.gz
tar -xzvf mediaproxy-2.6.1.tar.gz
./setup.py install
开启:
iptables -I INPUT -p udp --dport 5060 -j ACCEPT
media-dispatcher start
media-relay start
#在启动的时候一定要观察/var/log/messages
具体配置参考:
yum -y install gcc gcc-c++ libgpg-error-devel python-devel libgcrypt-devel python-setuptools
rpm -ivh libnfnetlink-0.0.40-1.el5.rf.x86_64.rpm
rpm -ivh libnfnetlink-devel-0.0.40-1.el5.rf.x86_64.rpm
rpm -ivh libnetfilter_conntrack-0.0.97-1.el5.rf.x86_64.rpm
rpm -ivh libnetfilter_conntrack-devel-0.0.97-1.el5.rf.x86_64.rpm
tar jxf gnutls-2.4.2. tar .bz2
cd gnutls-2.4.2
. /configure --with-included-libtasn1 --libdir= /usr/local/lib64/
make
make install
ln -s /usr/local/lib64/libgnutl * /usr/lib64/
ln -s /usr/lib64/libgcrypt .11 /usr/lib64/libgcrypt .11.2.2
ln -s /usr/lib64/libgcrypt .11 /usr/lib64/libgcrypt .11.2.3
cd
tar zxf ctypes-1.0.2. tar .gz
cd ctypes-1.0.2
. /setup .py build
. /setup .py install
cd
tar zxf python-application-1.1.5. tar .gz
cd python-application-1.1.5
. /setup .py build
. /setup .py install
cd
tar zxf python-cjson-1.0.5. tar .gz
cd python-cjson-1.0.5
. /setup .py build
. /setup .py install
cd
tar zxf python-gnutls-1.1.9. tar .gz
cd python-gnutls-1.1.9
. /setup .py build
. /setup .py install
cd
rpm -ivh python-zopeinterface-3.3.0-114.2.x86_64.rpm
tar jxf Twisted-8.1.0. tar .bz2
cd Twisted-8.1.0
. /setup .py build
. /setup .py install
cd
tar zxf mediaproxy-2.4.4. tar .gz
cd mediaproxy-2.4.4
. /setup .py build
. /setup .py install
cd
mkdir /etc/mediaproxy
mkdir -p /var/run/opensips/
mkdir -p /var/run/mediaproxy
cp /root/mediaproxy-2 .4.4 /config .ini.sample /etc/mediaproxy/config .ini
cp -rf /root/mediaproxy-2 .4.4 /tls/ /etc/mediaproxy/
开启ip_forward
sed -i 's#net.ipv4.ip_forward = 0#net.ipv4.ip_forward = 1#g' /etc/sysctl .conf
sysctl -p
config.ini
[Relay]
dispatchers = 192.168.88.245
passport = None
relay_ip = 192.168.88.245
port_range = 50000:60000
log_level = DEBUG
on_hold_timeout = 1800
[Dispatcher]
socket_path = dispatcher.sock
listen = 192.168.88.245
listen_management = 192.168.88.245
management_use_tls = no
passport = None
management_passport = None
log_level = DEBUG
[TLS]
[Database]
[Radius]
[OpenSIPS]
socket_path = /var/run/opensips/socket
max_connections = 10
https://blog.csdn.net/weixin_33895695/article/details/89830764
(3)安装opensips
参考:
https://yum.opensips.org/packages.php?v=2.4
https://yum.opensips.org/2.4/releases/el/7/x86_64/
yum install https://yum.opensips.org/2.4/releases/el/7/x86_64/opensips-yum-releases-2.4-6.el7.noarch.rpm
yum install opensips
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
yum install opensips-db_mysql
yum install opensips-db_unixodbc
yum install opensips-regex
yum install opensips-httpd
yum install opensips-mi_xmlrpc
yum -y install opensips-proto_ws opensips-proto_wss
yum install opensips-pua*
yum install opensips-presence*
yum install opensips-json*
1、只在内网负载均衡
####### Global Parameters #########
log_level=4
log_stderror=no
log_facility=LOG_LOCAL0
children=4
/* uncomment the following lines to enable debugging */
debug_mode=no
/* uncomment the next line to enable the auto temporary blacklisting of
not available destinations (default disabled) */
#disable_dns_blacklist=no
/* uncomment the next line to enable IPv6 lookup after IPv4 dns
lookup failures (default disabled) */
#dns_try_ipv6=yes
/* comment the next line to enable the auto discovery of local aliases
based on revers DNS on IPs */
auto_aliases=yes
listen=udp:192.168.1.100:5060
####### Modules Section ########
#set module path
mpath="/usr/lib64/opensips/modules/"
#### SIGNALING module
loadmodule "signaling.so"
#### StateLess module
loadmodule "sl.so"
#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 5)
modparam("tm", "fr_inv_timeout", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)
#### Record Route Module
loadmodule "rr.so"
/* do not append from tag to the RR (no need for this script) */
modparam("rr", "append_fromtag", 0)
#### MAX ForWarD module
loadmodule "maxfwd.so"
#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"
#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)
#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)
loadmodule "proto_udp.so"
loadmodule "proto_tcp.so"
loadmodule "proto_ws.so"
modparam("proto_ws","ws_port",8080)
modparam("proto_ws","ws_send_timeout",20000)
#### MYSQL module
loadmodule "db_mysql.so"
#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", "NAT")
modparam("usrloc", "db_mode", 2)
modparam("usrloc", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
modparam("registrar", "received_avp", "$avp(received_nh)")
/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)
#### ACCounting module
loadmodule "acc.so"
/* what special events should be accounted ? */
modparam("acc", "early_media", 0)
modparam("acc", "report_cancels", 0)
/* by default we do not adjust the direct of the sequential requests.
if you enable this parameter, be sure the enable "append_fromtag"
in "rr" module */
modparam("acc", "detect_direction", 0)
modparam("acc", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### AUTHentication modules
loadmodule "auth.so"
loadmodule "auth_db.so"
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("auth_db|uri", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
modparam("auth_db", "load_credentials", "")
#### ALIAS module
loadmodule "alias_db.so"
modparam("alias_db", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### DIALOG module
loadmodule "dialog.so"
modparam("dialog", "dlg_match_mode", 1)
modparam("dialog", "default_timeout", 21600) # 6 hours timeout
modparam("dialog", "db_mode", 2)
modparam("dialog", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### NAT modules
loadmodule "nathelper.so"
modparam("nathelper", "natping_interval", 10)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "received_avp", "$avp(received_nh)")
modparam("nathelper", "sipping_from", "sip:pinger@192.168.1.100")
modparam("nathelper", "natping_interval", 30)
modparam("nathelper", "sipping_bflag", "SIP_PING_FLAG") #OPTIONS ping
######################################################################
## Path Module Parameters
######################################################################
loadmodule "path.so"
modparam("path", "use_received", 1)
loadmodule "dispatcher.so"
modparam("dispatcher", "ds_ping_method", "OPTIONS") # CUSTOMIZE ME
modparam("dispatcher", "ds_ping_interval", 3) # CUSTOMIZE ME
modparam("dispatcher", "ds_probing_threshhold", 2) # CUSTOMIZE ME
modparam("dispatcher", "ds_probing_mode", 1) # CUSTOMIZE ME
modparam("dispatcher", "db_url", "mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
loadmodule "load_balancer.so"
modparam("load_balancer", "db_url", "mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
modparam("load_balancer", "probing_method", "OPTIONS")
modparam("load_balancer", "probing_interval", 3)
loadmodule "rtpproxy.so"
modparam("rtpproxy", "rtpproxy_sock", "udp:192.168.1.100:1111")
loadmodule "mediaproxy.so"
modparam("mediaproxy","disable", 0)
modparam("mediaproxy", "mediaproxy_socket", "/var/run/mediaproxy/dispatcher.sock")
modparam("mediaproxy", "mediaproxy_timeout", 1000)
modparam("mediaproxy", "signaling_ip_avp", "$avp(nat_ip)")
modparam("mediaproxy", "media_relay_avp", "$avp(media_relay)")
modparam("mediaproxy", "ice_candidate", "low-priority")
loadmodule "httpd.so"
modparam("httpd", "ip", "0.0.0.0")
modparam("httpd", "port", 8888)
loadmodule "mi_json.so"
####### Routing Logic ########
route{
if (!mf_process_maxfwd_header("10")) {
send_reply("483","Too Many Hops");
exit;
}
if (!has_totag()) {
# handle hop-by-hop ACK (no routing required)
record_route();
}else{
loose_route();
t_relay();
exit;
}
# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans())
t_relay();
exit;
}
if (is_method("INVITE")) {
if (!load_balance("1","pstn")) {
send_reply("503","Service Unavailable");
exit;
}
loose_route();
t_relay();
exit;
}
else if (is_method("REGISTER")) {
if (!ds_select_dst("1", "0")) {
send_reply("503","Service Unavailable");
exit;
}
} else {
send_reply("405","Method Not Allowed");
exit;
}
if (!t_relay()) {
sl_reply_error();
}
}
2、NAT转换负载均衡
####### Global Parameters #########
log_level=4
log_stderror=no
log_facility=LOG_LOCAL0
children=4
/* uncomment the following lines to enable debugging */
debug_mode=no
/* uncomment the next line to enable the auto temporary blacklisting of
not available destinations (default disabled) */
#disable_dns_blacklist=no
/* uncomment the next line to enable IPv6 lookup after IPv4 dns
lookup failures (default disabled) */
#dns_try_ipv6=yes
/* comment the next line to enable the auto discovery of local aliases
based on revers DNS on IPs */
auto_aliases=yes
listen=udp:192.168.1.100:5060
####### Modules Section ########
#set module path
mpath="/usr/lib64/opensips/modules/"
#### SIGNALING module
loadmodule "signaling.so"
#### StateLess module
loadmodule "sl.so"
#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 5)
modparam("tm", "fr_inv_timeout", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)
#### Record Route Module
loadmodule "rr.so"
/* do not append from tag to the RR (no need for this script) */
modparam("rr", "append_fromtag", 0)
#### MAX ForWarD module
loadmodule "maxfwd.so"
#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"
#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)
#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)
loadmodule "proto_udp.so"
loadmodule "proto_tcp.so"
loadmodule "proto_ws.so"
modparam("proto_ws","ws_port",8080)
modparam("proto_ws","ws_send_timeout",20000)
#### MYSQL module
loadmodule "db_mysql.so"
#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", "NAT")
modparam("usrloc", "db_mode", 2)
modparam("usrloc", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
modparam("registrar", "received_avp", "$avp(received_nh)")
/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)
#### ACCounting module
loadmodule "acc.so"
/* what special events should be accounted ? */
modparam("acc", "early_media", 0)
modparam("acc", "report_cancels", 0)
/* by default we do not adjust the direct of the sequential requests.
if you enable this parameter, be sure the enable "append_fromtag"
in "rr" module */
modparam("acc", "detect_direction", 0)
modparam("acc", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### AUTHentication modules
loadmodule "auth.so"
loadmodule "auth_db.so"
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("auth_db|uri", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
modparam("auth_db", "load_credentials", "")
#### ALIAS module
loadmodule "alias_db.so"
modparam("alias_db", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### DIALOG module
loadmodule "dialog.so"
modparam("dialog", "dlg_match_mode", 1)
modparam("dialog", "default_timeout", 21600) # 6 hours timeout
modparam("dialog", "db_mode", 2)
modparam("dialog", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### NAT modules
loadmodule "nathelper.so"
modparam("nathelper", "natping_interval", 10)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "received_avp", "$avp(received_nh)")
modparam("nathelper", "sipping_from", "sip:pinger@192.168.1.100")
modparam("nathelper", "natping_interval", 30)
modparam("nathelper", "sipping_bflag", "SIP_PING_FLAG") #OPTIONS ping
######################################################################
## Path Module Parameters
######################################################################
loadmodule "path.so"
modparam("path", "use_received", 1)
loadmodule "dispatcher.so"
modparam("dispatcher", "ds_ping_method", "OPTIONS") # CUSTOMIZE ME
modparam("dispatcher", "ds_ping_interval", 3) # CUSTOMIZE ME
modparam("dispatcher", "ds_probing_threshhold", 2) # CUSTOMIZE ME
modparam("dispatcher", "ds_probing_mode", 1) # CUSTOMIZE ME
modparam("dispatcher", "db_url", "mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
loadmodule "load_balancer.so"
modparam("load_balancer", "db_url", "mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
modparam("load_balancer", "probing_method", "OPTIONS")
modparam("load_balancer", "probing_interval", 3)
loadmodule "rtpproxy.so"
modparam("rtpproxy", "rtpproxy_sock", "udp:192.168.1.100:1111")
loadmodule "mediaproxy.so"
modparam("mediaproxy","disable", 0)
modparam("mediaproxy", "mediaproxy_socket", "/var/run/mediaproxy/dispatcher.sock")
modparam("mediaproxy", "mediaproxy_timeout", 1000)
modparam("mediaproxy", "signaling_ip_avp", "$avp(nat_ip)")
modparam("mediaproxy", "media_relay_avp", "$avp(media_relay)")
modparam("mediaproxy", "ice_candidate", "low-priority")
loadmodule "httpd.so"
modparam("httpd", "ip", "0.0.0.0")
modparam("httpd", "port", 8888)
loadmodule "mi_json.so"
####### Routing Logic ########
#main request routing logic
route{
force_rport();
if (nat_uac_test("23")) {
if (is_method("REGISTER")) {
fix_nated_register();
setbflag(NAT);
}else {
fix_nated_contact();
setflag(NAT);
}
}
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
if (has_totag()) {
if ( is_method("ACK") && t_check_trans() ) {
t_relay();
exit;
}
if ( !loose_route() ) {
send_reply("404","Not here");
exit;
}
if ( $DLG_status!=NULL && !validate_dialog() ) {
xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog\n");
}
if (is_method("BYE")) {
do_accounting("db","failed");
}
if (check_route_param("nat=yes"))
setflag(NAT);
route(relay);
exit;
}
if (ds_is_in_list("$si", "", "1"))
{
route(relay);
exit;
}
# check if the clients are using WebSockets or WebSocketSecure
# CANCEL processing
if (is_method("CANCEL"))
{
if (t_check_trans())
t_relay();
exit;
}
t_check_trans();
# preloaded route checking
if (loose_route()) {
xlog("L_ERR",
"Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
if (!is_method("ACK"))
sl_send_reply("403","Preload Route denied");
exit;
}
# record routing
if (!is_method("REGISTER|MESSAGE"))
record_route();
if (is_method("INVITE")) {
if ( !create_dialog("B") ) {
send_reply("500","Internal Server Error");
exit;
}
do_accounting("db");
}
if (!is_myself("$rd")) {
append_hf("P-hint: outbound\r\n");
route(relay);
}
# requests for my domain
if (is_method("PUBLISH|SUBSCRIBE"))
{
sl_send_reply("503", "Service Unavailable");
exit;
}
if (is_method("REGISTER") )
{
if (isflagset(NAT)) {
setbflag(SIP_PING_FLAG);
}
if (!save("location")){
sl_reply_error();
}
if (!ds_select_dst("1", "0")) {
send_reply("503","Service Unavailable");
exit;
}
}
else if (is_method("INVITE")) {
if (!load_balance("1","pstn")) {
send_reply("503","Service Unavailable");
exit;
}
}
if ($rU==NULL) {
send_reply("484","Address Incomplete");
exit;
}
alias_db_lookup("dbaliases");
if (!lookup("location","m")) {
t_reply("404", "Not Found");
exit;
}
if (isbflagset(NAT)) setflag(NAT);
do_accounting("db","missed");
route(relay);
}
route[relay] {
if (is_method("INVITE")) {
if (isflagset(NAT)) {
rtpproxy_offer("ro");
}
t_on_branch("per_branch_ops");
t_on_reply("handle_nat");
t_on_failure("missed_call");
}
if (isflagset(NAT)) {
add_rr_param(";nat=yes");
}
if (!t_relay()) {
send_reply("500","Internal Error");
};
exit;
}
branch_route[per_branch_ops] {
xlog("new branch at $ru\n");
}
onreply_route[handle_nat] {
if (nat_uac_test("1"))
fix_nated_contact();
if ( isflagset(NAT) )
rtpproxy_answer("ro");
xlog("incoming reply\n");
}
failure_route[missed_call] {
if (t_was_cancelled()) {
exit;
}
}
local_route
{
if (is_method("BYE") && $DLG_dir=="UPSTREAM") {
acc_db_request("200 Dialog Timeout", "acc");
}
}
3、只用Load_Balancer模块负载均衡
####### Global Parameters #########
log_level=3
log_stderror=no
log_facility=LOG_LOCAL0
children=4
/* uncomment the following lines to enable debugging */
debug_mode=no
/* uncomment the next line to enable the auto temporary blacklisting of
not available destinations (default disabled) */
#disable_dns_blacklist=no
/* uncomment the next line to enable IPv6 lookup after IPv4 dns
lookup failures (default disabled) */
#dns_try_ipv6=yes
/* comment the next line to enable the auto discovery of local aliases
based on revers DNS on IPs */
auto_aliases=yes
listen=udp:192.168.1.100:5060
####### Modules Section ########
#set module path
mpath="/usr/lib64/opensips/modules/"
#### SIGNALING module
loadmodule "signaling.so"
#### StateLess module
loadmodule "sl.so"
#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 5)
modparam("tm", "fr_inv_timeout", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)
#### Record Route Module
loadmodule "rr.so"
/* do not append from tag to the RR (no need for this script) */
modparam("rr", "append_fromtag", 0)
#### MAX ForWarD module
loadmodule "maxfwd.so"
#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"
#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)
#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)
loadmodule "proto_udp.so"
loadmodule "proto_tcp.so"
loadmodule "proto_ws.so"
modparam("proto_ws","ws_port",8080)
modparam("proto_ws","ws_send_timeout",20000)
#### MYSQL module
loadmodule "db_mysql.so"
#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", "NAT")
modparam("usrloc", "db_mode", 2)
modparam("usrloc", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
modparam("registrar", "received_avp", "$avp(received_nh)")
/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)
#### ACCounting module
loadmodule "acc.so"
/* what special events should be accounted ? */
modparam("acc", "early_media", 0)
modparam("acc", "report_cancels", 0)
/* by default we do not adjust the direct of the sequential requests.
if you enable this parameter, be sure the enable "append_fromtag"
in "rr" module */
modparam("acc", "detect_direction", 0)
modparam("acc", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### AUTHentication modules
loadmodule "auth.so"
loadmodule "auth_db.so"
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("auth_db|uri", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
modparam("auth_db", "load_credentials", "")
#### ALIAS module
loadmodule "alias_db.so"
modparam("alias_db", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
#### DIALOG module
loadmodule "dialog.so"
modparam("dialog", "dlg_match_mode", 1)
modparam("dialog", "default_timeout", 21600) # 6 hours timeout
modparam("dialog", "db_mode", 2)
modparam("dialog", "db_url",
"mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
######################################################################
## Path Module Parameters
######################################################################
loadmodule "path.so"
modparam("path", "use_received", 1)
loadmodule "load_balancer.so"
modparam("load_balancer", "db_url", "mysql://root:123456@localhost/opensips") # CUSTOMIZE ME
modparam("load_balancer", "probing_method", "OPTIONS")
modparam("load_balancer", "probing_interval", 60)
loadmodule "httpd.so"
modparam("httpd", "ip", "0.0.0.0")
modparam("httpd", "port", 8888)
loadmodule "mi_json.so"
####### Routing Logic ########
route{
if (!mf_process_maxfwd_header("10")) {
send_reply("483","Too Many Hops");
exit;
}
if (!has_totag()) {
# handle hop-by-hop ACK (no routing required)
record_route();
}else{
loose_route();
t_relay();
exit;
}
# CANCEL processing
if (is_method("CANCEL")) {
if (t_check_trans())
t_relay();
exit;
}
if (is_method("INVITE")) {
if (!load_balance("1","pstn")) {
send_reply("503","Service Unavailable");
exit;
}
loose_route();
t_relay();
exit;
}
else if (is_method("REGISTER")) {
if (!load_balance("1","pstn")) {
send_reply("503","Service Unavailable");
exit;
}
} else {
send_reply("405","Method Not Allowed");
exit;
}
if (!t_relay()) {
sl_reply_error();
}
}
转载请注明:SuperIT » opensips负载均衡最终脚本