Está en la página 1de 18

Hng dn xy dng h thng Asterisk server

1. Yu cu phn cng
Ty theo mc ch s dng v s lng ngi dng h thng s c trang b phn cng theo cc mc khc nhau. Di y l mt khuyn ngh t cng ng s dng asterisk Mc ch Th nghim, hc tp H thng cho vn phng hoc nh ring H thng cho doanh nghip nh H thng thng mi c va v ln S lng cc knh 1-5 5-10 Ti 15 knh Hn 15 Cu hnh ti thiu 400-MHz x86, 256 MB RAM 1-GHz x86, 512 MB RAM 3-GHz x86, 1 GB RAM Dual CPUs hoc trin khai trn nhiu server

2. Ci t Asterisk
2.1. Lp t phn cng
My ch: ch thng s in th trn khe PCI phi tng thch vi cc card giao tip cn kt ni Card giao tip mng: Kt ni my ch vi mng IP Card giao tip analog: Kt ni my ch vi mng PSTN. Card ny c hai loi FXO Foreign eXchange Office Kt ni ti nh cung cp PSTN FXS Foreign eXchange Station Kt ni cc in thoi PSTN vo PBX

Hnh 1:

M hnh kt ni phn cng Asterisk server

Thng tin v cc loi card cng nh gi c ca chng c th tham kho ti trang web http://www.digium.com Hin ti ti s dng hai card nghin cu v xy dng ti liu ny l card TDM400P. (01 card 4 port FXO TDM04B v 01 card 4 port FXS TDM40B)

2.2. Yu cu phn mm
H iu hnh: Linux based. th nghim v xy dng ti liu ny, ti s dng bn phn phi Redhat linux 9.0 Gi phn mm asterisk: Download t asterisk. http://www.asterisk.org/downloads Zapata driver zaptel trong trng hp s dng cc card kt ni FXO/FXS ni vi mng PSTN. Nu h thng ko s dng cc card ny (ch l IP n thun) th c th s dng module ztdummy thay th. Zapata driver c th download ti http://downloads.digium.com/pub/telephony/zaptel/ Cc yu cu v th vin v trnh bin dch: Trnh bin dch gcc phin bn 3.x tr ln Gi m ngun nhn kernel-source (vi phin bn nhn 2.4) Th vin bison: gip asterisk phn tch cu lnh CLI Th vin openssl v openssl-devel tr gip vic m ha Th vin libnewt v gi devel lin quan bin dch zaptel driver Tm li: Cc gi phn mm cn thit thi im hin ti bao gm

asterisk-1.4.4.tar.gz zaptel-1.4.2.1.tar.gz Cc gi rpm cn ci t thm cho bn RedhatLinux 9.0 (nu cha ci) gcc-3.2.2-5 bison-1.35-6 openssl-devel-0.9.7a-2 openssl-0.9.7a-2 newt-0.51.4-1 newt-devel-0.51.4-1 kernel-source-2.4.20-8 Ch khi ci cc gi trn s c thng bo cn ci t mt s gi khc lin quan.

2.3. Bin dch v ci t


n gin, ta copy cc file nn vo th mc /usr/src ri dng lnh sau gii nn : cd /usr/src/ tar -zxvf zaptel-*.tar.gz tar -zxvf asterisk-*.tar.gz Sau khi gii nn, ta c cc th mc cha m ngun tng ng. Thc hin bin dch v ci t cho vi tng gi ny nh cc phn di y

2.3.1. Bin dch v ci t Zaptel


Asterisk s dng module chan_zap giao tip vi nhn h iu hnh v iu khin phn cng. Giao din iu khin zaptel l mt module ng c np vo nhn h iu hnh. y chng ta s bin dch v s dng hai module chnh l zaptel.o v wctdm.o bin dch c module zaptel trong vi nhn h iu hnh Redhat Linux 9.0 (bn nhn 2.4), trnh bin dch cn tm kim cc file tiu v th vin kernerl-source ti th mc /usr/linux-2.4. Tuy nhin, gi kernel-source li t cc file ny trong th mc /usr/src/linux-2.4.20-8. Vy nn cn to mt slink vi tn linux-2.4 n th mc ny nh sau:

ln s /usr/src/linux-2.4.20-8 /usr/srv/linux-2.4 Trc khi bin dch, ta c th thay i mt s tham s trong file zconfig.h. Cc tham s ny s nh hng n hot ng ca trnh iu khin sau khi bin dch. Mt s tham s c th thay i v tnh nng ca chng c m t trong bng sau: Tnh nng Cu hnh mc nh
/* #define BOOST_RINGER */ /* #define CONFIG_CALC_XLAW */ /* #define CONFIG_ZAPTEL_MMX */ /* #define ECHO_CAN_STEVE */ /* #define ECHO_CAN_STEVE2 */ /* #define ECHO_CAN_MARK */ #define ECHO_CAN_MARK2 /* #define ECHO_CAN_MARK3 */ /* #define AGGRESSIVE_SUPPRESSOR */ /* #define NO_ECHOCAN_DISABLE */ /* #define CONFIG_ZAPATA_NET */ /* #define CONFIG_ZAPATA_PPP */ /* #define CONFIG_ZAPTEL_WATCHDOG */ #define DEFAULT_TONE_ZONE 0 /* #define CONFIG_CAC_GROUNDSTART */ /* #define TDM_REVH_MATCHALL */

Boost ringer Disable -law/A-law precomputation Enable MMX optimization Choose echo cancellation method

Enable aggressive suppression Disable echo cancellation Enable HDLC Enable ZapRAS Enable Zaptels watchdog Set default tone zone Enable CAC ground start signaling TDM400P Revision H PCI ID workaround

Thng tin c th v tnh nng cng nh ti u ha thit b da trn cc tham s ny s c tm hiu v trnh by trong mt phn khc. n gin, ti s dng thng s mc nh bin dch v ci t module zaptel. Cc lnh bin dch v ci t nh sau: cd /usr/src/zaptel-version make distclean ./configure make make install make config

Lu vi lnh ./configure, chng ta c th thm vo mt s tham s. bit chi tit cc tham s ny, g lnh ./configure help. Lnh make config s to script trong th mc khi ng h iu hnh np module vo nhn khi h thng khi ng. Vi lnh make instal, module zaptel v mt s ng dng s c ci t vo h thng trong c hai cng c h tr rt hiu qu l ztcfg v zttool. Cng c ztcfg dng kim tra v cu hnh thit b da trn file cu hnh /etc/zaptel.conf. Cng c zttool c s dng kim tra trng thi ca thit b. S dng lnh man xem thng tin chi tit v hai chng trnh ny. bt u khi ng trnh iu khin thit b, ti s dng lnh sau y: /etc/init.d/zaptel start kim tra module zaptel c np vo b nh cha, ta dng lnh lsmod. Kt qu lnh thc lsmod ca ti nh sau:

Ch cc dng gch chn chnh l module iu khin thit b zaptel Ta c th thay i tham s ca module wctdm bng lnh modprobe ti u ha hot ng ca module ny. Vn ny s c tm hiu v trnh by sau.

2.3.2. Bin dch Asterisk


bin dch v ci t mc nh, ta thc hin cc lnh sau cd /usr/src/asterisk-version make distclean ./configure make make install

make samples Lnh make samples s to ra cc file cu hnh mu vi cc tham s mc nh gip cho vic thit lp v ci t asterisk c nhanh chng v d dng hn. Chng ta s iu chnh cc tham s ny trong cc phn sau. Sau khi bin dch v ci t thnh cng, chng ta c th khi ng v s dng Asterisk vi cc tham s mc nh nh trn. C nhiu cch khi ng asterisk nhng cch n gin nht l thc hin lnh sau: /usr/sbin/asterisk vo ch dng lnh ca asterisk ta dng mt trong hai cch sau /user/sbin/asterisk cvvvv Nu asterisk cha chy hoc /user/sbin/asterisk rvvvv Nu asterisk ang hot ng to cc script khi ng asterisk khi boot h thng, s dng lnh sau khi make install make config

3. Thit lp cu hnh Asterisk server


3.1. Cu trc th mc ca Asterisk
Asterisk s dng mt s th mc trong h thng file Linux lu tr cc lnh thc thi, d liu v cc tham s cu hnh. V tr v tn cc th mc ny c th thay i khi ta bin dch h thng (khi chy lnh configure trc khi make g ./configure help xem chi tit). Theo mc nh, Asterisk s dng cc th mc sau: /etc/asterisk: Cha cc file cu hnh ca Asterisk (tr file zaptel.conf c t ti th mc /etc) /usr/lib/asterisk/modules: Cha cc module ng ca Asterisk server. Cc module ny s c np khi chy hoc khi ng li dch v /var/lib/asterisk: Cha cc file v mt s th mc d liu phc v cho hot ng ca Asterisk nh cc file sound, cc file thc thi kch bn cuc gi, kha m ha d liu /var/spool/asterisk/: Cha mt s file v th mc lin quan n hot ng ca Asterisk server nh lu tr voice mail, ghi nh cuc gi

/var/run/: Cha file ghi process ID ca Asterisk server phc v vic qun l tin trnh /var/log/asterisk/: Cha cc file log hot ng ca Asterisk server trong c th mc /var/log/asterisk/cdr-csv cha d liu phc v vic ghi cc s dng Ngoi ra, cc lnh thc thi ca Asterisk server c lu tr trong cc th mc ca h thng nh /usr/sbin, /user/lib

3.2. Cc file cu hnh ca Asterisk


Ngoi tr file cu hnh thit b zaptel.conf, cc file cha cc tham s cu hnh ca Asterisk server u c t trong th mc /etc/conf (theo mc nh). Asterisk s dng rt nhiu tham s cu hnh trong cc file khc nhau thit lp cc tham s hot ng ca dch v nh tham s tr li t ng (amd.conf), tham s phc v ghi cc (cdr.conf), tham s m ha (codecs.conf). y ti ch xin tp trung vo mt s file cu hnh chnh quyt nh n hot ng ca Asterisk server nh kch bn cuc gi, d liu ngi dng, kt ni PSTN Cc tham s khc c th thit lp mc nh nh lnh make samples nh hng dn phn trn. Chng ta s cn xem xt cc tham s cu hnh trong cc file sau: zaptel.conf : Cc tham s cu hnh cho trnh iu khin card giao tip zapata.conf : Cu hnh cho asterisk giao tip vi phn cng extensions.conf : Thit lp cc kch bn cuc gi sip.conf : Thng tin cu hnh ngi dng v giao thc bo hiu SIP iax.conf : Thng tin cu hnh ngi dng v cuc gi theo knh IAX

Ch khi thay i cc tham s trong cc file cu hnh trn, cn khi ng li Asterisk server dch v hot ng vi cc tham s mi.

3.3. Cu hnh card giao tip zaptel


Trong th nghim ny, ti s dng hai server lp t hai card zaptel khc nhau l card 4 cng FXO TDM04B v card 4 cng FXS TDM40B. Nh trnh by trn, cng FXO c s dng kt ni vi ng dy ca nh cung cp dch v in thoi, cng FXS c s dng kt ni cc in thoi analog thng thng vi Asterisk server. im khc bit d nhn bit nht gia hai loi cng ny l cng FXS cung cp m quay s (dial tone) trong khi cng FXO th khng c. Do vy khi ta kt ni mt in thoi analog vo cng FXS, ta s thy m ch quay s in thoi trong khi nu ni vo cng FXS th s khng c m ny. Chnh v vy, khi gn card c cng FXS vo my tnh, cn phi cp ngun cho cc cng FXS card ny c th pht m quay s v pht bo hiu chung ti in thoi. Trn module FXS c cng kt ni ngun in t my tnh v vy cn ch kt ni ngun cho module ny.

Cc cng giao tip s c nh ngha v xc nh da vo kiu bo hiu n s dng trong file cu hnh zaptel.conf. Cng FXO s c khai bo s dng kiu bo hiu FXS v tng ng cng FXS s c khai bo s dng kiu bo hiu FXO. Di y, ti xin trnh by vic cu hnh vi tng loi cng giao tip v th nghim chng theo tng bc Cu hnh file zaptel.conf Cu hnh file zapata.conf t kch bn cuc gi Kim tra hot ng

3.3.1. Cu hnh cng FXO


Cc tham s ti thiu cn t trong file /etc/zaptel.conf nh sau: fxsks=1,2,3,4 loadzone=us defaultzone=us Dng u tin ch ra bo hiu s dng l fxsks cho cc cng t 1 n 4 (do ton b 4 cng ca card u l FXO). FXS ch ra kiu bo hiu cn KS l loi giao thc. C ba loi giao thc nh sau: Loop start (ls): Ground start (gs): Kewlstart (ks): Ti u loop start vi kh nng nhn bit kt ni xa hn v thng c la chn lm giao thc bo hiu mch analog cho asterisk Tham s loadzone ch ra tp cc tham s nh nhc chung, bo bn c s dng cho cc cng tng ng. Tham s defaultzone s c s dng nu khng t loadzone cho cng ny. Sau khi thit lp cu hnh zaptel, np li module cho thit b bng lnh sau: /etc/init.d/zaptel restart Hoc np trc tip module vo nhn modprobe wctdm

Ch : C th lnh khi ng trn s gp thng bo bn do module ang c s dng bi Asterisk. Nu gp thng bo ny, ta tt chng trnh asterisk bng lnh sau: killall -9 asterisk Ri thc thi li cc lnh trn Sau khi np c module, kim tra li h thng bng lnh ztcfg: ztcfg vv Sau y l kt qu ca ti:

Tip theo, ta s cu hnh cho Asterisk giao tip vi card zaptel bng cc tham s trong file zapata.conf nh sau: [trunkgroups] ; nh ngha cc nhm trung k ti y. Mc nh c th b qua

[channels]

; Cc gi tr mc nh usecallerid=yes hidecallerid=no callwaiting=no threewaycalling=yes transfer=yes

echocancel=yes echotraining=yes

; nh ngha cc cng context=incoming signalling=fxs_ks channel => 1 ; Cuc gi n s ng vi context [incoming] ; Dng kiu bo hiu FXS cho cng FXO ; ng thoi PSTN gn ti cng s 1 ; nh ngha ID cho cuc gi n

callerid=incoming <123>

Khi c cuc gi n cng s 1, Asterisk server s phi thc thi cc tc v p ng cuc gi. Nh cu hnh trn, Asterisk server s tm n kch bn cuc gi ti context [incoming] trong file extension.conf. to kch bn test, trong file extension.conf ta thm mt kch bn nh sau: [incoming] ; incoming calls from the FXO port are directed to this context from zapata.conf exten => s,1,Answer( ) exten => s,2,Echo( ) Vi kch bn trn, cc cuc gi n s c kt ni vi mt b lp nhc li li ngi gi. kim tra card, s dng lnh zttool theo di hot ng ca thit b, khi kt ni line thoi vo cng s 1 th thng tin hin th ti zttool hnh di y:

Ch s 1 c gch chn hin th 01 ng kt ni.

S dng mt in thoi khc (di ng hoc c nh) gi n s thu bao ca line thoi gn vo card th Asterisk server s nhc my v khi ng b lp hot ng.

3.3.2. Cu hnh cng FXS


Cng ging nh vi cng FXO, cu hnh cng FXS c thc hin vi tham s cu hnh ti cc file nh sau File zaptel.conf fxoks=1-4 loadzone=us defaultzone=us Load li module bng lnh /etc/init.d/zaptel restart ri dng lnh ztcfg vv cho kt qu nh sau ; Ch fxoks cho cng FXS

Trong file zapata.conf [trunkgroups] ; Mc nh b qua

[channels] ; Cc gi tr cu hnh mc nh usecallerid=yes hidecallerid=no callwaiting=no threewaycalling=yes transfer=yes

echocancel=yes echotraining=yes immediate=no

; Tham s khai bo cho cng FXS context=internal signalling=fxo_ks channel => 1 ; S dng context [internel] cho cuc gi i ; Dng bo hiu FXO cho cng FXS ; in thoi ni vi cng 1

kim tra thit b, ti to mt kch bn gi lp vi s gi n l 1080 trong file cu hnh extension.conf nh sau [internal] exten => 1080,1,Answer( ) exten => 1080,2,Echo( ) Gn ng thoi t mt in thoi analog vo cng s 1 trn card, s dng cng c zttool kim tra thit b ti c kt qu nh sau: Khi cha nhc my in thoi

Khi nhc my

My in thoi pht m mi quay s, quay 1080 khi ng b lp ca Asterisk server. (Ch ch khi khi ng Asterisk server th mi c m mi quay s ti my in thoi, khi Asterisk cha khi ng th ch c tn hiu bo ti my in thoi ch khng c m mi quay s).

3.4. Cu hnh ngi dng v s dng softphone s dng


Trong phn ny, ti s trnh by v cch cu hnh thm ngi dng s dng dch v VoIP cho Asterisk server. C nhiu loi ngi dng tng ng vi cc giao thc bo hiu khc nhau c s dng trong Asterisk server tuy nhin c hai dng thng c s dng nht l SIP v IAX. SIP l giao thc bo hiu c tnh m cao, c s dng ph bin trong nhiu thit b VoIP hin ti. Tuy nhin n c mt im yu l kh nng hot ng b gii hn khi NAT gia cc lp mng khc nhau. Thng tin c th v giao thc bo hiu ny s c trnh by trong mt phn khc. Giao thc bo hiu th hai thng c s dng vi Asterisk l IAX (Inter-AsteriskeXchange). y l mt giao thc thng c s dng kt ni gia cc Asterisk server vi nhau. Ngoi ra IAX cn c s dng cho cc server dng FWD (Free World Dialup) khi ngi dng khng cn quan tm n h thng mng ca server cng nh client. Tuy nhin, khng nhiu cc thit b VoIP h tr giao thc ny.

3.4.1. Cu hnh SIP


Thng tin v SIP c t trong file cu hnh sip.conf vi cc tham s c chia lm hai phn: - Phn tham s chung: Cha cc tham s chung cho ton b Asterisk server - Phn ngi dng: Cha thng tin v tng ngi dng File sip.conf cha cc tham s n gin nht s nh sau: [general] context=default srvlookup=yes

;Phn sau khai bo ngi dng huydd vi mt khu l matkhau [huydd] type=friend secret=matkhau

qualify=yes nat=no ; Khng s dng NAT

host=dynamic ; a ch s c xc nh khi ng k SIP canreinvite=no context=internal ; S dng context internal cho huydd

3.4.2. Cu hnh IAX


Tng t nh vi SIP, cc tham s IAX t trong file iax.conf cng bao gm hai phn chnh l phn cha tham s chung [general] v phn cho tng ngi dng. File cu hnh n gin iax s cha thng tin nh sau: [general] bandwidth=low disallow=lpc10 jitterbuffer=no forcejitterbuffer=no tos=lowdelay autokill=yes

; Khai bo ngi dng huydd_iax vi mt khu matkhau [huydd_iax] type=friend callerid=huydd_iax username=huydd_iax secret=matkhau ;Thng tin hin th khi gi n

context=internal host=dynamic

3.4.3. Cu hnh v s dng softphone


C nhiu softphone h tr SIP c th s dng vi Asterisk server m thng dng nht l sn phm Xlite v EyeBeam ca CounterPath Solutions. C th download bn dng th vi cc tnh nng c bn ti http://www.counterpath.com/xlitedownload.html cu hnh ti khon SIP cho Xlite, ta nhp cc thng s nh hnh di y:

y, my ch Asterisk c a ch tng ng vi tn min sip1.cdit.com.vn Sau khi nhp thng tin v ngi dng, Xlite s tin hnh ng k vi Asterisk server. Trong trng hp ng k thnh cng, server s hin th thng tin log (gi lnh asterisk rvvvvvv trc khi chy Xlite trn my trm hin th thng tin) nh sau

Cn trn ca s Xlite s hin th ngi dng ang ng k hin ti

Vi giao thc IAX, do c thit k ring cho bo hiu lin server nn khng nhiu softphone h tr giao thc ny. y ti s dng sn phm softphone Firefly ca hng Frehstel. Cc tham s cu hnh c thit lp cho ngi dng IAX c m t nh hnh di y:

Sau khi nhp thng tin, trn Asterisk server s hin th thng tin nh hnh di y cho bit ng k thnh cng

Ta c th dng cc softphone trn quay n s 1080 thit lp cc phn trc kim tra.

3.5. Kch bn cuc gi (dial plan)


C th coi dialplan chnh l tri tim ca h thng Asterisk. N s quyt nh Asterisk server lm g vi cc cuc gi n, cc s gi i. Thc cht, dialplan chnh l mt dy cc ch th m Asterisk server thc hin theo ng vi mt iu kin u vo tng ng vi s gi i hoc n.

Cc ch th ny c t trong file cu hnh extension.conf v cc file include lin quan c ch ra trong file extension.conf. Kch bn cuc gi trong Asterisk server c phn thnh cc vng khc nhau c gi l context. Mi ngi dng hoc cc phn t h thng thuc cc context khc nhau thc hin theo cc ch th ca context . Theo nh hng dn cu hnh cc phn trn, hin ti chng ta cn cu hnh 2 context: Internal: Cho cc thit b ni vo cng FXS v cc thu bao SIP, IAX gi ln nhau v gi qua PSTN Incoming: Cho kt ni gi vo t mng PSTN

Ngoi ra, h thng cn mt context chung cha cc tham s tng qut l general. Mi context s c t trong mt vng bt u bng k hiu tn context trong cp ngoc [], v d [incoming]. Di y ti s khai bo kch bn cuc gi phc v mc tiu sau: Cuc gi n t mng PSTN s c chuyn n a ch thu bao SIP huydd Cuc gi n cc thu bao SIP s chuyn ti ia ch tng ng Cuc gi n cc thu bao mng PSTN s bt u vi u s 9

File cu hnh extension.conf nh sau: [general] static=yes writeprotect=no clearglobalvars=no userscontext=internal

[incoming] exten => s,1,Dial(SIP/huydd)

[internal] exten => _[a-z].,1,Dial(SIP/${EXTERN},30)

exten => _[a-z].,1,Hangup()

exten => _9.,1,Dial(Zap/g1/${EXTERN:1}) exten => _9.,2,Hangup()

n y ta c th s dng softphone cng nh in thoi kim tra v th nghim h thng

4. Kt lun
Ch vi mt s thit b phn cng n gin kt hp vi asterisk, chng ta hon ton c th t chc mt tng i hon chnh th nghim dch v VoIP cng nh kt ni gia mng IP v PSTN. Hng dn trn y mi ch l mt s bc c bn thit lp h thng. Cn rt nhiu ch lin quan c th ti u cng nh lm phong ph thm kch bn dch v m ti cha c thi gian nghin cu v trnh by y. Tuy nhin ti hi vng s c dp nghin cu v trnh by thm v h thng rt th v ny. Mi thng tin trao i xin gi n huydd@cdit.com.vn