2016/02/02

Asterisk : The Cookbook 食譜 023 - 在 Ubuntu 下的安裝

Q023: 能談談在 Ubuntu 下怎麼安裝 Asterisk 嗎?

其實不管 Ubuntu, Debian, Redhat, CentOS 等等,系統部份雖然不見得一樣,但是 Asterisk 的編譯部份是相差不多的。

1. 安裝編譯環境:
  $ sudo apt-get install build-essential subversion \
libncurses5-dev libssl-dev libxml2-dev libsqlite3-dev \
uuid-dev

2. 準備源碼
  $ mkdir ~/pbx; cd ~/pbx
  $ wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
  我實驗的版本是 11-current, 解開後是 11.21.0,可以自行驗證 12, 13 等
  $ tar zxf asterisk-11-current.tar.gz; cd asterisk-11*
  $ contrib/scripts/get_mp3_source.sh
  $ sudo ./contrib/scripts/install_prereq install
  $ sudo ./contrib/scripts/install_prereq install-unpackaged
3. 編譯,以我的 Ubuntu 是 64 bit, 命令如下
  $ ./configure 即可

    目前的電腦大部份都是多核心的,底下 -j8 可以加速編譯速度,可以視系統的 CPU 核心數來決定。
  $ make -j8
  $ make menuselect
  在 make menuselect 時,我是盡可能都選了,也可以不做 make menuselect,這不影響本次實驗結果
  $ sudo make install && sudo make config && sudo make samples
4. 修改權限
  $ sudo adduser --home /var/lib/asterisk --shell /bin/false asterisk && sudo passwd asterisk
  $ sudo chown -R asterisk.asterisk /var/{lib,spool,log,run}/asterisk
5. 準備設定檔,存放在 /etc/asterisk/ 中
  這一段比較複雜,先以我實驗的實例提供大家參考

===== extensions.conf ======
[globals]
INTERNAL_DIAL_OPT=,30
[internal]
exten => 7001,1,Answer()
exten => 7001,2,Dial(SIP/7001,60)
exten => 7001,3,Playback(vm-nobodyavail)
exten => 7001,4,VoiceMail(7001@main)
exten => 7001,5,Hangup()
exten => 7002,1,Answer()
exten => 7002,2,Dial(SIP/7001,60)
exten => 7002,3,Playback(vm-nobodyavail)
exten => 7002,4,VoiceMail(7001@main)
exten => 7002,5,Hangup()
exten => 7003,1,Answer()
exten => 7003,2,Dial(SIP/7001,60)
exten => 7003,3,Playback(vm-nobodyavail)
exten => 7003,4,VoiceMail(7001@main)
exten => 7003,5,Hangup()
exten => 8001,1,VoicemailMain(7001@main)
exten => 8001,2,Hangup()
exten => 8002,1,VoicemailMain(7002@main)
exten => 8002,2,Hangup()
exten => 8003,1,VoicemailMain(7003@main)
exten => 8003,2,Hangup()

===== sip.conf ======
[general]
  context=internal
  allowguest=no
  allowoverlap=no
  bindaddr=0.0.0.0
  bindport=5060
  srvlookup=no
  allow=ulaw
  localnet=192.168.1.0/255.255.255.0
[7001]
  type=friend
  host=dynamic
  secret=123456
  context=internal
[7002]
  type=friend
  host=dynamic
  secret=123456
  context=internal
[7003]
  type=friend
  host=dynamic
  secret=123456
  context=internal

===== manager.conf ======
[general]
  enabled = yes
  webenabled = yes
  port = 5038
  bindaddr = 0.0.0.0
  displaysystemname = yes
  httptimeout = 60
[admin] 
  secret = 123456
  permit = 192.168.1.0/24
  read = system,call,log,verbose,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate,message
  write = system,call,log,verbose,agent,user,config,command,reporting,originate,message

===== asterisk.conf ======
[directories]
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk
astdbdir => /var/lib/asterisk
astkeydir => /var/lib/asterisk
astdatadir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir => /var/run/asterisk
astlogdir => /var/log/asterisk
astsbindir => /usr/sbin
[options]
runuser = asterisk
rungroup = asterisk
documentation_language = en_US
[compat]
pbx_realtime=1.6
res_agi=1.6
app_set=1.6

===== modules.conf ======
[modules]
  autoload=yes
  load => res_musiconhold.so
  noload => res_speech.so
  noload => res_phoneprov.so
  noload => pbx_gtkconsole.so
  noload => chan_alsa.so
  noload => chan_console.so
  noload => res_ael_share.so
  noload => res_clialiases.so
  noload => res_adsi.so
  noload => pbx_ael.so
  noload => pbx_dundi.so
  noload => chan_oss.so
  noload => chan_mgcp.so
  noload => chan_skinny.so
  noload => chan_phone.so
  noload => chan_agent.so
  noload => chan_unistim.so
  noload => app_nbscat.so
  noload => app_amd.so
  noload => app_minivm.so
  noload => app_zapateller.so
  noload => app_ices.so
  noload => app_sendtext.so
  noload => app_speech_utils.so
  noload => app_mp3.so
  noload => app_flash.so
  noload => app_getcpeid.so
  noload => app_setcallerid.so
  noload => app_adsiprog.so
  noload => app_forkcdr.so
  noload => app_sms.so
  noload => app_morsecode.so
  noload => app_followme.so
  noload => app_url.so
  noload => app_alarmreceiver.so
  noload => app_disa.so
  noload => app_dahdiras.so
  noload => app_senddtmf.so
  noload => app_sayunixtime.so
  noload => app_test.so
  noload => app_externalivr.so
  noload => app_image.so
  noload => app_dictate.so
  noload => app_festival.so
  noload => chan_pjsip.so
  noload => func_pjsip_aor.so
  noload => func_pjsip_contact.so
  noload => func_pjsip_endpoint.so
  noload => res_hep_pjsip.so
  noload => res_pjsip_acl.so
  noload => res_pjsip_authenticator_digest.so
  noload => res_pjsip_caller_id.so
  noload => res_pjsip_config_wizard.so
  noload => res_pjsip_dialog_info_body_generator.so
  noload => res_pjsip_diversion.so
  noload => res_pjsip_dlg_options.so
  noload => res_pjsip_dtmf_info.so
  noload => res_pjsip_endpoint_identifier_anonymous.so
  noload => res_pjsip_endpoint_identifier_ip.so
  noload => res_pjsip_endpoint_identifier_user.so
  noload => res_pjsip_exten_state.so
  noload => res_pjsip_header_funcs.so
  noload => res_pjsip_keepalive.so
  noload => res_pjsip_log_forwarder.so
  noload => res_pjsip_logger.so
  noload => res_pjsip_messaging.so
  noload => res_pjsip_multihomed.so
  noload => res_pjsip_mwi_body_generator.so
  noload => res_pjsip_mwi.so
  noload => res_pjsip_nat.so
  noload => res_pjsip_notify.so
  noload => res_pjsip_one_touch_record_info.so
  noload => res_pjsip_outbound_authenticator_digest.so
  noload => res_pjsip_outbound_publish.so
  noload => res_pjsip_outbound_registration.so
  noload => res_pjsip_path.so
  noload => res_pjsip_phoneprov_provider.so
  noload => res_pjsip_pidf_body_generator.so
  noload => res_pjsip_pidf_digium_body_supplement.so
  noload => res_pjsip_pidf_eyebeam_body_supplement.so
  noload => res_pjsip_publish_asterisk.so
  noload => res_pjsip_pubsub.so
  noload => res_pjsip_refer.so
  noload => res_pjsip_registrar_expire.so
  noload => res_pjsip_registrar.so
  noload => res_pjsip_rfc3326.so
  noload => res_pjsip_sdp_rtp.so
  noload => res_pjsip_send_to_voicemail.so
  noload => res_pjsip_session.so
  noload => res_pjsip_sips_contact.so
  noload => res_pjsip.so
  noload => res_pjsip_t38.so
  noload => res_pjsip_transport_websocket.so
  noload => res_pjsip_xpidf_body_generator.so

6. 啟動與停止
  $ sudo /usr/sbin/asterisk -cvvv
  $ CLI> core stop now
如果想直接在背景執行,就不加參數 $ sudo /usr/sbin/asterisk
如果想停止背景中的 asterisk, 可以如下:
  $ sudo /usr/sbin/asterisk -rc
  CLI> core stop now

PS: 我試過 asterisk-13.7.0, 11.21.0, 12.8.2 都是可以連線的
PS: 如果無法連線,有很多情況是模組載入問題,請試著修改 modules.conf 試試

0 意見: