利用Digium卡搭建一个小型的asterisk电话系统

环境: Linux(Debian 6), Asterisk1.8

硬件:586旧式电脑一台,TMP100 Digium卡一张(4口FSO),来自PSTN的电话线一根


一、配置环境

1.1 安装sudo,参见debian下开启sudo 

如果是Ubuntu或者Readhat,则可以跳过

1.2 更新资源列表,

vi /etc/apt/sources.list

在文件末尾加入以下内容

# deb cdrom:[Debian GNU/Linux 6.0.5 _Squeeze_ - Official i386 CD Binary-1 20120512-13:45]/ squeeze main
deb http://ftp.sjtu.edu.cn/debian/ squeeze main non-free contrib
deb http://ftp.sjtu.edu.cn/debian/ squeeze-proposed-updates main non-free contrib
deb http://ftp.sjtu.edu.cn/debian-security/ squeeze/updates main non-free contrib

deb http://mirrors.163.com/debian/ squeeze main non-free contrib
deb http://mirrors.163.com/debian/ squeeze-proposed-updates main non-free contrib
deb http://mirrors.163.com/debian-security/ squeeze/updates main non-free contrib


保存后更新

$sudo apt-get update


1.3 下载并安装Asterisk所需的依赖包

su asteriskpbx

sudo apt-get install build-essential subversion libncurses5-dev libssl-dev libxml2-dev vim-nox


二、系统安装


2.1 下载Asterisk、源代码

mkdir -p ~/src/asterisk-complete/asterisk
cd ~/src/asterisk-complete/asterisk

svn co http://svn.asterisk.org/svn/asterisk/branches/1.8

cd ~/src/asterisk-complete/asterisk/1.8/


2.2 安装libpri,DAHDI,ASterisk

2.2.1 安装libpri(针对ISDN,并非必须)

$ cd ~/src/asterisk-complete/
$ mkdir libpri
$ cd libpri/
$ svn co http://svn.asterisk.org/svn/libpri/tags/1.4.12
$ cd 1.4.12
$ make
$ sudo make install

2.2.2 安装DAHDI

在继续之前,确保已经在电脑的PCI插槽插上Digium卡,并且通过4口电线端口以便在电脑启动时通电。

安装DAHDI驱动之前,需要先安装LINUX内核source

$ sudo apt-get install linux-headers-`uname -r`

这样就可以安装DAHDI驱动了,

$ cd ~/src/asterisk-complete/
$ mkdir dahdi
$ cd dahdi/
$ svn co http://svn.asterisk.org/svn/dahdi/linux-complete/tags/2.4.0+2.4.0
$ cd 2.4.0+2.4.0
$ make
$ sudo make install
$ sudo make config

如果Digium卡安装正确,这时会得到找到Digium卡的提示信息,接下来,修改dahdi.rules文件,使得asteriskpbx用户(更改成你自己的用户即可)可以访问,

vim /etc/udev/rules.d/dahdi.rules
SUBSYSTEM=="dahdi", OWNER="asteriskpbx", GROUP="asteriskpbx", MODE="0660"


2.2.3 安装Asterisk

2.2.3.1  安装

$ cd ~/src/asterisk-complete/asterisk/1.8
$ ./configure
$ make
$ sudo make install

$ sudo make samples
$ sudo make config


2.2.3.2  更改asterisk文件权限

$ sudo chown -R asteriskpbx:asteriskpbx /usr/lib/asterisk/
$ sudo chown -R asteriskpbx:asteriskpbx /var/lib/asterisk/
$ sudo chown -R asteriskpbx:asteriskpbx /var/spool/asterisk/
$ sudo chown -R asteriskpbx:asteriskpbx /var/log/asterisk/
$ sudo chown -R asteriskpbx:asteriskpbx /var/run/asterisk
$ sudo chown asteriskpbx:asteriskpbx /usr/sbin/asterisk

$ sudo chown asteriskpbx:asteriskpbx /etc/asterisk/


2.2.3.3 修改asterisk.conf

$ vim /etc/asterisk/asterisk.conf
去掉runuser和rungroup这两行的注释,并修改成如下
runuser=asteriskpbx
rungroup=asteriskpbx


2.2.3.4 安装声音文件

$ sudo apt-get install libnewt-dev
$ cd ~/src/asterisk-complete/asterisk/1.8
$ cd menuselect
$ make clean
$ ./configure
$ cd ..
$ make menuselect

选择并安装你感兴趣的声音文件,eg.

Once you’ve started menuselect, scroll down to Core Sound Packages and press the
right arrow key (or Enter ) to open the menu. You will be presented with a list of
available options. These options represent the core sound files in various languages and
formats. By default, the only set of files selected is CORE-SOUNDS-EN-GSM, which is the
English-language Core Sounds package in GSM format.
Select CORE-SOUNDS-EN-WAV and CORE-SOUNDS-EN-ULAW (or ALAW if you’re outside of North
America or Japan‖), and any other sound files that may be applicable in your network.
After selecting the appropriate sound files, press the left arrow key to go back to the
main menu. Then scroll down two lines to the Extra Sound Packages menu and press
the right arrow key (or Enter ). You will notice that by default there are no packages
selected. As with the core sound files, select the appropriate language and format to be
installed. A good option is probably to install the English sound files in the WAV, ULAW,
and ALAW formats.

安装之后,更改权限

$ sudo make install
$ sudo chown -R asteriskpbx:asteriskpbx /var/lib/asterisk/sounds/


三、系统配置

3.1修改chan_dahdi.conf

通过lsdahdi命令可以查看已经安装的digium电话卡信息

$ cd /etc/dahdi
$ lsdahdi

根据以上列出的信息,修改chan_dahdi.conf配置

$ cd /etc/asterisk

$ vim  chan_dahdi.conf

[channels]
;
; To apply other options to these channels, put them before "channel".
;
signalling = fxs_ks ; in Asterisk, FXO channels use FXS signaling
; (and yes, FXS channels use FXO signaling)
channel => 1-4 ; apply all the previously defined settings to this channel


3.2 生成dahdi-channels.conf配置文件并使其生效

$ su dahdi_genconf

这样就可以看到生成了 /etc/asterisk/dahdi-channels.conf

本文的例子如下:

; Autogenerated by /usr/sbin/dahdi_genconf on Fri Aug 10 19:53:05 2012
; If you edit this file and execute /usr/sbin/dahdi_genconf again,
; your manual changes will be LOST.
; Dahdi Channels Configurations (chan_dahdi.conf)
;
; This is not intended to be a complete chan_dahdi.conf. Rather, it is intended
; to be #include-d by /etc/chan_dahdi.conf that will include the global settings
;

; Span 1: WCTDM/4 "Wildcard TDM400P REV E/F Board 5" (MASTER) 
;;; line="1 WCTDM/4/0 FXSKS"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 1
callerid=
group=
context=default

;;; line="2 WCTDM/4/1 FXSKS"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 2
callerid=
group=
context=default

;;; line="3 WCTDM/4/2 FXSKS"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 3
callerid=
group=
context=default

;;; line="4 WCTDM/4/3 FXSKS"
signalling=fxs_ks
callerid=asreceived
group=0
context=from-pstn
channel => 4
callerid=
group=
context=default

使更改生效

$ sudo /etc/init.d/dahdi restart


3.3 建立几个sip电话

$ vim /etc/asterisk/sip.conf

在文件的末尾加入

[2220]
context=default
type=friend
secret=blah
qualify=yes
host=dynamic
canreinvite=no
dtmfmode=rfc2833
insecure=port,invite
disallow=all
;allow=g729
allow=alaw
allow=ulaw
callerid="A" <2220>
nat=yes

[2221]
context=default
type=friend
secret=blah
qualify=yes
host=dynamic
canreinvite=no
dtmfmode=rfc2833
insecure=port,invite
disallow=all
;allow=g729
allow=alaw
allow=ulaw
callerid="B" <2221>
nat=yes

[2222]
context=default
type=friend
secret=blah
qualify=yes
host=dynamic
canreinvite=no
dtmfmode=rfc2833
insecure=port,invite
disallow=all
;allow=g729
allow=alaw
allow=ulaw
callerid="C" <2222>
nat=yes

[2223]
context=default
type=friend
secret=blah
qualify=yes
host=dynamic
canreinvite=no
dtmfmode=rfc2833
insecure=port,invite
disallow=all
;allow=g729
allow=alaw
allow=ulaw
callerid="D" <2223>
nat=yes

[2224]
context=default
type=friend
secret=blah
qualify=yes
host=dynamic
canreinvite=no
dtmfmode=rfc2833
insecure=port,invite
disallow=all
;allow=g729
allow=alaw
allow=ulaw
callerid="E" <2224>
nat=yes

[2225]
context=default
type=friend
secret=blah
qualify=yes
host=dynamic
canreinvite=no
dtmfmode=rfc2833
insecure=port,invite
disallow=all
;allow=g729
allow=alaw
allow=ulaw
callerid="F" <2225>
nat=yes

[2226]
context=default
type=friend
secret=blah
qualify=yes
host=dynamic
canreinvite=no
dtmfmode=rfc2833
insecure=port,invite
disallow=all
;allow=g729
allow=alaw
allow=ulaw
callerid="G" <2226>
nat=yes

修改chan_dahdi.conf,加入#include dahdi-channels.conf

$ vim  chan_dahdi.conf

[channels]
;
; To apply other options to these channels, put them before "channel".
;
signalling = fxs_ks ; in Asterisk, FXO channels use FXS signaling
; (and yes, FXS channels use FXO signaling)
channel => 1-4 ; apply all the previously defined settings to this channel
#include dahdi-channels.conf


3.4 建立简单的拨号方案

$ vim /etc/asterisk/extensions.conf

[globals]

TRUNK=DAHDI/2-1



[default]
exten => _222x,1,Verbose(2,to ${EXTEN})
	same => n,Verbose(2,from ${CALLERID(number)})
	same => n,Dial(SIP/${EXTEN},,f)
	same => n,Hangup
exten => _ZXXXXX.,1,Verbose(2,to ZXXXXX  ${EXTEN})
	same => n,Verbose(2,from ${CALLERID(number)})
	same => n,Dial(${TRUNK}/${EXTEN},,f)
	same => n,Hangup



[from-pstn]
exten => s,1,Verbose(2,INCOMING CALL ${EXTEN})
	same => n,Answer()
	same => n,Dial(SIP/2222)
	;same => n,Playback(tt-weasels)
	same => n,Hangup

TRUNK=DAHDI/2-1是全局变量,定义了电话拨出外线时将要使用的通道,本例使用第二个FSO,请确保来自PSTN的电话线插入digium卡的第二个插口。

[default] context定义了电话拨打的规则,_222x处理SIP分机之间的通话规则,而_ZXXXXX.定义了通过PSTN电话线播出的规则,本例中限制本地拨叫,如果希望拨打国内长途或者国际长途,可以修改成_XXXXXX.

[from-pstn]定义了,如果有外面的电话呼叫PSTN电话线所带的号码,自动转接到2222分机。


4.4 修改Path

修改Path的目的是为了每次避免输入 /usr/sbin/asterisk这样完整的路径,

$vim /home/asterisk/.profile

在文件的末尾加入

PATH=$PATH:$HOME/bin:/usr/sbin:/sbin

通过

$ echo $PATH

命令可以查看path是否被更改了


4.5 启动Asterisk

$ /etc/init.d/asterisk start

进入控制台,则敲入

$asterisk -rvvvvvvv


4.5 安装软电话和IP电话机

本例配备一个sip软件话机和一部IP电话机,信息如下

sip软件话:

XLite5.0, 下载地址 http://counterpath.s3.amazonaws.com/downloads/X-Lite_Win32_5.0.0_67284.exe

IP:192.168.1.102

userid:2221

asterisk server:201



Grandstream IP 电话机:

IP:192.168.1.100

userid:2222


电话启动后可以看到注册成功的信息




敲入 sip show peers 可以看到已经注册的sip账号2221 和 2222(见下图)


四、系统测试

至此,所有的配置就结束了,一个简单的IPPBX就搭建结束了,下面进行一下测试,激动人心的时刻到了。

4.1 分机拨打(2221到2222)


可以看到可以成功地拨打分机了


4.2 拨打外线 (2221到外线,如:1891890xxxx)



4.3 外线拨入 (如 1891890xxxx 到 2222)



至此,一个小型的IPPBX搭建就结束了。其中包括,分机拨打分机,分机拨打外线,外线拨打分机等功能。

当然,这样的配置是最初级的,在实际的使用过程中,需要对此进行修改和增强。在后继的文章中,我们将逐步进行讲解。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值