📜 ⬆️ ⬇️

Private experience of installing and configuring Asterisk from scratch

First, the disclaimer

Asterisk configuration is dedicated to sites, forums and entire portals like voip-info.org. But there are always people for whom this topic is a dense forest, and it is necessary to launch the product “yesterday”. A month and a half ago, I knew about Asterisk only what it is. This work is intended only to make life easier for those who find themselves in the same situation after me. It can be errors of any degree of "teapot". If you are a guru of Asterisk settings - indicate the error, I will correct it, the descendants will be grateful to you.

First there was the word

At some point in time, through my efforts, the company's infrastructure development strategy was literally turned on its head. The goals and objectives were outlined and it became clear that we needed a dynamic, mobile server infrastructure in order to save money, so that in case of any problems, we could quickly recover and / or rise elsewhere, so that it would be easier to care for iron, etc. P.

Then there was the matter

In general, on paper everything was beautiful and easy. The case arose only for deployment.
First, two simple servers were purchased. Core i7-930, 12GB of memory and 12TB on SATA-drives. These servers were installed free Xen Server and deployed virtual servers and workstations for remote employees.
QNAP NAS is used as external storage, which was inherited.
Terabyte local storage is only needed to store a media bank, which is quite large. The servers themselves collectively weigh less than 3 terabytes.
One of the servers was Asterisk to replace the old Panasonic TDE-200. Because companies need a cheap connection, direct numbers in different countries, and free negotiations between employees, then there is no alternative to it for 12 shekels.


Day One: Make World

It was decided to deploy Asterisk on the CentOS operating system native to Citrix Xen. The same RedHat, only from the side. I’ll make a reservation right away: I’ve been admin Windows all my life, and * nix have only been “played” in virtual machines, not counting a couple of web servers on hardware. Therefore, this Asterisk deployment in Citrix Xen gives some naivety from the point of view of experienced people.
In general, I went on a proven path: a detailed how-to instruction for teapots from official manuals opens on the laptop and is executed on the server literally and without initiative. It will be possible to play heroes-adjusters later, when everything is set up and work in the “default” state and the first full backup will be made.
')
Day two: yum install asterisk -y

Not that I was very surprised, but, nevertheless, I went to a familiar signalman for advice when I discovered that there were already three almost independent forks living asterisks: 1.4, 1.6, and 1.8. Each of them has its own cockroaches and lotions. Because I was not deceived by the hope of overcoming an asterisk with a swoop, then I decided to install version 1.4, like a friend, in order to have the maximum possible compatibility of configs. Although, subsequently, I had to rise to 1.6 due to the lack of TCP support in 1.4, when such a need arose.
For this, a digium repository was attached to CentOS and Asterisk was installed from it.
The installation was quite expected, without a hitch. Basically, a sensible step-by-step roadmap with voip-info was used .
Immediately iptables were corrected to allow traffic over SIP ports.
Not immediately, but I recommend to future generations to install and configure immediately a package named fail2ban . It is not an extra program on the server exposed to the Internet. One day after installation, all of Taiwan in the drop left, judging by the iptables.

Day Three: TZ for PBX functionality

Getting the most interesting - planning. Before any adjustment process, it is necessary to record and structure all the wishes of the customer and be sure to sign an agreement to avoid further conflicts like “no, I said something completely different”. In my case, the customer is the company in which I work, but it does not change anything. We write a technical task for a functional, discuss it with responsible people, dispel disagreements and sign the final version.
TK on the configuration turned out this:
  • Phone numbering four-digit.
  • The first digit of the number is a sign of the country where the office is located.
  • The numbering in each department begins with the first digit of the next hundred.
  • Each department is a separate call group.
  • If the called subscriber is not available for a call in any way, then the call is transferred to the whole group.
  • Incoming call service logic:
    1. Pick up the phone.
    2. Play a greeting.
    3. Play ads about current promotions.
    4. Play the call options of different departments or offer to dial the number of the subscriber.
    5. Starting from point 2, wait for the input of any commands.
    6. After the end of step 4, wait for the commands to be entered for another 10 seconds.
    7. In the absence of commands, play the call options again.
    8. If the subscriber is still tupit, then transfer the call to the secretary.
  • Users who need such a service, fasten voice mail. In this case, if the user is in any way unavailable for a call, transfer the call to voice mail.
  • By default, calls are allowed only to Russia and Italy - the countries where our company mainly operates. The remaining directions are opened as needed by the narrowest masks, since we all remember scary stories about “Cuban telephone operators” and one day we don’t want our PBX to start calling all the 50 channels in Sierra Leone at $ 14 per minute for each channel.


At first glance, the task is simple, but in practice it took quite a lot of blood to coordinate it. Especially, for the approval of the ban of all directions, except for explicitly permitted. This client had to agree only in the face of the inevitable, otherwise, necessity of configuring a VPN on each device connecting to the PBX. I just try to stick to the most simple and understandable configurations, and it always seems to the client that adding some functionality to the system is “just a few buttons to push.”

Day four: nano sip.conf

The most interesting begins: the configuration process.
In order not to delay the already long article, burdening it with a detailed description of the torments of the initial configuration and the subsequent tuning, I will simply show my current configs with comments what's what.

[general] context=default ;   allowguest=no ; ,     allowoverlap=no ;           .  –  . alwaysauthreject=yes ;  ,         –  .    . useragent=Orgue de Barbaris ; –     .      ,         , ..     . defaultexpiry=360 ;   . callevents=yes ;  ,       music on hold limitonpeer=yes ;      . tcpenable=yes ; TCP   SIP. rtptimeout=60 ;     ,      . language=ru ; .    . bindport=5060 ;  .        ,   . bindaddr=0.0.0.0 ;   , ..         . srvlookup=yes tos_sip=cs3 ; <a href="http://www.voip-info.org/wiki/view/Asterisk+sip+tos">http://www.voip-info.org/wiki/view/Asterisk+sip+tos</a> tos_audio=ef disallow=all ;    allow=alaw ;,   ,   .    . allow=g729 allow=g723 allow=ulaw dtmfmode=rfc2833 ; Asterisk-   info,       rfc. rtpholdtimeout=300 rtpkeepalive=5 canreinvite=no ;     .     .               g.729,        . ,      alaw<->g.729a         .    Core i7-930     . externip=xxx.xxx.xxx.xxx ;   IP.   -,   Asterisk   NAT,     .  . allowexternaldomains=yes ; <a href="http://www.voip-info.org/wiki/view/Asterisk+config+sip.conf"></a>  , -  . domain=mydomain.com,default fromdomain=mydomain.com ;      .    SIP-       Asterisk        .         . ,       ,    .          . register => tcp://@multifon.ru::@sbc.megafon.ru/~60 ;   SIP-   -    [multifon] ;   ,      type=peer secret= username= host=sbc.megafon.ru port=5060 insecure=port,invite call-limit=1 context=incoming canreinvite=no qualify=yes transport=tcp dtmfmode=inband ;  –  .     , ,        ,   .   : [defaults](!) canreinvite=no ;     disallow=all allow=alaw allow=g729 allow=g723 [peer](!,defaults) type=peer host=dynamic ;    qualify=yes ;     nat=yes ;,      NAT call-limit=1 ; -   busylevel=1 ;,     “” rtpkeepalive=5 ;     . [ext1000](peer) secret=secretsecretsecret [ext1001](peer) secret=secretsecretsecret [ext1002](peer) secret=secretsecretsecret ;   -   ,     : [ext1101](peer) secret=secretsecretsecret transport=tcp ;   SIP  TCP. 


Day Five: nano extensions.conf

Not less interesting file in which all logic of automatic telephone exchange registers. These articles turned out to be very useful for understanding the dial-plan logic: http://inhibitz.ucoz.ru/publ/9-1-0-21 , http://asterisk-pbx.ru/wiki/doku.php / asterisk_dialplan
So, let's go:

 [general] static=yes ;    CLI writeprotect=yes ;    CLI [globals] ;  ,     . [macro-dial-ext] ; “    4- ” exten => s,1,Answer() ;  exten => s,2,Dial(SIP/ext${ARG1},20,tT) ; ,        20       . exten => s,3,Goto(s-${DIALSTATUS},1) ;     Dial. exten => s-NOANSWER,1,Macro(group-dial,${ARG1:0:2}00) ;   exten => s-BUSY,1,Macro(group-dial,${ARG1:0:2}00) exten => s-CONGESTION,1,Macro(group-dial,${ARG1:0:2}00) exten => s-CHANUNAVAIL,1,Macro(group-dial,${ARG1:0:2}00) exten => _s-.,1,Hangup ;  [macro-dial-vip] ;     exten => s,1,Answer() exten => s,2,Dial(SIP/ext${ARG1},20,tT) exten => s,3,Goto(s-${DIALSTATUS},1) exten => s-NOANSWER,1,Voicemail(${ARG1}) ;     . exten => s-BUSY,1,Voicemail(${ARG1}) exten => s-CONGESTION,1,Voicemail(${ARG1}) exten => s-CHANUNAVAIL,1,Voicemail(${ARG1}) exten => _s-.,1,Hangup [macro-secretary] ;     exten => s,1,Answer() exten => s,3,Dial(SIP/ext2222,15,tTm) ;   exten => s,n,Goto(s-${DIALSTATUS},1) exten => s-NOANSWER,1,Macro(group-dial,${ARG1}) ;       exten => s-CHANUNAVAIL,1,Macro(group-dial,${ARG1}) exten => s-BUSY,1,Macro(group-dial,${ARG1}) exten => s-UNKNOWN,1,Macro(group-dial,${ARG1}) exten => s-CONGESTION,1,Macro(group-dial,${ARG1}) exten => s-CHANUNAVAIL,1,Macro(group-dial,${ARG1}) exten => _s-.,1,Hangup [macro-group-dial] ;    exten => s,1,Answer() exten => s,n,Queue(${ARG1}) ; queue,     queues.conf exten => s,n,Goto(s-${DIALSTATUS},1) exten => s,n,Hangup exten => s-BUSY,1,Playback(all-circuits-busy-now) exten => s-BUSY,n,Macro(secretary,1100) ;  ,    exten => s-NOANSWER,1,Macro(secretary,1100) exten => s-CHANUNAVAIL,1,Macro(secretary,1100) exten => s-CONGESTION,1,Macro(secretary,1100) exten => _s-.,1,Hangup ;     . [default] ; Default context including all specials include => incoming include => multifon ;  default    ;     exten => _[123]X00,1,Macro(group-dial,${EXTEN}) exten => _1[1-689]XX,1,Macro(dial-ext,${EXTEN}) exten => _17XX,1,Macro(dial-vip,${EXTEN}) exten => _[2]XXX,1,Macro(dial-vip,${EXTEN}) exten => _[3]XXX,1,Macro(dial-ext,${EXTEN}) ;       . ;            : ;<a href="http://sbelikov.ru/2009/03/golosovoe-menyu-v-asterisk/">http://sbelikov.ru/2009/03/golosovoe-menyu-v-asterisk/</a> ;  ,          .       : <a href="http://www.ivrvoice.ru/">http://www.ivrvoice.ru/</a> ;      Asterisk : <a href="http://www.voip-info.org/wiki/view/Convert+WAV+audio+files+for+use+in+Asterisk">http://www.voip-info.org/wiki/view/Convert+WAV+audio+files+for+use+in+Asterisk</a> [incoming] exten => s,1,Goto(s-${CHANNEL(peername)},1) ;-,         .       . exten => s-sipcity,1,Answer() ;   exten => s-sipcity,2,Background(it-greet) ;     exten => s-sipcity,3,Background(advert) exten => s-sipcity,4,Background(it-route) exten => s-sipcity,n,Waitexten() exten => s-sipcity,n,Macro(group-dial,1100) exten => ,1,Answer() ; - exten => ,2,Macro(dial-vip,2001) ;      exten => _s-zebra,1,Answer() ;   exten => _s-zebra,2,Background(ru-greet) ;,   exten => _s-zebra,3,Background(advert) exten => _s-zebra,4,Background(ru-route) exten => _s-zebra,n,Waitexten() exten => _s-zebra,n,Macro(group-dial,1100) exten => s-eng,1,Answer() ;   exten => s-eng,2,Background(en-greet) ; - - exten => s-eng,3,Background(advert) exten => s-eng,4,Background(en-route) exten => s-eng,n,Waitexten() exten => s-eng,n,Background(en-route) exten => s-eng,n,Waitexten() exten => s-eng,n,Macro(group-dial,1100) exten => 5000,1,Answer() ;       IVR,     .  . exten => 5000,2,Background(ru-greet) exten => 5000,3,Background(advert) exten => 5000,4,Background(ru-route) exten => 5000,5,Waitexten() exten => 5000,6,Background(ru-route) exten => 5000,n,Waitexten() exten => 5000,n,Macro(group-dial,1100) ;   IVR   exten => 1,1,Macro(group-dial,1100) ;  “1”,     1100 exten => 2,1,Macro(group-dial,1200) exten => 3,1,Macro(group-dial,1300) exten => 4,1,Macro(group-dial,1400) exten => 5,1,Macro(group-dial,1500) exten => 6,1,Macro(group-dial,1100) exten => 9,1,Goto(s-sipcity,1) ;       -   exten => 0,1,Goto(s-eng,1) exten => _1[1-689]XX,1,Macro(dial-ext,${EXTEN}) ;   exten => _17XX,1,Macro(dial-vip,${EXTEN}) exten => _2XXX,1,Macro(dial-vip,${EXTEN}) exten => _3XXX,1,Macro(dial-ext,${EXTEN}) exten => i,1,Goto(s-zebra,4) ;    exten => t,1,Goto(s-zebra,4) ; –   ;       [zebra] ;   “”,       e164. ..   ,   “+”. : 74951234567. exten => _99ZXXXXXX,1,Dial(SIP/zebra/7495${EXTEN:2}) ;          495. “99” –  “    ”, ZXXXXXX –   7-  ,        1.      zebra       7495,      “99”    Asterisk . ;  .   ,   ,    . ;############################# ; International ;############################# ;Italy exten => _9939.,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99+39.,1,Dial(SIP/zebra/${EXTEN:3}) ;   ,       ,    .      SIP  .      rewrite,        . ;Belorussia exten => _9937517XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99+37517XXXXXXX,1,Dial(SIP/zebra/${EXTEN:3}) ;Kazakhstan exten => _997727XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99+7727XXXXXXX,1,Dial(SIP/zebra/${EXTEN:3}) ;Ukraine exten => _99380XXXXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99+380XXXXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) ;############################# ; cellular ;############################# exten => _99790[3-9]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99791[0-79]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99792[569]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _997930XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99793[1-4678]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99795[0-3]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99796[0-578]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99798[0-5789]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _997997XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) ;############################# ; cities starting at 3 ;############################# exten => _99730[12]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99734[1-35-79]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99735[1-3]XXXXXXX,1,Dial(SIP/zebra-out/${EXTEN:2}) exten => _99738[1-5]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _997388XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99739[01]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99739[45]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) ;############################# ; cities starting at 4 ;############################# exten => _997401XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99741[1356]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99742[13467]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99747[1-5]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99748[1-7]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99749[1-689]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) ;############################# ; cities starting at 8 ;############################# exten => _99781[1-8]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _997820XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _997821XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99783[13-6]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99784[0-8]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99785[15]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99786[1-35-7]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) exten => _99787[1-37-9]XXXXXXX,1,Dial(SIP/zebra/${EXTEN:2}) 


Day Six: nano Voicemail.conf, nano queues.conf

It's time to attach voicemail.

Here, in fact, there is no point in even putting configs, because there almost nothing changes, and what changes is deeply specific. The main problem for me was setting up MTA for sending mail through a non-standard port and with smtp-authentication. After killing half a day on smoking forums, he finally put exim and set up mail transmission through it.
Two points on which I would like to focus attention - my voice messages are killed on Asterisk immediately after sending. Just so as not to clog the screw. For the relevance of such a message is measured in minutes, and it makes me feel silly to force users to follow the voice box. In addition, I put the wav49 format for messages, because I was too lazy to bother with compressing files in mp3, and on the mailer the harsh rules are inhumanly delivered with multimedia applications - all mp3s are replaced with Spectrum Exolon as mp3.

With queues.conf, too, everything is simple:
 [general] persistentmembers = yes ; ,     autofill = yes ;   autopause = no ;   ,   -  monitor-type = MixMonitor ;   [1100] ;  strategy = ringall ;   –    eventwhencalled = yes ;     Fop2 ringinuse = no ;   timeout = 20 ; retry = 1 ;     1  wrapuptime = 0 ;       () maxlen = 0 ;     . 0= ; –     member => SIP/2222 member => SIP/1101 member => SIP/1102 member => SIP/1103 member => SIP/1104 member => SIP/1105 member => SIP/1106 member => SIP/1107 member => SIP/1108 member => SIP/1109 member => SIP/1110 


Day Seven: Afterword

Firstly, I would like to point out my own mistakes as well as the obvious disadvantages of this solution:
- Error: a bag of ordinary headsets, which are used at home to communicate on Skype or in TS, was purchased for users. This is a completely unsuitable office solution. Sitting all day with a headset stuck in the ear of an ordinary person is very tiring. A professional camera headsets are like a ticket to the orbit. In addition, the women's team does not accept headsets with a headband - “we have hairstyles!”. The solution is USB-tubes or desktop SIP-phones for those who have a good budget.
- Error: rush is needed when catching fleas. If you do not know what Asterisk is and what it is eaten with, then it is better to start studying it right now. Study carefully. Because this knowledge will definitely be needed, and, as usual, with the term “so that it was ready yesterday”. Not the fact that you need to install Asterisk, but the general theory of VoIP and Dial-plan constructs will be very useful for you. I had to literally “fire” paces to put everything and master it on the move due to a tough conflict with the telephone company-monopolist in our office center, therefore, it was not without fakapov.
- Reliability. While I have not grown my gray hair behind the Asterisk configuration process, I monitor the PBX constantly. I'm just not sure yet, I did everything right. A couple of times she stopped serving my customers for no reason and now I’m afraid to leave her unattended.
- There are no faxes. More precisely, they seem to be there, but purely for show. Normal faxing is very difficult without the use of iron cards, which I avoid to maintain mobility.
- Non-guaranteed quality of communication. On whatever wide channel you sit, anyway, with enviable consistency, you will receive claims for “gurgling connection”. Despite the rapid development of technology and the expansion of data transmission channels, problems still occur regularly. The simplest example: a small hotel in Italy, which is a representative of the company. The hotel held as much as 2Mbps of ADSL Internet with uplink of 256k, which is distributed free of charge to guests via WiFi. A representative contacts the office using this channel, and the connection is disgusting - it constantly gurgles and in general. Just someone at the hotel decided to post a pack of 12 pixel photos to classmates. The usual thing.
- If the budget is not very big and there is not enough money for desk phones, then users have to master new methods of working with the phone - using software dialers like Zoiper or PhonerLite. In addition, dialing * 77 to transfer a call also bothers them, they want to “as before”, by briefly pressing the lever, which is no longer available.
- Also, my users are annoyed by the need to dial the numbers not “in the old-fashioned way” 810 (country code) (city code) (telephone), but in the format e164. I could have left 810, but in this case, the number of an ordinary Italian hotel becomes simply cosmic length: 998103912345678901. And in E164 it is three digits shorter.

In general, the overwhelming majority of problems are caused by the unwillingness of users to live in an era of change. Starting with grunts and ending with outright sabotage. I could have a couple of pages to list the claims of users, but it will be a hard offtop. The only thing that can be recommended in this case - plan your move to Asterisk carefully. Try to make it as inconvenient as possible for users. It is unprofitable for business to spend paid time on people learning their new things, which could work as before if everything was planned properly.

Now the advantages of the solution:
+ The first and most obvious is money. I managed to reduce communication costs by about 15 times. Previously, the average bill for telephony we had about 5 thousand dollars a month. Over the past month after the introduction of Asterisk even three hundred dollars did not run up. The lion's share of savings - conversations between employees in different countries.
+ Mobility. If suddenly something happens, no matter what - whether it is a new Moscow black out or just a fire in the building - I pick up a virtual machine with Asterisk on any hosting that can import them, and just inform customers of the new IP PBX. Try to imagine the unavailability of telephone communication with regular telephony.
+ Just fantastic solution flexibility and its almost complete free of charge. Of course, we pay with our time saving money on solutions “from the iron box”, but personally I was interested to find out how it all works.

One question that I asked myself a couple of times and that probably would have appeared in the comments if I hadn’t answered it here: “Why didn’t I put Elastix, FreePBX, PiaF or something like that? On a roadmap in 10 minutes, it is installed and running for years! ”The answer is simple: there is no forest behind the web-face. Yes, this is convenient, but to overcome the functionality of the web-muzzle, you will have to edit non-standard configs, risking breaking everything to hell with one comma. And I can’t even imagine what we need in a year. In addition, with the web-muzzle never know what and how it works. Therefore, pure Asterisk, Komsomol members can not without difficulties.

Now I have an Asterisk with such configs working quite satisfactorily. There are annoying little things, such as echoes when calling on some strange urban PBXs, or the disgusting work of some embedded sound cards (damn one popular manufacturer of low-cost motherboards), but this is a common thing - it is solved with USB-tubes with which the free Zoiper Free fits very well .
In general, I and my management are satisfied with the work done. It is only necessary to work more with a file and it will be possible to proceed to the next project.

What else is left to finish, for complete happiness:
Put and configure Fop2 so that users can see which of the employees are in what condition, so that there is no situation of transferring a call to a busy subscriber, when the call is automatically transferred to the group and the person does not go where they want to.
Set up a monitoring system to monitor the state of the PBX, calls, queues in real time.
Put some extremely simple call reporting system. The task is all-only in a clear visualization of the number of calls for checking accounts.

Source: https://habr.com/ru/post/113707/


All Articles