Anda di halaman 1dari 28

Asterisk Basics, and Load Balancing via DUNDi 01 July 2010

Asterisk Basics, and Load Balancing via


DUNDi
Prepared by : Vivek Kapoor http://exain.com
Prepared on : 01 July 2010
Web verion : http://exain.!ordpre.com/2010/0"/0#/aterik$baic$and$load$balancin%$via$dundi
Table of Contents
&terik 'aic( and )oad 'alancin% via *+,*i................................................................................1
Purpoe o- thi document.................................................................................................................#
&ckno!led%ement..........................................................................................................................#
*iclaimer........................................................................................................................................#
'e-ore !e be%in................................................................................................................................
/uick look at the tep......................................................................................................................
&terik 0ntallation.........................................................................................................................1
'aic 20P +er 3reation 4 5etin%.................................................................................................."
2erver &(' 4 3 : /etc/aterik/aterik.con-................................................................................"
2erver & : /etc/aterik/ip.con-..................................................................................................."
2erver & : /etc/aterik/extenion.con-......................................................................................."
2erver ' : /etc/aterik/ip.con-..................................................................................................."
2erver ' : /etc/aterik/extenion.con-......................................................................................6
5etin% the etup..........................................................................................................................6
7akin% it !ork !ith *+,*i $ 2 2erver 2etup..............................................................................10
2erver & : /etc/aterik/ip.con-.................................................................................................10
2erver ' : /etc/aterik/ip.con-.................................................................................................10
2erver & 4 ' : /etc/aterik/iax.con-.........................................................................................11
*+,*i key %eneration.............................................................................................................12
2erver & : /etc/aterik/dundi.con-............................................................................................12
2erver ' : /etc/aterik/dundi.con-............................................................................................1#
2erver & : /etc/aterik/extenion.con-.....................................................................................1.
2erver ' : /etc/aterik/extenion.con-....................................................................................11
5etin% the etup........................................................................................................................11
7ore *+,*i $ # 2erver 2etup......................................................................................................16
2erver & : /etc/aterik/dundi.con-............................................................................................16
2erver ' : /etc/aterik/dundi.con-............................................................................................18
2erver 3 : /etc/aterik/dundi.con-............................................................................................18
5etin% the # 2erver 2etup.........................................................................................................21
&ddin% 9eal5ime to it...................................................................................................................22
2ettin% up 7y2/) 2erver.........................................................................................................22
2erver & : /etc/aterik/re:my;l.con-.....................................................................................2#
2erver ' : /etc/aterik/re:my;l.con-.....................................................................................2.
2erver & 4 ' : /etc/aterik/extcon-i%.con-...............................................................................2.
2erver & 4 ' : /etc/aterik/ip.con-.........................................................................................2.
5etin% 9eal5ime 2etup............................................................................................................2.
Page 1 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
What< next.....................................................................................................................................2=
>nablin% actual callin% out........................................................................................................2=
+in% extenion in 9eal5ime...................................................................................................2=
2ecurin% the etup.....................................................................................................................2"
*o load balancin% 4 -ail over...................................................................................................26
Page 2 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
Purpose of this document
&terik i an open ource P'?. Which mean( you can etup your o!n little telephone exchan%e in
your home/o--ice environment. @n a much lar%er ua%e( you may look -or!ard to ettin% up a
redundant phone etup !herein multiple boxe are interconnected !ith each other and provide ome
ort o- -ailover capability and eaier mana%ement( !hich i poible throu%h omethin% called
*+,*i. 5hi document aim to provide uch a olution !ith a poibility o- horiAontal calin%
intead o- vertical calin%. 2o( thi may mean that by uin% lo!$end commodity hard!are( you can
etup a tron% telephone in-ratructure !hich can cater to thouand o- uer.
9ead the document care-ully. 9ead it -ully be-ore you tart implementin% it. 0t i intentionally
detailed o that you kno! !hat you<re doin%.
Acknoledgements
&ll credit o- thi document %oe to J9 9ichardon. 0<m a-raid 0<ve not been able to -ind a uitable
link -or him( but hi !hitepaper and preentation are the one !hich helped me move -or!ard.
&nd o- coure( 7ark 2pencer $ the %uy behind &terik. Without him thi document !ouldn<t have
exited.
5he !ritin% by J9 9ichardon
http://!!!.voip$in-o.or%/tora%e/uer/61#/."61#/ima%e/1=1./*+,*i:2o:>ay.pd-
http://atlau%.com/tu--/Preentation/&tricon0=/J9:9ichardon:Whitepaper.pd-
Disclaimer
5hou%h 0 have i%ni-icant experience doin% )inux and related ytem( but 0<m more o- a novice in
&terik. 5he -ollo!in% may or may not !ork -or you. 0 don<t provide any !arranty !hatoever o- it
bein% ucce-ul( or rather( conitently ucce-ul( and providin% an actual load balanced olution.
0<ve yet to implement it in a production etup( and hence all you do i at your o!n rik. 5he belo!
procedure 2B@+)* !ork( but 0 3&,,@5 ay that it W0)) !ork.
Page 3 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
Before e begin
& little about the nomenclature
Asterisk : http://aterik.or% 0t i a P'? CPrivate 'ranch >xchan%eD o-t!are !hich run on
)inux plat-orm. 0t allo! you to have V@0P -acility !ithout incurrin% cot on proprietary
hard!are( and can run o-- a home dektop ytem.
DUNDi : http://dundi.com *+,*i i a peer$to$peer ytem -or locatin% 0nternet %ate!ay to
telephony ervice. +nlike traditional centraliAed ervice Cuch a the remarkably imple
and concie >,+7 tandardD( *+,*i i -ully$ditributed !ith no centraliAed authority
!hatoever. We !ill be uin% it to interconnect multiple aterik boxe and ettin% up a load
balanced environment !hich !ill alo act a a -ailover.
SIP Softphone : & o-tphone runnin% -rom your dektop !hich allo! you to re%iter to
aterik and enable V@0P communication. 0( -or thi document( ue Eoiper $
http://Aoiper.com
RealTime : http://!!!.voip$in-o.or%/!iki/vie!/&terikF9eal5ime 0t !ill allo! u to
connect to 7y2/) and have the uer re%itered in there intead o- bein% hard coded in ip
con-i%uration. 5hi !ay it !ill be poible to have uer re%iter to any re%itration erver
and not Gut one on !hich they<re con-i%ured.
Hou need to have ome experience related to )inux ytem. Hou hould be com-ortable in
compilin% application -rom cratch. 5he method mentioned in thi email hould !ork a i( but i-
there are iue( then you !ould be reolvin% them on your o!n. &lo( it i hi%hly recommended to
have ome !orkin% kno!led%e about &terik. Hou hould have etup ome &terik baed
environment $ i- you<ve not done that yet( then 0 think you hould -irt concentrate on that. Hou<ll be
deli%hted to ee !hat all i poible throu%h &terik.
!uick look at the steps
5o make it !ork !ith the minimum con-i%uration( !e<ll proceed tep by tep o that !e don<t mi a
thin%. 5hi mean !e<ll not Gump trai%ht$a!ay to the -ully -unctional *+,*i etup( but do it
lo!ly( undertandin% each tep a !e do it. Bere< ho! !e<ll move -or!ard
1. 0ntallation o- &terik on a *ebian/+buntu ytem C2 ytem initially( later #D
2. 'aic 20P +er 3reation 4 5etin%
#. 7akin% it !ork !ith *+,*i $ 2 2erver 2etup
.. 7ore *+,*i $ # 2erver 2etup
1. &ddin% 9eal5ime to it
=. What< next
Page 4 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
Asterisk "nstallation
1. Hou need to have atleat 5W@ !orkin% *ebian/+buntu machine. 0 !ill be uin% 5B9>>
machine eventually( but !ill tart !ith t!o. 5hou%h the -ollo!in% !ould !ork -or any
)inux ditribution available( the tep related to intallation and initialiAation o- packa%e
could vary $ o you may re-er to the documentation o- your ditribution.
2. 0 am uin% Virtual 7achine runnin% via KV7 -or thi exercie. Hou may ue Virtualbox(
?en( or any o- your pre-erred olution. Bere< the baic tructure
2erver &( 0P: 182.1=6.1.1( 7&3 &ddre: 00:1=:#=:88:1.:=2
2erver '( 0P: 182.1=6.1.=( 7&3 &ddre: 00:1=:#=:2-:11:8c
2erver 3( 0P: 182.1=6.1.10( 7&3 &ddre: 00:1=:#=:=e:d":dc
#. 5hree packa%e are re;uired -rom the aterik !ebite( the aterik packa%e itel-( dahdi 4
aterik$addon -or my;l upport. Iet them -rom http://aterik.or% $ 0 choe the -ollo!in%
verion !hich !ere the latet at the time o- !ritin% thi article
aterik$1.=.2.6.tar.%A
dahdi$linux$complete$2.#.0.1F2.#.0.tar.%A
aterik$addon$1.=.2.1.tar.%A
.. 5he intallation tep are a under. 5he aterik intallation document are readily available
on the internet( o you may try out a more detailed one. Bere< !hat !ill %et you tarted
1. 0ntall the pre$re;uiite -irt
apt-get install linux-headers-$(uname -r) build-essential automake
autoconf bison flex libtool libncurses5-dev libssl-dev libgsm1
libgsm1-dev libgsmme-dev libgsm-tools libxml2-dev libmysqlclient-
dev
=. +ntar all the do!nloaded packa%e Caterik( dahdi and aterik$addonD into /ur/local/rc
and then one by one run the -ollo!in%
!ahdi "irst
cd dahdi-linux-complete-2#$#%#1&2#$#%
make clean
make
make install
make config
'o( for )sterisk
cd asterisk-1#*#2#+
make clean
#,configure
make install
make samples
make config
-ast. the asterisk add-ons (important for /y01- support)
cd asterisk-addons-1#*#2#1
make clean
#,configure
make menuselect 2ptional - 3 usually disable h$2$ support
make
make install
make samples
Page of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
". *&B*0 may re;uire ome do!nloadin% -rom the 0nternet( o make ure you have the
machine connected to the 0nternet( or ue a proxy by uin%
export http4proxy5http6,,your#proxy#ip6port
6. 5hat< all. &terik i con-i%ured. Hou may run the -ollo!in% to veri-y.
,etc,init#d,asterisk start
asterisk -r
,etc,init#d,asterisk stop
Page ! of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
Basic #"P User Creation $ Testing
Jor each -ile lited belo!( certain chan%e are done. Hou can name a per your convenience( but it
hould match in all the relevant ection -urther in the document.
#erver A,B $ C % &etc&asterisk&asterisk'conf
+ncomment the -ollo!in%
verbose 5 17
#erver A % &etc&asterisk&sip'conf
8general9
srvlookup5no
'):5yes
bindport55%*%
allo(guest5no
canreinvite5no
81%%19
type5friend
context5internal
host5dynamic
disallo(5all
allo(5gsm
canreinvite5no
qualify5yes
Hou can chan%e bindport a per the re;uirement. 0- you happen to chan%e the bindport to( ay(
10"0( then !hile con-i%urin% Eoiper( in the domain ection( !rite omethin% like 182.1=6.1.1:10"0
#erver A % &etc&asterisk&e(tensions'conf
8general9
static5yes
(riteprotect5no
autofallthrough5yes
clearglobalvars5no
priority;umping5no
8internal9
exten 5< 12$.1.=layback(demo-congrats)
exten 5< 12$.n.>angup()
#erver B % &etc&asterisk&sip'conf
8general9
srvlookup5no
'):5yes
Page " of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
bindport55%*%
allo(guest5no
canreinvite5no
81%%29
type5friend
context5internal
host5dynamic
disallo(5all
allo(5gsm
canreinvite5no
qualify5yes
#erver B % &etc&asterisk&e(tensions'conf
8general9
static5yes
(riteprotect5no
autofallthrough5yes
clearglobalvars5no
priority;umping5no
8internal9
exten 5< 75*.1.=layback(demo-congrats)
exten 5< 75*.n.>angup()
Testing the setup
What !e ee above i that there are t!o erver( 2erver & and 2erver '. 2erver & ha 20P uer 1001(
and 2erver ' ha 1002. 'oth the uer belon% to a context called KinternalK( !hich probably mean
that !hen they dial in any extenion( the -irt context that they<ll hit i KinternalK( and -rom there
on!ard they<d be redirected to other context a per the dial plan.
5he context KinternalK i de-ined in Kextenion.con-K -ile. 5here< not much in that context except
one in%le extenion( 12# in 2erver & and .1= in 2erver '. When that extenion i called( a
con%ratulation mea%e i played. 2o to tet it( 0 have ued an application called Eoiper !hich
allo! t!o line to be connected. Hou can do!nload Eoiper -rom http://!!!.Aoiper.com/o-tphone/
$ 0 ued Eoiper 3laic -or )inux.
)et< tart aterik -irt on 2erver & 4 2erver ' by uin%
,etc,init#d,asterisk start
and then connect to an aterik eion by uin%
asterisk -r
0 created t!o 20P account in Eoiper( -or 2erver & 0 entered 182.1=6.1.1 a domain( and 1001 a
uername( and -or 2erver ' 0 entered 182.1=6.1.= a domain and 1002 a uername. 9et o- the
detail can be added a per your pre-erence. 0 deelected the K9e%iter on tartupK option under
advanced ettin%. 5hen on the Eoiper inter-ace 0 re%itered to both the erver.
Page 8 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
@n 2erver &( omethin% like the -ollo!in% hould appear !hen you lit the ip peer
?-3< sip sho( peers
'ame,username >ost !yn 'at )?- =ort 0tatus
1%%1,1%%1 xx#xx#xx#xx ! ' 5%*% 2@ (11* ms)
1 sip peers 8/onitored6 1 online. % offline Anmonitored6 % online. % offline9
?-3<
2ame %oe -or 2erver '. 0t hould ho! omethin% like the -ollo!in%
?-3< sip sho( peers
'ame,username >ost !yn 'at )?- =ort 0tatus
1%%2,1%%2 xx#xx#xx#xx ! ' 5%*% 2@ (1$7 ms)
1 sip peers 8/onitored6 1 online. % offline Anmonitored6 % online. % offline9
?-3<
,o! elect in Eoiper( the 2erver & &ccount and dial 12# $ it hould playback the con%ratulation
mea%e. 0- you try to dial .1=( it<ll not !ork. 'ut i- you elect 2erver ' in the &ccount( and then
dial .1=( it hould !ork a expected.
& ample creenhot o- Eoiper i belo!
&lo check the mea%e that appear in the conole that you<d opened earlier Cby uin% aterik $rD.
& ample o- the ame on 2erver & i a under
?-3<
55 Asing 03= B:= ?o0 mark 5
-- Cxecuting 812$Dinternal619 =layback(E03=,1%%1-%%%%%%%1E. Edemo-
congratsE) in ne( stack
-- F03=,1%%1-%%%%%%%1< =laying Gdemo-congrats#gsmG (language GenG)
-- Cxecuting 812$Dinternal629 >angup(E03=,1%%1-%%%%%%%1E. EE) in ne( stack
55 0pa(n extension (internal. 12$. 2) exited non-Hero on G03=,1%%1-%%%%%%%1G
?-3<
2o( our baic con-i%uration i !orkin% -ine. 0- you add more 20P uer in ip.con- -ile( and add
relevant extenion in extenion.con- -ile( then you can have a in%le erver P'? runnin% per-ectly
-ine. 0t i important to have the above !orkin% o that !e can be ure that our etup i ready -or
*+,*i.
Page # of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
)aking it ork ith DUNDi * + #erver #etup
'e-ore !e delve -urther into *+,*i( pleae remember that the mot important thin% here i
KcontextK. 0- you peci-y them incorrectly( it !ouldn<t !ork a expected and you<ll be le-t
!onderin% !hat< happenin%.
)et< be%in no! in a t!o erver con-i%uration. 5he purpoe here i that extenion 1001 !ould be
re%itered on 2erver &( and 1002 on 2erver '. 'ut( via *+,*i( 2erver & !ould kno! that
extenion 1002 i on 2erver '( and !ould e--ectively be able to call it too.
#erver A % &etc&asterisk&sip'conf
&dd a ne! context Cre%context to be precieD called KdundiextenK in the L%eneralM ection. 0t< a
pretty imple -ile
8general9
regcontext5dundiextens
srvlookup5no
'):5yes
bindport55%*%
allo(guest5no
canreinvite5no
81%%19
type5friend
context5internal
host5dynamic
disallo(5all
allo(5gsm
canreinvite5no
qualify5yes
5he regcontext parameter i very important here. 0t auto$create a context a oon a a 20P uer lo%
in Cin our cae the context !ill be dundiextenD. 5hi i ued and earched by *+,*i to %et to the
deired extenion. )ater !e<ll ee ho! to vie! the uer !ho belon% to KdundiextenK context.
#erver B % &etc&asterisk&sip'conf
2imilar to 2erver &( the ne! context ha to be added. 5he -ollo!in% !ould be the -inal ip.con- -or
2erver '.
8general9
regcontext5dundiextens
srvlookup5no
'):5yes
bindport55%*%
allo(guest5no
canreinvite5no
81%%29
type5friend
context5internal
Page 1$ of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
host5dynamic
disallo(5all
allo(5gsm
canreinvite5no
qualify5yes
#erver A $ B % &etc&asterisk&ia('conf
We !ill be uin% 0&?2 trunk to interconnect the *+,*i boxe. 0&?2 doen<t !ork too !ell in
virtual machine a it re;uire a timin% device/timin% ource. Jor me it didn<t !ork !ell a -ar a
PlaybackCD !a concerned( but !hen doin% a voice call everythin% eemed to be Gut -ine. 0<ve not
been able to -i%ure out i- it< a timin% device/virtual machine iue or it< Gut ome ettin% in
iax.con- that need to be done. 0- 0 run dahdi:tet in a virtual machine( the reult are al!ay above
88.=N. 5he ame i !ith a dedicated machine( o 0 %ue the timin% ource eem to okay.
5ried uin% 20P 5runk alo( but it caue a number o- iue !hen doin% 9eal5ime. When uin%
9eal5ime the uer !ere re%itered multiple time on &terik box( o 1001 !hich !a initially
re%itered on 2erver & %ot re%itered on 2erver ' a !ell. &lo( 0 !an<t able to -i%ure out a !ay to
end a call -rom 2erver & to a particular context on 2erver '. 0t alo caued a bit o- calability
iue a !ell ince i- uin% dedicated trunk then 0<d have to provide each erver< detail in
ip.con- o- all erver. 2o !hen a ne! erver i added( the ip.con- !ould need to be updated on all
the erver( !hich in<t that ele%ant Cbecaue then ip reload !ould alo be calledD.
Bere< the content o- the Kiax.con-K -ile !here LiaxuerM i added. 0t< the ame on each erver
8general9
;itterbuffer5no
nochecksums5no
disallo(5all
allo(5gsm
8iaxuser9
type5friend
dbsecret5dundi,secret
context5incomingdundi
2o( a !e ee( there are three context !e<ve encountered till no!. 3ontext KinternalK( !hich i
aociated !ith the 20P uer bein% re%itered( context KdundiextenK !hich i auto$created a oon
a the -irt uer re%iter on a particular erver( and latly context Kincomin%dundiK $ thi i ued
!hen a call arrive via the 0&? trunk. &ll thee have to be mentioned in extenion.con- o- each
erver.
0- you notice( there< a parameter KdbecretK in the -ile. 0 %ue it allo! one erver to authenticate to
another by uin% a uername/pa!ord combination. 5he advanta%e i that it< Gut a
uername/pa!ord authentication and not any erver in-ormation hard coded. Which ha the bet
advanta%e that i- any ne! erver i added to the cluter( it<ll automatically be authenticated. &lo( 0
had read ome!here( probably in the link belo!( that Kdundi/ecretK value -or KdbecretK i to be
taken literally $ you houldn<t be chan%in% it.
0- you !ant to read about uin% 0&? and 20P trunk in *+,*i( you can re-er to the -ollo!in%
http://!!!.voip$in-o.or%/!iki/vie!/*+,*iF>nterprieF3on-i%urationF0&?
Page 11 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
http://!!!.voip$in-o.or%/!iki/vie!/*+,*iF>nterprieF3on-i%urationF20P Cthi doen<t
!ork yetD
http://!!!.voip$
in-o.or%/!iki/vie!/*+,*iF>nterprieF3on-i%urationF20PF!ithFnoFpa!ord
DUNDi ke, generation
'e-ore !e proceed -urther( !e !ill need to create a couple o- key on one erver( and 3@PH it to
another erver. 0 haven<t tried creatin% di--erent key( o cannot con-irm other!ie.
@n 2erver &( %o to /var/lib/aterik/key directory( and execute the -ollo!in%
astgenkey -n dundi
and !hen it ak -or prein% >,5>9( Gut do that. & couple o- -ile !ould be created in that
directory $ dundi.key 4 dundi.pub. 3opy both the -ile to 2erver ' in the ame directory $
/var/lib/aterik/key. 5hi eentially mean that dundi.key and dundi.pub are identical on both the
erver( and !ould remain identical a ne! erver Goin the cluter.
#erver A % &etc&asterisk&dundi'conf
dundi.con- ha three primary ection( L%eneralM( Lmappin%M and peer in-ormation to !hich it can
place ;uerie. Bere< !hat need to be in dundi.con-
I =art 1
8general9
department5Jour !epartment
organiHation5Jour ?ompany. 3nc#
locality5Jour ?ity
stateprov50:
country5A0
email5yourDemail#com
phone5&125*5551212
bindaddr51K2#1*+#1#5
port5752%
entityid5%%61*6$*6KK6576*2
cachetime55
ttl52
autokill5yes
I =art 2
8mappings9
priv 5< dundiextens.%.3)L2.iaxuser6$M0C?BC:ND1K2#1*+#1#5,$M'A/OCBN.nopartial
I =art $
8%%61*6$*62f6116Kc9 I /)? )ddress of 0erver O
model 5 symmetric
host 5 1K2#1*+#1#* I(this is the 3= address of the !A'!i 0erver O)
inkey 5 dundi
outkey 5 dundi
include 5 priv
permit 5 priv
Page 12 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
qualify 5 yes
order 5 primary
)et< move to each item tep by tep
Part 1 $ 5he L%eneralM ection i el- explanatory. Jollo!in% point hould be looked into
bindaddrO182.1=6.1.1 P$ 5he 0P &ddre o- your exitin% machine
entityidO00:1=:#=:88:1.:=2 P$ 5he 7&3 addre o- the inter-ace -or 182.1=6.1.1. Bo!ever(
it could be any mac addre that you o!n( that i( it hould be omethin% uni;ue.
cachetimeO1 P$ 'etter to have it at 1 econd than #=00 econd i- it< a cloed %roup
net!ork. 0- there< a -ailure o- one erver( the re$re;uet hall be redirected to other erver
a-ter 1 econd have elaped. 7ay not be %ood i- you<re connectin% to outide erver not in
your domain a it ha to potential -or -re;uent ;uerie i- there< heavy tra--ic.
ttlO2 P$ 5he number o- *+,*i lookup re;uet made. 2o( i- re;uet %oe to 2erver ' -rom
2erver &( then that< one re;uet. ,o! 2erver ' can make a maximum o- 1 more re;uet to
other erver it ha paired !ith.
Part 2 $ 5he Lmappin%M ection de-ine !hat you !ill provide a the contact addre !hen another
erver %et in touch !ith you. 2o( i- a 20P extenion i re%itered !ith you( you !ill provide the
erver akin% -or that extenion a complete path to your machine. 0- !e break the -ollo!in%
tatement(
priv 5< dundiextens.%.3)L2.iaxuser6$M0C?BC:ND1K2#1*+#1#5,$M'A/OCBN.nopartial
& per the documentation( here KprivK i the *+,*i context and !ill be ued by *+,*i. We<ll ee
later ho! it< ued in extenion.con- -ile. 5hen come the local context !hich it<ll earch. 0n our
cae it< KdundiextenK !hich !e de-ined in ip.con- under the re%context parameter. 5hen i the
!ei%ht( the technolo%y bein% ued( the detination that i to be ent to the erver re;uetin%
in-ormation( and then -urther option. Hou can revie! *+,*i documentation at http://!!!.voip$
in-o.or%/!iki/vie!/*+,*i -or more detail on each o- the parameter.
Part # $ 5hee are the peer that you<ll re%iter !ith -or lookin% up / doin% *+,*i earchin%. 2o( i-
you have multiple erver( then you<ll need to have multiple peer de-inition imilar to the one
mentioned earlier. 2ince !e<re uin% only one 2erver C2erver ' D a the peer( !e<ve entered that
in-ormation in dundi.con-. 0 think the 7&3 addree are more -or conitency than any technical
veri-ication( o you hould be able to connect machine outide your net!ork too $ acro the %lobe
maybe.
#erver B % &etc&asterisk&dundi'conf
0n continuation to the concept above( !e<ll add the dundi.con- -or 2erver '. Bere< an example
I =art 1
8general9
department5Jour !epartment
organiHation5Jour ?ompany. 3nc#
locality5Jour ?ity
stateprov50:
country5A0
Page 13 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
email5yourDemail#com
phone5&125*5551212
bindaddr51K2#1*+#1#*
port5752%
entityid5%%61*6$*62f6116Kc
cachetime55
ttl52
autokill5yes
I =art 2
8mappings9
priv 5< dundiextens.%.3)L2.iaxuser6$M0C?BC:ND1K2#1*+#1#*,$M'A/OCBN.nopartial
I =art $
8%%61*6$*6KK6576*29 I /)? )ddress of 0erver )
model 5 symmetric
host 5 1K2#1*+#1#5 I(this is the 3= address of the !A'!i 0erver ))
inkey 5 dundi
outkey 5 dundi
include 5 priv
permit 5 priv
qualify 5 yes
order 5 primary
@ur *+,*i con-i%uration i complete. ,o! 2erver & ha 2erver ' a *+,*i peer( and vice vera.
5hi mean i- 2erver & ;uerie 2erver '( then 2erver ' !ould repond -avorably and provide the
location to the 20P extenion i- it exit on that erver Cand o- coure vice veraD.
#erver A % &etc&asterisk&e(tensions'conf
,o!( -or *+,*i !e<ll need to !ork up a bit more. Jollo!in% i the extenion.con- -or each o- the
context mentioned above( that i( internal( dundiexten( and incomin%dundi
8general9
static5yes
(riteprotect5no
autofallthrough5yes
clearglobalvars5no
priority;umping5no
8lookupdundi9
s(itch 5< !A'!i,priv
8internal9
exten 5< 12$.1.=layback(demo-congrats)
exten 5< 12$.n.>angup()
include 5< lookupdundi
exten 5< 4LLLL.2.=layback(demo-congrats)
exten 5< 4LLLL.n.>angup()
Page 14 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
8incomingdundi9
exten 5< 4LLLL.1.Poto(internal.$MCL:C'N.2)
We<ve created a ne! context called LlookupdundiM. 5hi per-orm the actual lookup( and i- you
notice( it doe earch the KprivK context mentioned in dundi.con- -ile.
5he LinternalM context till ha the extenion 12# on !hich demo$con%rat i bein% played.
Bo!ever( !e have included KlookupdundiK context in there( and -urther to that created a pattern o- .
di%it tartin% -rom Priority 2. Priority 2 i very important here. WhyQ 'ecaue !hen a 20P Phone i
re%itered( due to the re%context bein% peci-ied in ip.con-( a Priority 1 !ith ,o@p i already
created( !hich you can ee by typin% Kdialplan ho! dundiextenK on the aterik prompt a-ter the
20P phone i re%itered. 2o( !hen the phone !ill reach the KinternalK context( it<ll look -or Priority 2(
and that< !hat !e need to provide.
5he lat context( Lincomin%dundiM i called via the 0&? 5runk that !e created Ccalled KiaxuerK in
ip.con-D. 5hi tran-er the re;uet to KinternalK context on Priority 2.
2o( it i%ni-ie that( primarily the KinternalK context i the one !here in the primary dialplan !ould
be !ritten related to !hat !ill happen to a call once it arrive. &t thi ta%e( !e are not doin%
anythin% except playin% a con%ratulation mea%e.
#erver B % &etc&asterisk&e(tensions'conf
5here< not much chan%e -or 2erver '( except havin% a di--erent extenion .1= intead o- 12#.
8general9
static5yes
(riteprotect5no
autofallthrough5yes
clearglobalvars5no
priority;umping5no
8lookupdundi9
s(itch 5< !A'!i,priv
8internal9
exten 5< 75*.1.=layback(demo-congrats)
exten 5< 75*.n.>angup()
include 5< lookupdundi
exten 5< 4LLLL.2.=layback(demo-congrats)
exten 5< 4LLLL.n.>angup()
8incomingdundi9
exten 5< 4LLLL.1.Poto(internal.$MCL:C'N.2)
Testing the setup
2o here !e are( our *+,*i con-i%uration !ith t!o erver i complete( and 0 Gut hope it !ork
!ithout iue -or you. Bere i ho! !e<ll tet it.
Page 1 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
1. 9etart &terik and tart the conole on both the erver
,etc,init#d,asterisk restart
asterisk -r
2. +e Eoiper and re%iter to both 2erver & and 2erver '. Hou hould ee appropriate
re%itration mea%e in the aterik conole o- both the erver.
#. ,o! !e !ill ee i- on both erver the KdundiextenK ha been created and i- the uer 1001
and 1002 are part o- it.
2n 0erver )
?-3< dialplan sho( dundiextens
8 ?ontext GdundiextensG created by G03=G 9
G1%%1G 5< 1# 'oop(1%%1)
803=9
-5 1 extension (1 priority) in 1 context# 5-
?-3<
2n 0erver O
?-3< dialplan sho( dundiextens
8 ?ontext GdundiextensG created by G03=G 9
G1%%2G 5< 1# 'oop(1%%2)
803=9
-5 1 extension (1 priority) in 1 context# 5-
?-3<
.. &ll cool. 'oth our phone are re%itered and a you ee the -irt priority o- ,o@p i created
in there. ,ext i to ee i- the peer are diplayed correctly. 2erver & !ould ho! 2erver ' a
it peer( and vice vera.
0erver ) 6 -isting !A'!i peers
?-3< dundi sho( peers
C3! >ost /odel )vg:ime
0tatus
%%61*6$*62f6116Kc 1K2#1*+#1#* (0) 0ymmetric Anavail 2@
(1 ms)
1 dundi peers 81 online. % offline. % unmonitored9
?-3<
0erver O 6 -isting !A'!i peers
?-3< dundi sho( peers
C3! >ost /odel )vg:ime
0tatus
%%61*6$*6KK6576*2 1K2#1*+#1#5 (0) 0ymmetric Anavail 2@
(1 ms)
1 dundi peers 81 online. % offline. % unmonitored9
?-3<
1. ,ext !e !ill ee i- !hat happen i- a lookup re;uet i made by *+,*i -rom 2erver & to
-ind 1001 C!hich i on 2erver &D( and 1002 C!hich i on 2erver 'D. & you !ill ee( 2erver
& !ill not %ive a reult o- the extenion re%itered on it o!n intance( but only thoe !hich
Page 1! of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
are re%itered on other erver. 2o( 1001 !hen earched doen<t retrieve any in-o( but 1002
doe.
?-3< dundi lookup 1%%1Dpriv
!A'!i lookup returned no results#
!A'!i lookup completed in Q ms
?-3< dundi lookup 1%%2Dpriv
1# % 3)L2,iaxuser65"Pl:LaaR1&J!:S%xmb'd155D1K2#1*+#1#*,1%%2
(CL30:0)
from %%61*6$*62f6116Kc. expires in 5 s
!A'!i lookup completed in + ms
?-3<
=. *oin% the above on 2erver ' %ive the reult a expected. 1002 return no reult a it i on
the ame machine( but 1001 doe.
?-3< dundi lookup 1%%1Dpriv
1# % 3)L2,iaxuser6tgH$cS1A22TtapRcibkp")55D1K2#1*+#1#5,1%%1
(CL30:0)
from %%61*6$*6KK6576*2. expires in 5 s
!A'!i lookup completed in * ms
?-3< dundi lookup 1%%2Dpriv
!A'!i lookup returned no results#
!A'!i lookup completed in + ms
?-3<
". ,o! let< place a call -rom 2erver & elected in Eoiper to 1001. 0t houldn<t play anythin%.
5hen place a call to 1002 $ it hould play a con%ratulation mea%e( and there hould be
ome in-ormation diplayed on 2erver '< aterik conole.
0- it !ork -or you( then it mean that the *+,*i con-i%uration i !orkin% !ell. 0- it doen<t( then it
!ould ho! ome mea%e at the conole o- !hat didn<t !ork. Hou can try enablin% ip debu%%in%
throu%h
sip set debug on
Page 1" of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
)ore DUNDi * - #erver #etup
We<ll no! add 2erver 3 to our exitin% cluter. 5hi !ill be our *+,*i lookup erver and no uer
!ould re%iter to it.
J9 9ichardon mentioned in hi document o- havin% a eparate *+,*i lookup erver !hich !ill
have all in-ormation about the peer. 5he advanta%e that it !ould have i
5here !ould be only one peer entered in all re%itration erver. 2o i- a ne! re%itration
erver i added to the cluter( the other re%itration erver needn<t have the *+,*i entry in
them.
0t !ill be eaier to mana%e ince the ne! re%itration erver !ould be added into the *+,*i
con-i%uration o- 2erver 3 only( and all other erver !ould kno! o- it intantly.
)et< move to the con-i%uration part on each erver. 0 am aumin% that you<ve done the baic
intallation o- &terik on 2erver 3. 5here< no need -or ettin% up ip.con-( iax.con- or
extenion.con- on 2erver 3( only Kdundi.con-K i needed.
*o the -ollo!in% be-ore proceedin% o that you don<t encounter !eird behavior
+nre%iter the 20P connection in Eoiper
2top &terik on all three erver via
,etc,init#d,asterisk stop
#erver A % &etc&asterisk&dundi'conf
We<ll remove 2erver '< entry -rom dundi.con- and add 2erver 3< entry. Bere< the -inal dundi.con-
on 2erver &
I =art 1
8general9
department5Jour !epartment
organiHation5Jour ?ompany. 3nc#
locality5Jour ?ity
stateprov50:
country5A0
email5yourDemail#com
phone5&125*5551212
bindaddr51K2#1*+#1#5
port5752%
entityid5%%61*6$*6KK6576*2
cachetime55
ttl52
autokill5yes
I =art 2
8mappings9
priv 5< dundiextens.%.3)L2.iaxuser6$M0C?BC:ND1K2#1*+#1#5,$M'A/OCBN.nopartial
I =art $
8%%61*6$*6*e6dQ6dc9 I /)? )ddress of 0erver ?
model 5 symmetric
Page 18 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
host 5 1K2#1*+#1#1% I(this is the 3= address of the !A'!i 0erver ?)
inkey 5 dundi
outkey 5 dundi
include 5 priv
permit 5 priv
qualify 5 yes
order 5 primary
@nly the Peer< 7&3 &ddre and hot are chan%ed in Part # o- the con-i%uration. 2o !e have
added 2erver 3 a a peer havin% 0P &ddre o- 182.1=6.1.10.
#erver B % &etc&asterisk&dundi'conf
5he con-i%uration i almot imilar to 2erver & except o- coure the bindaddre and entityid.
I =art 1
8general9
department5Jour !epartment
organiHation5Jour ?ompany. 3nc#
locality5Jour ?ity
stateprov50:
country5A0
email5yourDemail#com
phone5&125*5551212
bindaddr51K2#1*+#1#*
port5752%
entityid5%%61*6$*62f6116Kc
cachetime55
ttl52
autokill5yes
I =art 2
8mappings9
priv 5< dundiextens.%.3)L2.iaxuser6$M0C?BC:ND1K2#1*+#1#*,$M'A/OCBN.nopartial
I =art $
8%%61*6$*6*e6dQ6dc9 I /)? )ddress of 0erver ?
model 5 symmetric
host 5 1K2#1*+#1#1% I(this is the 3= address of the !A'!i 0erver ?)
inkey 5 dundi
outkey 5 dundi
include 5 priv
permit 5 priv
qualify 5 yes
order 5 primary
#erver C % &etc&asterisk&dundi'conf
9emember( you hould have copied dundi.key and dundi.pub -rom either 2erver & or 2erver ' to
2erver 3< /var/lib/aterik/key. 5he t!o aid -ile hould be identical on all the machine. 5he
*+,*i con-i%uration !ill have in-ormation on the peer to !hich it !ill connect. 2ince it !ill
connect to all aterik re%itration erver( hence the peer !ould be 2erver & and 2erver '.
Page 1# of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
Bere< the con-i%uration
I =art 1
8general9
department5Jour !epartment
organiHation5Jour ?ompany. 3nc#
locality5Jour ?ity
stateprov50:
country5A0
email5yourDemail#com
phone5&125*5551212
bindaddr51K2#1*+#1#1%
port5752%
entityid5%%61*6$*6*e6dQ6dc
cachetime55
ttl51 I Jou (ouldnGt (ant this server to loop. but only ask its peers 2'?C
autokill5yes
I =art 2
8mappings9
priv 5<
I =art $
8%%61*6$*6KK6576*29 I =eer 1 6 /)? )ddress of 0erver )
model 5 symmetric
host 5 1K2#1*+#1#5 I(this is the 3= address of the 0erver ))
inkey 5 dundi
outkey 5 dundi
include 5 priv
permit 5 priv
qualify 5 yes
order 5 primary
8%%61*6$*62f6116Kc9 I =eer 2 6 /)? )ddress of 0erver O
model 5 symmetric
host 5 1K2#1*+#1#* I(this is the 3= address of the 0erver O)
inkey 5 dundi
outkey 5 dundi
include 5 priv
permit 5 priv
qualify 5 yes
order 5 primary
& -e! detail on above. 5he KttlK i 1 intead o- 2. 2ince our lookup erver C2erver 3D i peerin%
!ith all the re%itration erver( it hould ak them only once and the re%itration erver houldn<t
-or!ard the re;uet to other erver. ttlO1 enure that. 0- it had been ttlO2( then re%itration erver
C2erver & 4 ' D !ould ;uery their peer $ and their peer i only 1( 2erver 3 $ and thu it !ould %et
into an un!anted loop.
5here< an empty Kpriv OR K parameter. 0t i there becaue Lmappin%M omeho! re;uire atleat one
parameter( even i- it< empty.
Peer 1 and Peer 2 are added. 0- you add another erver to it( then you Gut need to add an entry in
thi -ile only and make it Peer # and o on.
Page 2$ of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
5hat< all to it. )et< tet thi out.
Testing the - #erver #etup
0n our tet !e have t!o erver( 2erver & and 2erver ' on !hich the 20P phone !ould re%iter.
2erver 3 !ould act Gut a a lookup erver and an!er re;uet.
1. 2tart &terik on all the three erver and connect to their conole.
,etc,init#d,asterisk start
asterisk -r
2. ,o! ue the command Kdundi ho! peerK. 0t hould ho! only 1 peer on 2erver & 4 ' and
2 peer on 2erver 3. 5hi i Gut -ine.
#. 9e%iter your 20P Phone on 2erver & 4 ' o both extenion 1001 4 1002 hould be
re%itered.
.. ,o! you can either do Kdundi lookup 1001SprivK or Kdundi lookup 1002SprivK -rom
2erver 3 and it<ll ho! you both. *oin% K1002SprivK -rom 2erver & or K1001SprivK -rom
2erver ' !ould alo %ive you reult !hich are retrieved -rom the peer C2erver 3D.
1. 7ake a call no! -rom 2erver & elected in Eoiper to extenion 1002 Con 2erver 'D.
0- you<ve been able to do a 2 erver etup( thi type o- etup hould be trivial -or you. 9emember(
dundi.key and dundi.pub hould be identical on all three erver( o make ure you do that.
Page 21 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
Adding .ealTime to it
Heah( havin% uer hard coded in ip.con- -ile i o o o uncoolT )et< have them in databae. @-
coure( -or thi to !ork you hould have aterik$addon intalled on 2erver & and 2erver '. 2erver
3 i Gut the lookup erver( o !e don<t need anythin% there a -ar a aterik i concerned.
#etting up ),#!L #erver
Hou need to have ome undertandin% o- 7y2/) to continue. @n a *ebian/+buntu machine you
can intall 7y2/) via
apt-get install mysql-server
Jor our etup( !e !ill intall it on 2erver 3 a it i ittin% idle in any cae( doin% Gut the lookup.
Hou can have a dedicated machine -or it dependin% on your re;uirement. &lo( a J9 9ichardon
had mentioned in one o- the document( aterik realtime doe a lot o- databae activity( o it i
rather %ood to have it on other erver and it hould %o via a eparate net!ork inter-ace !hich i not
bein% ued -or V@0P. 2ince uually all erver have atleat t!o ethernet card( it hould be trivial.
5hink about it and implement a per your re;uirement.
&-ter intallation( comment out Kbind$addreK in /etc/my;l/my.cn- -ile and then retart my;l
throu%h /etc/init.d/my;l retart. 5hi i !hat 0 did on the my;l erver a-ter connectin% to it
mysql< create database asteriskI
mysql< grant all privileges on asterisk#U to user)D1K2#1*+#1#5 identified by
Gsecret)GI
mysql< grant all privileges on asterisk#U to userOD1K2#1*+#1#* identified by
GsecretOGI
0 eparated the uer o that i- in -uture 0 need to identi-y !hich uer i doin% !hat( then it< poible.
@ther!ie you can have a in%le uer( it< much more convenient that !ay( pecially !hen you add
more erver. Hou can alo ue <N< C;uote intendedD intead o- 0P &ddre o that anyone can
connect to it.
,ext import the databae tructure in !hich you<ll tore the uer. Hou can copy pate the -ollo!in%
directly into my;l prompt( or ave it a a -ile and import it later. 5hi i copied directly -rom
aterik ource and i in the contrib/cript/ip$-riend.;l -ile. & minor chan%e you<d need i that
K-ullcontactK column hould have a varcharC126D( other!ie aterik !ould complain.
?BC):C :)O-C VsipfriendsV (
VnameV varchar(7%) '2: 'A-- default GG.
VtypeV varchar(1%) '2: 'A-- default GG.
VdefaultuserV varchar(7%).
VfromuserV varchar(7%).
VfromdomainV varchar(7%).
VsecretV varchar(7%).
Vmd5secretV varchar(7%).
VauthV varchar(1%).
VmailboxV varchar(2%).
Vsubscribem(iV varchar(1%). -- yes,no
VvmextenV varchar(2%).
VcalleridV varchar(7%).
Page 22 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
Vcid4numberV varchar(7%).
VcallingpresV varchar(2%).
VusereqphoneV varchar(1%).
VlanguageV varchar(1%).
VincominglimitV varchar(1%).
VcontextV varchar(7%) '2: 'A-- default GG.
VsubscribecontextV varchar(7%).
VamaflagsV varchar(2%).
VaccountcodeV varchar(2%).
VmusicclassV varchar(2%).
VmohsuggestV varchar(2%).
Vallo(transferV varchar(2%).
VcallgroupV varchar(2%).
VpickupgroupV varchar(2%).
VautoframingV varchar(1%). -- yes,no
Vdisallo(V varchar(2%) default GallG.
Vallo(V varchar(2%).
VmaxcallbitrateV varchar(15).
VhostV varchar(7%) default GdynamicG.
VoutboundproxyV varchar(7%).
VipaddrV varchar(2%) '2: 'A-- default GG.
VdefaultipV varchar(2%).
VportV int(*) '2: 'A-- default G%G.
VfullcontactV varchar(12+).
VinsecureV varchar(2%).
VqualifyV varchar(15).
VregsecondsV int(11) '2: 'A-- default G%G.
VregextenV varchar(2%).
VregserverV varchar(2%).
VrtptimeoutV varchar(15).
VrtpholdtimeoutV varchar(15).
VrtpkeepaliveV varchar(15).
VlastmsV int(11) '2: 'A-- default G-1G.
VsetvarV varchar(2%%).
VuseragentV varchar(5%).
=B3/)BJ @CJ (VnameV).
3'!CL host (host. port).
3'!CL ipaddr (ipaddr. port)
) :J=C5/y30)/I
)at tep $ add t!o uer into it( !hich !ill be our 20P uer.
mysql< insert into sipfriends set
name5G1%%1G.type5GfriendG.context5GinternalG.host5GdynamicG.disallo(5GallG.allo
(5GgsmG.qualify5GyesGI
mysql< insert into sipfriends set
name5G1%%2G.type5GfriendG.context5GinternalG.host5GdynamicG.disallo(5GallG.allo
(5GgsmG.qualify5GyesGI
)et< move on to other con-i%uration.
#erver A % &etc&asterisk&res/m,s0l'conf
5he -ile contain the databae detail
Page 23 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
8general9
dbhost 5 1K2#1*+#1#1%
dbname 5 asterisk
dbuser 5 user)
dbpass 5 secret)
dbport 5 $$%*
requirements5(arn
#erver B % &etc&asterisk&res/m,s0l'conf
0- you didn<t con-i%ure t!o eparate uer in 7y2/)( then 2erver &< value could be ued. 'ut
ince in my etup each erver ha a eparate uer( there-ore the -ollo!in% i needed
8general9
dbhost 5 1K2#1*+#1#1%
dbname 5 asterisk
dbuser 5 userO
dbpass 5 secretO
dbport 5 $$%*
requirements5(arn
#erver A $ B % &etc&asterisk&e(tconfig'conf
Bere< !hat hould be there in the -ile on both the erver
8settings9
sipusers 5< mysql.general.sipfriends
sippeers 5< mysql.general.sipfriends
,o! !e<ll remove the uer in ip.con- -ile on both the erver C1001 4 1002D. Hou may !ant to
comment them out by pre-ixin% a emi$conon CUD.
#erver A $ B % &etc&asterisk&sip'conf
We<ll Gut remove the ip uer entrie Co- 1001 4 1002D in ip.con- -ile a it< no lon%er needed. &nd
!e<ll add one parameter Krtcache-riendK in the %eneral context o that uer re%itered in real time
are cached by ip and thu ;uali-yOye !ork -or them. Hou may omit it a per your re;uirement.
8general9
regcontext5dundiextens
srvlookup5no
'):5yes
bindport55%*%
allo(guest5no
canreinvite5no
rtcachefriends5yes
Testing .ealTime #etup
1. +nre%iter the phone -rom Eoiper.
2. 9etart aterik and then open the conole o- 2erver & 4 2erver '.
Page 24 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
,etc,init#d,asterisk restart
asterisk -r
#. @n 2erver 3< my;l prompt( i- you enter Kho! procelitK( you !ill t!o peritent
connection -rom both the erver. &ll< %ood to %o.
.. ,o! try re%iterin% the phone. 0t hould re%iter. 2erver &< aterik conole hould print
out omethin% imilar to the -ollo!in%
?-3< sip sho( peers
'ame,username >ost !yn 'at )?- =ort
0tatus Bealtime
1%%1,1%%1 xx#xx#xx#xx ! ' 5%*% 2@
(122 ms) ?ached B:
priv 1K2#1*+#1#* ' 5%*%
Anmonitored
2 sip peers 8/onitored6 1 online. % offline Anmonitored6 1 online.
% offline9
?-3<
1. )et< try callin% extenion 1001 no! -rom 2erver ' elected in Eoiper.
=. 0t hould playback the con%ratulation mea%e that !e<d de-ined in extenion.con-.
Page 2 of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
1hat2s ne(t
3nabling actual calling out
5ill no! !e had Gut ued playback. 0- you intend to actually call out the uer( !hich o- coure
you<d !ant to do( then do the -ollo!in%.
/etc/aterik/extenion.con-
8general9
static5yes
(riteprotect5no
autofallthrough5no
clearglobalvars5no
priority;umping5no
8lookupdundi9
s(itch 5< !A'!i,priv
8internal9
exten 5< 12$.1.=layback(demo-congrats)
exten 5< 12$.n.>angup()
include 5< dundiextens
exten 5< 4LLLL.2.'o2p(internal context called on 0erver ) to $MCL:C'N)
exten 5< 4LLLL.n.!ial(03=,$MCL:C'N.1%)
exten 5< 4LLLL.n.>angup()
include 5< lookupdundi
8incomingdundi9
exten 5< 4LLLL.1.'o2p(-anded on 0erver ) $MCL:C'N)
exten 5< 4LLLL.n.Poto(internal.$MCL:C'N.2)
0- you notice( 0<ve included KdundiextenK in the KinternalK context. 5hi !ould allo! you to call
uer !ho are re%itered on the ame erver a your. 0- they<re not re%itered( then KlookupdundiK
!ould be called. 5he 20P extenion i- -ound !ould rin% -or 10 econd unle an!ered( and then
han%up !ould be called. 5hi i very very baic( but it hould %ive you an idea !here to tart.
Using e(tensions in .ealTime
0- you plan to ue extenion alo in 9eal5ime intead o- hard codin% them( uch a -or 0V9(
Voicemail etc. 5hen the -ollo!in% hould !ork. 0 !ould pre-er that you don<t put the uer extenion
in-ormation in there( but rather ue it a a replacement -or extenion .1= or extenion 12# that !e
created above.
0n databae( the table tructure !ould be
?BC):C :)O-C VextensionsV (
VidV int(11) '2: 'A-- )A:243'?BC/C':.
VcontextV varchar(2%) '2: 'A-- !C")A-: GG.
VextenV varchar(2%) '2: 'A-- !C")A-: GG.
Page 2! of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
VpriorityV tinyint(7) '2: 'A-- !C")A-: G%G.
VappV varchar(2%) '2: 'A-- !C")A-: GG.
VappdataV varchar(12+) '2: 'A-- !C")A-: GG.
=B3/)BJ @CJ (VcontextV.VextenV.VpriorityV).
@CJ VidV (VidV)
) C'P3'C5/y30)/I
0n /etc/aterik/extcon-i%.con- you !ill add
extensions 5< mysql.general.extensions
0n /etc/aterik/extenion.con-( in KinternalK context you !ill add
s(itch 5< Bealtime
& an example( let< inert an >choCD application a extenion 100. >nter the -ollo!in% in-ormation
in the databae
mysql< insert into extensions set
context5GinternalG.exten5G1%%G.priority5G1G.app5G=laybackG.appdata5Gdemo-
echotestGI
mysql< insert into extensions set
context5GinternalG.exten5G1%%G.priority5G2G.app5GCchoG.appdata5GGI
9etart aterik and then try dialin% out extenion 100 -rom either 2erver & or '. @ne thin% to note
i that !e are retartin% only becaue !e<ve made i%ni-icant chan%e in the con-i%uration. 5he bet
part o- 9eal5ime i that you don<t need to retart any o- the ervice i- ne! 20P uer are added( or
ne! extenion are added.
#ecuring the setup
1. 2ecure the 20P uer. 0n the databae( put ome value -or KecretK column.
2. Put -ire!all on your erver. Hou need to open port -or 20P( -or 95P and *+,*i. Bere< a
ample con-i%uration
"or 3)L
$3=:)O-C0 -) 3'=A: -p tcp --dport 75*K -; )??C=:
$3=:)O-C0 -) 3'=A: -p udp --dport 75*K -; )??C=:
"or !A'!i
$3=:)O-C0 -) 3'=A: -p tcp --dport 752% -; )??C=:
$3=:)O-C0 -) 3'=A: -p udp --dport 752% -; )??C=:
"or 03=
$3=:)O-C0 -) 3'=A: -p udp --dport 5%*% -; )??C=:
3n case 03= bindport is different
$3=:)O-C0 -) 3'=A: -p udp --dport 5%Q% -; )??C=:
"or 03= B:=
$3=:)O-C0 -) 3'=A: -p udp --dport 1%%%%62%%%% -m udp -; )??C=:
3n case bindport is different then you can do a bit of port
for(arding# :he belo( should be in a single line
$3=:)O-C0 -) =BCB2A:3'P -t nat -p udp --dport 5%*% -; !'): --to
xxx#xxx#xxx#xxx65%Q%
Page 2" of 28 By Vivek Kapoor, http://exain.com
Asterisk Basics, and Load Balancing via DUNDi 01 July 2010
Do load balancing $ fail over
9ound 9obin *,2 -or poor man< load balancin%. 5hi mean havin% t!o Cor moreD K&K
record -or your domain. 5he o-tphone !ould connect randomly to any. ,o -ailure can be
detected in thi cenario( but till you can maintain uptime by uin% linux$ha Chi%h
availabilityD
*,2 29V -or load balancin% a !ell a -ailover. Eoiper upport *,2 29V and it< not that
di--icult to implement. &ll you need i a -e! 29V record in your *,2 2erver( and that<
pretty eay via Io*addy< *,2. Hou can ai%n !ei%ht to each erver a !ell a port
number( and the o-tphone !ould automatically connect to another erver in cae the one
it< connected !ith %oe do!n.
Ieo*,2 in cae you are havin% uer pread acro the %lobe. Bave multiple re%itration
erver pread all over the !orld and ue Ieo*,2 to make the uer re%iter to the one
cloet to them.
Bave multiple dundi lookup erver in cae dundi lookup erver itel- %oe do!n.
9ecommended i a Bi%h &vailability cenario Cha $ http://linux$ha.or%/D
7y2/) 3luter etup -or databae. 2o you<ll have hi%h uptime.
7ater 2lave/9eplication con-i%uration o- 7y2/) -or better per-ormance. J9 9ichardon
mentioned ome!here that !e can have multiple 7y2/) erver runnin% $ the data i read
-rom one databae and !ritten to another. 5hi !ay !e can have -ater and localiAed read in
cae the erver are %eo%raphically apart.
Bope thi erve a %ood purpoe -or you. &ny comment or ;uetion are !elcome.
Page 28 of 28 By Vivek Kapoor, http://exain.com

Anda mungkin juga menyukai