2016-09-05 99 views
0

我有三臺運行Ubuntu 14.04的虛擬服務器。在一臺服務器上安裝了Kamailio和其他Asterisk。我希望Kamailio服務器作爲負載均衡器工作,並將傳入呼叫轉發到星號服務器(循環賽)。Kamailio作爲多個星號服務器的負載平衡器

我想先用一個星號服務器測試它,如果可以的話,我可以增加更多的性能。

我說我的SIP提供商的憑據是這樣的:

kamctl add test testpasswd 

然後,我添加星號服務器的調度表是這樣的:

INSERT INTO dispatcher (setid,destination,flags,priority,attrs,description) VALUES (1,"sip:10.1.1.3:5060",0,0,"","Asteriskl-I"); 

我改變了我的星號的sip.conf文件服務器,它連接到我的kamailio服務器,似乎工作。

我kamailio.cfg文件看起來像這樣:

#!KAMAILIO 
 
# 
 
# sample config file for dispatcher module 
 
# - load balancing of VoIP calls with round robin 
 
# - no TPC listening 
 
# - don't dispatch REGISTER and presence requests 
 
# 
 
# Kamailio (OpenSER) SIP Server v3.2 
 
#  - web: http://www.kamailio.org 
 
#  - git: http://sip-router.org 
 
# 
 
# Direct your questions about this file to: [email protected] 
 
# 
 
# Refer to the Core CookBook at http://www.kamailio.org/dokuwiki/doku.php 
 
# for an explanation of possible statements, functions and parameters. 
 
# 
 
# Several features can be enabled using '#!define WITH_FEATURE' directives: 
 
# 
 
# *** To run in debug mode: 
 
#  - define WITH_DEBUG 
 
# 
 

 
####### Global Parameters ######### 
 

 
#!define WITH_DEBUG 
 

 
#!ifdef WITH_DEBUG 
 
debug=4 
 
log_stderror=yes 
 
#!else 
 
debug=2 
 
log_stderror=no 
 
#!endif 
 

 
memdbg=5 
 
memlog=5 
 

 
log_facility=LOG_LOCAL0 
 

 
fork=yes 
 
children=4 
 

 
/* comment the next line to enable TCP */ 
 
disable_tcp=yes 
 

 
/* uncomment the next line to disable the auto discovery of local aliases 
 
    based on revers DNS on IPs (default on) */ 
 
auto_aliases=no 
 

 
/* add local domain aliases */ 
 
# alias="mysipserver.com" 
 

 
port=5060 
 

 
/* uncomment and configure the following line if you want Kamailio to 
 
    bind on a specific interface/port/proto (default bind on all available) */ 
 
# listen=udp:127.0.0.1:5060 
 

 
sip_warning=no 
 

 
####### Modules Section ######## 
 

 
#set module path 
 
mpath="/usr/local/lib64/kamailio/modules/" 
 

 
# loadmodule "db_mysql.so" 
 
loadmodule "mi_fifo.so" 
 
loadmodule "kex.so" 
 
loadmodule "tm.so" 
 
loadmodule "tmx.so" 
 
loadmodule "sl.so" 
 
loadmodule "rr.so" 
 
loadmodule "pv.so" 
 
loadmodule "maxfwd.so" 
 
loadmodule "textops.so" 
 
loadmodule "siputils.so" 
 
loadmodule "xlog.so" 
 
loadmodule "sanity.so" 
 
# loadmodule "ctl.so" 
 
loadmodule "mi_rpc.so" 
 
loadmodule "acc.so" 
 
loadmodule "dispatcher.so" 
 

 

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

 

 
# ----- mi_fifo params ----- 
 
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo") 
 

 

 
# ----- rr params ----- 
 
# add value to ;lr param to cope with most of the UAs 
 
modparam("rr", "enable_full_lr", 1) 
 
# do not append from tag to the RR (no need for this script) 
 
modparam("rr", "append_fromtag", 0) 
 

 

 
# ----- acc params ----- 
 
modparam("acc", "log_flag", 1) 
 
modparam("acc", "failed_transaction_flag", 3) 
 
modparam("acc", "log_extra", 
 
     "src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd;src_ip=$si") 
 

 
# ----- tm params ----- 
 
modparam("tm", "fr_timer", 2000) 
 
modparam("tm", "fr_inv_timer", 40000) 
 

 
# ----- dispatcher params ----- 
 
# modparam("dispatcher", "db_url", 
 
#  "mysql://kamailio:[email protected]/kamailio") 
 
modparam("dispatcher", "table_name", "dispatcher") 
 
modparam("dispatcher", "flags", 2) 
 
modparam("dispatcher", "dst_avp", "$avp(AVP_DST)") 
 
modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)") 
 
modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)") 
 

 
####### Routing LogiC######## 
 

 

 
# main request routing logic 
 

 
route { 
 

 
     # per request initial checks 
 
     route(REQINIT); 
 

 
     # handle requests within SIP dialogs 
 
     route(WITHINDLG); 
 

 
     ### only initial requests (no To tag) 
 

 
     # CANCEL processing 
 
     if (is_method("CANCEL")) 
 
     { 
 
       if (t_check_trans()) 
 
         t_relay(); 
 
       exit; 
 
     } 
 

 
     t_check_trans(); 
 

 
     # record routing for dialog forming requests (in case they are routed) 
 
     # - remove preloaded route headers 
 
     remove_hf("Route"); 
 
     if (is_method("INVITE|SUBSCRIBE")) 
 
       record_route(); 
 
     #if (is_method("INVITE")) 
 
     #{ 
 
     #  ds_select_domain("1","4"); 
 
     #  #sl_send_reply("300","Redirect"); 
 
     #  #t_relay(); 
 
     #  exit; 
 
     #} 
 

 
     # account only INVITEs 
 
     if (is_method("INVITE")) 
 
     { 
 
       setflag(1); # do accounting 
 
     } 
 

 
     # handle presence related requests 
 
     route(PRESENCE); 
 

 
     # handle registrations 
 
     route(REGISTRAR); 
 

 
     if ($rU==$null) 
 
     { 
 
       # request with no Username in RURI 
 
       sl_send_reply("484","Address Incomplete"); 
 
       exit; 
 
     } 
 

 
     # dispatch destinations 
 
     route(DISPATCH); 
 

 
     route(RELAY); 
 
} 
 

 

 
route[RELAY] { 
 
     if (!t_relay()) { 
 
       sl_reply_error(); 
 
     } 
 
     exit; 
 
} 
 

 
# Per SIP request initial checks 
 
route[REQINIT] { 
 
     if (!mf_process_maxfwd_header("10")) { 
 
       sl_send_reply("483","Too Many Hops"); 
 
       exit; 
 
     } 
 

 
     if(!sanity_check("1511", "7")) 
 
     { 
 
       xlog("Malformed SIP message from $si:$sp\n"); 
 
       exit; 
 
     } 
 
} 
 

 
# Handle requests within SIP dialogs 
 
route[WITHINDLG] { 
 
     if (has_totag()) { 
 
       # sequential request withing a dialog should 
 
       # take the path determined by record-routing 
 
       if (loose_route()) { 
 
         if (is_method("BYE")) { 
 
           setflag(1); # do accounting ... 
 
           setflag(3); # ... even if the transaction fails 
 
         } 
 
         route(RELAY); 
 
       } else { 
 
         if (is_method("SUBSCRIBE") && uri == myself) { 
 
           # in-dialog subscribe requests 
 
           route(PRESENCE); 
 
           exit; 
 
         } 
 
         if (is_method("ACK")) { 
 
           if (t_check_trans()) { 
 
             # non loose-route, but stateful ACK; 
 
             # must be ACK after a 487 or e.g. 404 from upstream server 
 
             t_relay(); 
 
             exit; 
 
           } else { 
 
             # ACK without matching transaction ... ignore and discard. 
 
             exit; 
 
           } 
 
         } 
 
         sl_send_reply("404","Not here"); 
 
       } 
 
       exit; 
 
     } 
 
} 
 

 
# Handle SIP registrations 
 
route[REGISTRAR] { 
 
     if(!is_method("REGISTER")) 
 
       return; 
 
     #sl_send_reply("404", "No registrar"); 
 
     #t_relay(); 
 
     if(!ds_select_dst("1", "4")) 
 
     { 
 
       sl_send_reply("404", "No registrar"); 
 
       exit; 
 
     } 
 
     forward(); 
 

 
     exit; 
 
} 
 

 
# Presence server route 
 
route[PRESENCE] { 
 
     if(!is_method("PUBLISH|SUBSCRIBE")) 
 
       return; 
 

 
     sl_send_reply("404", "Not here"); 
 
     exit; 
 
} 
 

 
# Dispatch requests 
 
route[DISPATCH] { 
 
     # round robin dispatching on gateways group '1' 
 
     if(!ds_select_dst("1", "4")) 
 
     { 
 
       send_reply("404", "No destination"); 
 
       exit; 
 
     } 
 
     xlog("L_DBG", "--- SCRIPT: going to <$ru> via <$du>\n"); 
 
     t_on_failure("RTF_DISPATCH"); 
 
     return; 
 
} 
 

 
# Sample failure route 
 
failure_route[RTF_DISPATCH] { 
 
     if (t_is_canceled()) { 
 
       exit; 
 
     } 
 
     # next DST - only for 500 or local timeout 
 
     if (t_check_status("500") 
 
         or (t_branch_timeout() and !t_branch_replied())) 
 
     { 
 
       if(ds_next_dst()) 
 
       { 
 
         t_on_failure("RTF_DISPATCH"); 
 
         route(RELAY); 
 
         exit; 
 
       } 
 
     } 
 
}

如果我直接連接我的星號框,我的SIP提供它完美的作品。但是,如果我將它連接到kamailio服務器並將它連接到SIP提供程序的kamailio服務器,它不會。

我GOOGLE了幾個小時,嘗試了很多事情,我真的不知道我可以嘗試下......如果有人可以幫助我,我會非常高興!

非常感謝和問候

+0

你究竟有什麼問題? kamailio提供的默認調度程序配置工作正常,除非你想添加到它和其他功能(需要非常特殊的知識設置)。爲什麼你幾個小時谷歌?你只需要進行SIP調試(使用tcpdump或其他),並確保你的配置是正確的。 – arheops

+0

所以你有防火牆,不是嗎? – arheops

回答

0

I added my SIP provider credentials like this:

kamctl add test testpasswd - 這是錯誤的。

檢查下面的鏈接瞭解詳細信息你應該如何建立對Kamailio SIP中繼,其使用用戶名/密碼認證:

http://lists.sip-router.org/pipermail/sr-users/2015-September/090001.html

+0

你好os11k,非常感謝你的回答! 我試圖用這個認證來配置它。我kamailio.cfg現在看起來是這樣的:http://pastebin.com/H6R8mZ0g 它編譯,但是當我撥打的號碼,它仍然無法正常工作。任何想法? – simplex

+0

我試過用uac模塊,但是我無法讓它工作。 我有這些信息: SIP提供者: 用戶名密碼 域 應該如何我kamailio.cfg是什麼樣子?我試圖想與UAC模塊10個不同的變化。還是我如何註冊我的kamailio服務器到我的SIP服務提供商? – simplex

+0

檢查:http://www.kamailio.org/docs/modules/4.4.x/modules/uac.html#idp23591108它說,你需要添加記錄uacreg表 – os11k