
Asteriskを利用するとIP電話内線網構築といった数十万する初期費用をぐぐっと安く抑えることができます。
「よっしゃ、オフィス作るぞ!」ってなった時のIP電話内線網って結構な出費です。これは必要だなといったオプションを積み重ねていくとかなりの金額になります。それに忘れた頃にくる機器更新の時も数十万・・・!
AsteriskによるIP電話内線網は、数十万の出費が痛いと感じる中小や零細オフィスにフィットします。
// もちろん外線も使えます!
前提条件
クラウドIPBXプロバイダ
- Cloco Cloud SIPトランク2契約済
 
パークコール
- パークプラン:700
 - パークエリア:701~702
 
SIPトランクサーバ
- AWSのEC2にて設置
 
SIPサーバポート番号
- 5060
 
混乱を避けるためにデフォルトポートで設定。
実際の利用ではセキュリティ上変更すると良いかと思います。
セキュリティ対策
- ポート番号変更
 - Fail2ban
 - IP制限
拠点利用のみの場合 - 海外通話制限
国内のみの通話利用の場合、海外に通話できないようにする。 Cloco Cloud管理画面で制御可能 
今回の記事では紹介していませんが、セキュリティ対策は必須です。
サーバへの設定
必要なライブラリを追加
| 
					 1 2 3 4  | 
						yum install -y libuuid-devel ncurses-devel sqlite sqlite-devel json-c-devel.x86_64 json-c-devel.x86_64  yum groupinstall -y 'Development Tools' 'base' yum install -y gcc gcc-c++ pcre-devel zlib-devel make wget openssl-devel libxml2 libxml2-devel libxslt-devel libxslt libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel gperftools-devel flex yum install -y gcc-c++ kernel-devel zlib-devel openssl-devel ncurses-devel newt-devel slang-devel compat-libtermcap  | 
					
更新します。
| 
					 1  | 
						# yum update  | 
					
kernelとkernel-develのバージョンがこれで合う。
jansson-2.5
jansson-2.5をインストールします。
| 
					 1 2 3 4  | 
						# cd /usr/src/ && wget http://www.digip.org/jansson/releases/jansson-2.5.tar.gz # tar -zxvf jansson-2.5.tar.gz # cd jansson* # ./configure --prefix=/usr/ && make clean && make && make install && ldconfig  | 
					
再起動して読み込ませます。
| 
					 1  | 
						# reboot now  | 
					
Asterisk12.8.2のダウンロードとインストール
ダウンロードを行いますよ!
| 
					 1 2 3  | 
						# cd /usr/local/src # wget http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-12.8.2.tar.gz # tar xzvf asterisk-12.8.2.tar.gz  | 
					
Asterisk12.8.2コンフィギュア
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33  | 
						# cd asterisk-12.8.2 asterisk-12.8.2]# ./configure configure: Menuselect build configuration successfully completed                .$$$$$$$$$$$$$$$=..             .$7$7..          .7$$7:.           .$$:.                 ,$7.7         .$7.     7$$$$           .$$77      ..$$.       $$$$$            .$$$7     ..7$   .?.   $$$$$   .?.       7$$$.    $.$.   .$$$7. $$$$7 .7$$$.      .$$$.  .777.   .$$$$$$77$$$77$$$$$7.      $$$,  $$$~      .7$$$$$$$$$$$$$7.       .$$$. .$$7          .7$$$$$$$7:          ?$$$. $$$          ?7$$$$$$$$$$I        .$$$7 $$$       .7$$$$$$$$$$$$$$$$      :$$$. $$$       $$$$$$7$$$$$$$$$$$$    .$$$. $$$        $$$   7$$$7  .$$$    .$$$. $$$$             $$$$7         .$$$. 7$$$7            7$$$$        7$$$  $$$$$                        $$$   $$$$7.                       $$  (TM)    $$$$$$$.           .7$$$$$$  $$      $$$$$$$$$$$$7$$$$$$$$$.$$$$$$        $$$$$$$$$$$$$$$$. configure: Package configured for: configure: OS type  : linux-gnu configure: Host CPU : x86_64 configure: build-cpu:vendor:os: x86_64 : unknown : linux-gnu : configure: host-cpu:vendor:os: x86_64 : unknown : linux-gnu :  | 
					
ロゴマークが出てきたらOK!です
インストール
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  | 
						asterisk-12.8.2]# make install make[1]: ディレクトリ `/usr/local/src/asterisk-12.8.2/sounds' に入ります make[1]: ディレクトリ `/usr/local/src/asterisk-12.8.2/sounds' から出ます find rest-api -name "*.json" | while read x; do \                 /usr/bin/install -c -m 644 $x "/var/lib/asterisk/rest-api" ; \         done  +---- Asterisk Installation Complete -------+  +                                           +  +    YOU MUST READ THE SECURITY DOCUMENT    +  +                                           +  + Asterisk has successfully been installed. +  + If you would like to install the sample   +  + configuration files (overwriting any      +  + existing config files), run:              +  +                                           +  +                make samples               +  +                                           +  +-----------------  or ---------------------+  +                                           +  + You can go ahead and install the asterisk +  + program documentation now or later run:   +  +                                           +  +               make progdocs               +  +                                           +  + **Note** This requires that you have      +  + doxygen installed on your local system    +  +-------------------------------------------+  | 
					
コンフィグサンプルファイルインストール
| 
					 1 2  | 
						# make samples # make config  | 
					
ライブラリの読み込み
| 
					 1  | 
						# ldconfig  | 
					
動かしてみよう
| 
					 1 2 3  | 
						# systemctl enable asterisk # systemctl restart asterisk # systemctl status asterisk  | 
					
DADHIドライバのインストール
DADHIのソースコードをダウンロードします。
| 
					 1 2  | 
						# cd /usr/local/src # wget https://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-2.11.1+2.11.1.tar.gz  | 
					
| 
					 1 2  | 
						# tar -zxvf dahdi-linux-complete-2.11.1+2.11.1.tar.gz # cd dahdi-linux-complete-*  | 
					
インストールします。
| 
					 1  | 
						# make  | 
					
| 
					 1  | 
						# make install  | 
					
| 
					 1  | 
						# make config  | 
					
| 
					 1  | 
						# cp /etc/dahdi/modules.sample /etc/dahdi/modules  | 
					
| 
					 1 2 3 4 5 6 7 8 9 10  | 
						# vi /etc/dahdi/modules # Xorcom Astribank Devices xpp_usb 最終行に以下を追加 # DAHDI Dummy dahdi_dummy  | 
					
libpriのインストール
| 
					 1 2 3  | 
						# cd /usr/local/src # wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.6.0.tar.gz # tar xzvf libpri-*.tar.gz  | 
					
インストール
| 
					 1 2 3 4 5 6 7 8 9 10 11  | 
						# cd libpri-* # make && make install install -m 644 libpri.h /usr/include install -m 755 libpri.so.1.4 /usr/lib #if [ -x /usr/sbin/sestatus ] && ( /usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled"); then /sbin/restorecon -v /usr/lib/libpri.so.1.4; fi ( cd /usr/lib ; ln -sf libpri.so.1.4 libpri.so) install -m 644 libpri.a /usr/lib if test $(id -u) = 0; then /sbin/ldconfig -n /usr/lib; fi  | 
					
ライブラリの読み込み
| 
					 1  | 
						# ldconfig  | 
					
Asterisk設定
| 
					 1  | 
						# cp -a /etc/asterisk/rtp.conf /etc/asterisk/rtp.conf.org  | 
					
通話用のポート設定
| 
					 1 2 3 4 5 6 7 8 9 10 11 12  | 
						# vi /etc/asterisk/rtp.conf rtpstart=10000 rtpend=20000 ↓変更 ;rtpstart=10000 ;rtpend=20000 rtpstart=30000 rtpend=31023  | 
					
ログ設定
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  | 
						# vi /etc/asterisk/logger.conf [general] ; ; Customize the display of debug message time stamps ; this example is the ISO 8601 date format (yyyy-mm-dd HH:MM:SS) ; ; see strftime(3) Linux manual for format specifiers.  Note that there is also ; a fractional second parameter which may be used in this field.  Use %1q ; for tenths, %2q for hundredths, etc. ; ;dateformat=%F %T       ; ISO 8601 date format ;dateformat=%F %T.%3q   ; with milliseconds dateformat=%F %T ←追加  | 
					
extensions.conf
SIPトランクサーバや子機との接続、発着信時の挙動を設定します。
| 
					 1  | 
						# cp /etc/asterisk/extensions.conf /etc/asterisk/extensions.conf.org  | 
					
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32  | 
						[general] writeprotect=no priorityjumping=yes [inbound] exten => <電話番号>, 1, Dial(SIP/20&SIP/21,120,t) exten => <電話番号>, 2,Congestion exten => <電話番号>, 102,Busy [outbound-Daihyou] exten => _0., 1,Set(CALLERID(num)= <電話番号>) exten => _0., 2,Dial(SIP/${EXTEN}@siptr,120,T) exten => _0., 3,Congestion exten => _0.,104,Busy exten => _1., 1,Set(CALLERID(num)= <電話番号>) exten => _1., 2,Dial(SIP/${EXTEN}@siptr,120,T) exten => _1., 3,Congestion exten => _1.,104,Busy ;117等の特番へ外線発信する設定です exten => _XX, 1,Dial(SIP/${EXTEN},120,T) exten => _XX, 2,Congestion exten => _XX, 102,Busy ;xxは内線桁数を表します(=2桁) 桁数が異なる場合は調整して下さい ;パーク保留設定 include => parkedcalls exten => 701,hint,park:701@parkedcalls exten => 702,hint,park:702@parkedcalls  | 
					
| 
					 1  | 
						# cp /etc/asterisk/sip.conf /etc/asterisk/sip.conf.org  | 
					
sip.conf
「Asterisk」に眠る様々な機能を覚醒させる。子機のアカウントや個別設定もここで行うよ!
勝てるかどうかはランナー次第。
https://wiki.asterisk.org/wiki/display/AST/Core+Configuration
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82  | 
						# cat /etc/asterisk/sip.conf [general] enabled = yes allowguest=no maxexpirey=3600 defaultexpirey=3600 port=5060 bindport=5060 bindaddr=0.0.0.0 tcpenable=yes udpbindaddr=0.0.0.0:5060 tcpbindaddr=0.0.0.0:5060 srvlookup=yes disallow=all allow=ulaw language=jp nat=force_rport,comedia ;BLF パーク保留で光らせる callcounter=yes busylevel=1 directmedia=yes register => <SIPトランク2ID>:<SIPトランクパスワード>@siptr ;SIP behind NAT externip=<SIPトランクサーバグローバルIP> localnet=<SIPトランクサーバグローバルIP>/255.255.254.0 ;AWSネットワーク サブネットは適当で良い [siptr] type=friend username=<SIPトランク2ID> secret=<SIPトランクパスワード> context=inbound canreinvite=no host=trunk2.cldpbx.com insecure=port,invite disallow=all allow=ulaw directmedia=yes qualify=yes ;;バージョン10以下の場合 ;nat=yes ;;バージョン11以上の場合 nat=force_rport,comedia ;====================================================================== ; クライアント子機設定 ;===================================================================== ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 子機 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; [21] type=friend username=21 secret=<子機パスワード> host=dynamic context=outbound-Daihyou qualify=yes nat=force_rport,comedia sendrpid=pai subscribecontext=outbound-Daihyou [22] type=friend username=22 secret=<子機パスワード> host=dynamic context=outbound-Daihyou qualify=yes nat=force_rport,comedia sendrpid=pai subscribecontext=outbound-Daihyou  | 
					
パーク保留設定
| 
					 1 2 3 4 5 6 7 8 9 10  | 
						# cat /etc/asterisk/features.conf [general] parkext => 700 parkpos => 701-702 context => parkedcalls parkingtime => 300 transferdigittimeout => 3 parkinghints => yes  | 
					
Asteriskに設定を反映させようね。
| 
					 1 2 3  | 
						# systemctl enable asterisk # systemctl restart asterisk # systemctl status asterisk  | 
					
子機の設定はこちら
お疲れ様です。
					        
              