`

使用kamailio 实现asterisk负载均衡

 
阅读更多

 

通过使用kamailio的dispatcher.so 模块实现astersik的负载均衡

配置如下

1:dispatcher.list

 

# group sip addresses of your * units 1 sip:10.1.2.3:5060 1 sip:10.1.2.4:5060 1 sip:10.1.2.5:5060

这里要给sip分组

 

2:kamailio.cfg主要配置如下

loadmodule("dispatcher.so") if ( method=="INVITE" ) { ds_select_dst("1","4"); sl_send_reply("100","Trying"); forward();#uri:host, uri:port); exit(); }


 

这里载入dispatcher.so模块,设置分配规则

其中关键的是用到了ds_select_dst("1","4") 这个方法,该方法接受两个参数,第一个是组ID,也就是dispatcher.list 第一列的是设置 “1”,第二个参数是分配规则,“4”表示轮训 "round-robin (next destination).“

这样,新的INVITE就会在这3个sip之间循环分配,从而实现负载均衡

更多分配规则如下

.

  • 0” - hash over callid

  • 1” - hash over from uri.

  • 2” - hash over to uri.

  • 3” - hash over request-uri.

  • 4” - round-robin (next destination).

  • 5” - hash over authorization-username (Proxy-Authorization or "normal" authorization). If no username is found, round robin is used.

  • 6” - random (using rand()).

  • 7” - hash over the content of PVs string. Note: This works only when the parameter hash_pvar is set.

  • 8” - use first destination (good for failover).

  • 9” - use weight based load distribution. You have to set the attribute 'weight' per each address in destination set.

  • 10” - use call load distribution. You have to set the attribute 'duid' (as an unique string id) per each address in destination set. Also, you must set parameters 'dstid_avp' and 'ds_hash_size'.

    The algorithm can be used even with stateless proxy mode, there is no SIP dialog tracking depending on other modules, just an internal lightweight call tracking by Call-Id, thus is fast and suitable even for embedded systems.

    The first destination selected by this algorithm is the one that has the least number of calls associated. The rest of the destination list is taken in order of the entries in set - anyhow, until a re-route to next destination happens, the load on each address can change.

    This algorithm can be used only for dispatching INVITE requests as it is the only SIP method creating a SIP call.

  • X” - if the algorithm is not implemented, the first entry in set is chosen.

更多功能参看

http://www.kamailio.org/docs/modules/3.1.x/modules_k/dispatcher.html#id2805068

http://www.kamailio.org/docs/modules/3.1.x/

http://www.kamailio.org/dokuwiki/doku.php/asterisk:load-balancing-and-ha

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics