Asterisk - dual servers Connecting two Asterisk servers

Overview

Of course you can also use SIP or H.323 (but not MGCP) to interlink two Asterisk servers, however IAX is the most common approach (Note: SIP > IAX > SIP does not currently work for video calls as of Jan 08). In order to share a dialplan you can
  • intelligently design the dialplan on each server so that it becomes immediately clear when an extension on the other server is dialed, e.g. use 3xxx for server A, 4xxx for server B, and 5xxx for extensions on server C.
  • use the "switch" statement to make server A lookup locally unknown extensions on server B (both boxes must bepermanently on-line, if that is not the case you'll experience large delays when dialing!)
  • use DUNDi: Distributed Universal Number Directory (DUNDi)
  • use EnumLookup (e.164)

概述

 你当然也可以用sip 或者 H.323 (但是不能用MGCP)去互联两个asterisk服务器,然而,IAX是最通用的方式。为了共享一个拨号方案,你可以

1. 在每一个服务器上智能的设计拨号方案,以便一个拨号指令在另一个服务器上执行的时候,拨号方案清晰明了。例如,拨号指令在服务器A上用3XXX,在服务器B上用4XXX,在服务器C上用5XXX。

2.  使用switch关键字让A服务器去B服务器上去查找本地未知指令。(两边的服务器必须持续的在线,否侧,在拨号的时候,你将遭遇长时间的延迟)

3.  使用 DNUDi: 分布式通用号码目录。这个应该是给asterisk实现负载均衡的东西。

4. 使用EnumLookup

----------------------------------------------------------------------------------------------------------------------------------------------

SIP methods

Unlike with IAX there is no clean distinction between type=peer and type=user when it comes to sip.conf. You can start out with type=friend on both sides, and if you get that working you'll probably want to split the entry into a peer and a user. Also take a look at the sip.conf parameters "insecure=very" and maybe "autocreatepeer=yes".

  • server A with static IP, server B with dynamic IP: Register server B with server A in sip.conf
  • both servers with static IP: No need to register at all
  • both servers with dynamic IP: That's a bit tricky, you'll need to resort to a service like dyndns.org in to be able to register the servers with each other; in any case this is not a good setup as during IP change connectivity will be lost until the update has been propagated through dyndns.
  • both servers behind their own NAT: Don't use SIP, turn to IAX2 instead

SIP方式

与IAX不同,当处理sip.conf时,type=peer 和type=usr没有明显的区别。在两边的服务器上,你可以以type=friend开头。(我理解是在服务器互相注册的那块)。如果可以正常工作了,你可能会考虑区分peer和user.

1. 服务器A是静态IP,服务器B是动态IP,那么需要服务器B去注册服务器A,并在服务器A的sip.conf上增加服务器B的账号信息。

2.两边都是静态IP,那么根本不需要注册。

3.两边都是动态IP,那有点棘手,你需要求助像dyndns.org(应该是一个域名服务商)这样的服务。他能够解决服务器之间互相注册。

4. 两边的服务器都在各自NAT后面,那么不要用SIP,改用IAX2代替。

----------------------------------------------------------------------------------------------------------------------------------------------

IAX setup details

An IAX connection between two Asterisk servers is setup in steps:

  • Configure Asterisk servers at both ends in iax.conf, one as peer and the other as user.
  • Set up the user's dialplan in extensions.conf so that calls can be made from the user to the peer.
  • Optionally, register the peer with the user (for when the peer's ip is dynamic and therefore unknown by the user.)
  • Repeat the previous steps in the opposite direction (swap peer and user) if you want to be able to place calls in both directions.

IAX 详细设置

用IAX来连接两个asterisk服务区的设置步奏如下:

1. 分别在两个asterisk服务器配置iax.conf,一个作为peer,另一个作为user。

2. 在extensions.conf里设置用户拨号方案,以使呼叫可以从user到peer。

3. 可选的,注册user的peer(当peer的ip是动态的)。

4. 重复前面的步奏,以相反的方向(交换peer和user),如果你想能够在两个方向呼叫。

----------------------------------------------------------------------------------------------------------------------------------------------

Declaration of IAX2 user

A peer receives calls. The following would be needed in iax.conf on the peer machine to verify (authenticate) the identify of the user before allowing calls from that user.


声明IAX2用户

一个peer接受呼叫。在允许一个user的呼叫之前,需要在peer机器上验证用户的标识。下面是peer机器上的iax.conf,用来验证用户的标识。

[username]
type=user
auth=md5
secret=secretword
context=iax2users


The "context" is important as it sets the local context in which to place any calls incoming from this user (seeextensions.conf ).
context是重要的,context作为本地拨号方案用来接收user的呼叫。

This setup lets the remote user register to your system from any host. If you want to restrict which IP-address or hostname the remote user connects from, addpermit ordeny settings when describing the user in the peer's iax.conf.

这个设置让远程的user注册要你的系统从任意主机。如果你想限制一个特定IP地址或主机名的远程用户的连接,添加permit或者deny设置,当在peer的iax.conf的user描述中。

----------------------------------------------------------------------------------------------------------------------------------------------


Declaration of IAX2 peer

A user makes calls. The following would be needed in iax.conf on the user machine to identify (authenticate) itself to the peer before the peer will take the call.

声明IAX2 peer

一个用户呼叫。在peer发起一个呼叫前,下面在user机器上的iax.conf中的设置用来标识peer。

[peername]
type=peer
host=hostname.domain.tld (or "dynamic" which would then require a "register" command by the peer.)
auth=md5
secret=secretword ; redundant when already embedded in Dial string
username=username-at-the-peer ; redundant when already embedded in Dial string


Please note:
  • a type=user is to authenticate an incoming call
  • a type=peer is someone you send a call to
  • type=friend, of course, is both
请注意:
  1. type=user 用来认证呼入。
  2. type=peer 是你要呼出的节点。
  3. type=frient 是上面的综合。

Using type=friend makes life easier, but treat it as a shortcut. If you add both type=friend and host=hostname, domain.ext you limit the hosts your peer can place calls from, which may not be what you want.

使用type=friend使问题更简单了。

For instructions on using auth=rsa, see Asterisk IAX RSA authentication wiki page.

Now that we have completed steps 1 and 2 the only thing left is to set up the dialplan. Read the examples below for how to accomplish that.



----------------------------------------------------------------------------------------------------------------------------------------------


Connecting the dial plans

Example 1


extensions.conf:
exten => _7XXX,1,Dial(IAX2/myserver:passwordA@IAXserverA/${EXTEN:1},30,r)
exten => _7XXX,2,Dial(SIP/myserver:passwordA@SIPserverA/${EXTEN:1},30,r)
exten => _7XXX,3,Congestion

exten => _8XXX,1,Dial(IAX2/myserver:passwordB@IAXserverB/${EXTEN:1},30,r)
exten => _8XXX,2,Dial(SIP/myserver:passwordB@SIPserverB/${EXTEN:1},30,r)
exten => _8XXX,3,Congestion

Of course we'll need matching entries like [IAXserverA] etc. in iax.conf and sip.conf in order for the above to work as intended. The example uses SIP as a fallback in case we have problems with your IAX connection.
Note that with this approach username and password will be shown in the CDR records (you might want to use the second example or to look at using keys instead of a username/password combination)!

Example 2

This example doesn't show the username and secret in the CDR.
Note: As if 1.0.9 this shortcut is still not part of the Asterisk Stable branch, so still requires the user and password as part of the dial string in extensions.conf. e.g.
exten => _7XXX,1,Dial(IAX2/username:pass@serverB/${EXTEN:1},30,r)


(serverA)
iax.conf
[general]
register => <username>:<password>@<serverB hostname or IP>

[serverB]
type=friend
user=<username>
secret=<password>
host=<serverB hostname or IP>

extensions.conf
exten => _7XXX,1,Dial(IAX2/serverB/${EXTEN:1},30,r)
exten => _7XXX,2,Congestion

(serverB)
iax.conf
[serverA]
type=friend
user=<username>
secret=<password>
host=<dynamic> | <serverA hostname or IP>

extensions.conf
exten => _8XXX,1,Dial(IAX2/serverA/${EXTEN:1},30,r)
exten => _8XXX,2,Congestion

In some cases the serverA and serverB, will be the usernames of the server.

Example 3

With the Switch object in extensions.conf you may connect two Asterisk servers and the other servers dial plan. In this case our own box "server C" will either connect to "server A" or "server B":

[default]
exten => _801XXX,1,Goto,srvA|${EXTEN}|1
exten => _802XXX,1,Goto,srvB|${EXTEN}|1

[srvA]
exten => _801XXX,1,StripMSD,3
exten => _XXX,2,Goto,1
switch => IAX/serverA

[srvB]
exten => _802XXX,1,StripMSD,3
exten => _XXX,2,Goto,1
switch => IAX/serverB

Notes: You may not establish circular links by switching serverA to serverB and serverB to serverA! Also take a look at the (new) iax.conf setting "autokill=" to prevent a long hang when the remote server is down or disconnected.

Example 4


In extensions.conf: (on slave)

[outbound]
switch => IAX2/master:secret@iax-gw1.company.net/outbound

In iax.conf (on master):

[slave]
type=user
auth=plaintext
context=outbound
context=outbound2 ; (can have multiple if you want)
secret=secret
host=dynamic
callerid="slave"
trunk=yes
notransfer=yes

[slave]
type=peer
auth=plaintext
context=outbound-nuphone
secret=secret
host=dynamic
trunk=yes
notransfer=yes

In extensions.conf (slave):

[assigned-dids]
; uncomment a dial mechanism, first one goes to specific extension
; other one goes to dial parameter s.

;exten => 7046446999,1,Dial,IAX2/master@slave/${EXTEN}
;exten => 7046446999,1,Dial,IAX2/master@slave

In iax.conf (slave):

register => slave:secret@iax-gw1.company.net

[master]
type=peer
host=iax-gw1.company.net
secret=secret
context=outbound
trunk=yes
canreinvite=no

[master]
type=user
secret=secret
context=acontext
trunk=yes
canreinvite=no

----------------------------------------------------------------------------------------------------------------------------------------------


The register command

When the ip of the peer is unknown, a user has no way to place a call (e.g. when an office/user calls a teleworker/peer at home, where the teleworker has only a dynamic ip or is behind NAT.) To compensate for this, the teleworker/peer actively registers with the office/user by providing its identity and ip location.

注册命令

当peer的ip是未知的,user没法呼叫。例如,当一个user呼叫一个peer,peer是一个动态的ip或者在NAT后。

要弥补这些,peer要激活注册到user,通过提供他的标识和ip。

On the peer, in the [general] section of iax.conf, add a registration entry:
在peer的iax.conf的[general]部分,添加一个注册条目。
register => user:password@hostname.domain.ext

The continually updates the user so it will always know how to reach the peer even if the peer's ip changes.

持续的更新,以至于user将始终知道如何到达peer,即使peer的ip变化了。


The "register" statement only works if you want to hook up a server with a dynamic IP to a server with a static (public) IP, i.e. on the user you must add "host=dynamic" in the iax.conf for that peer. If both servers are at known, static IPs then there is no need for a register statement as you'd use host=hostname on both ends.

register语句只工作在这种情况,如果你想连接一个动态ip服务器到一个静态ip服务器的时候。也就是说,在user机器上,你必须添加"host=dynamic“在iax.conf为peer.如果两边的服务器都是静态的,那么就不需要resigiter语句了。你可以直接用host=hostname在两边的服务器上。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值