4
2

More than 3 years have passed since last update.

【ハマったところまとめ】内線電話環境をAsterisk×AWSで構築する

Last updated at Posted at 2021-05-23

AWS・EC2にAsteriskを載せて、内線電話環境を構築しました。
基本的な流れは他のサイトでも紹介されていますが、自分がハマったところに絞って記載します。

環境

【VPC】
インターネット接続が必要なのでデフォルトVPCを利用
【EC2】
AMI:Red Hat Enterprise Linux 8 (HVM・64bit)
インスタンスタイプ:t2.micro
【Asterisk】
オープンソースのIP-PBX※ミドルウェア。今回はAsterisk 13.38.2を利用。
※IP電話機で従来のPBX(電話交換機)と同じ機能を実現するもの。
電話番号と端末の紐づけ情報を保持して、通話開始までのやり取りを制御してくれる。
発信~着信~通話開始まではAsteriskを介して行い、通話開始後は電話機同士で通信する。
image.png
SIP: Wait for ACK packet on Callee site to start RTP session
【クライアント(電話機)】
端末:iPhone/iPad
PCでもスマホでもなんでもOK。
アプリ:Zoiper/AGEphone
試行錯誤していく中で2種類入れて試していたが、1種類でOK。最終的にはどちらのアプリでもうまく動いた。

手順

今回一番重要だったのが手順サイト。こちらのサイトを利用した。AWS特有のお作法とか、パッケージ導入時の手順が丁寧に書いてあって分りやすい。
余談だが、呼制御(SIP:5060)だけでなく通話用プロトコル(RTP:10000-20000とか)も使うらしく何も考えずにSIPだけセキュリティグループの穴あけしたら躓いたので注意。上記手順サイトのものを空ければうまくいくが、細かいところを見るならAsteriskが使用するポート一覧を参考に。

ハマったところ

基本は手順サイトを見れば大丈夫だが、個人的にハマったところを記載します。

①パッケージ導入

RHEL系はAsteriskパッケージがyumに入っておらず自身でコンパイル・インストールする必要があるが、コンパイルのためにも必要パッケージが複数あり、それが不足していたためにmakeでエラーが大量に出た。色々なサイトを見て試行錯誤した結果、2021/5/22時点では上記手順サイトで上手くいった。ちなみにDebian系ならaptにAsteriskが最初から入っているので楽。

②sip.conf設定

こちらのサイトを見て気づいたが、generalセクション設定を2重にしていたため、NAT跨ぎなどの設定が上手く入っていなかった。気付かず進めても発信~着信はうまくいってしまうので、クライアント側の設定なのか?など原因の切り分けに時間がかかった。

▶私の失敗② sip.confの設定
元々のsip.confの下に設定を追記したことで、sample記載としてあった[general]と追記した[general]セクションが2つできてしまった。asterisk起動後、NAT設定などが正しく読み込めなかった。→設定を修正

③CLIへのログイン

起動してもCLIにログインできなかった。
psやpstreeでプロセスを見てみても、Asteriskのプロセスが動いていないように見える。

[root@ip-xxx-xx-xx-xxx etc]# /etc/init.d/asterisk stop
Stopping asterisk (via systemctl):  Terminated
[root@ip-xxx-xx-xx-xxx etc]# /etc/init.d/asterisk start
Starting asterisk (via systemctl):                         [  OK  ]

[root@ip-xxx-xx-xx-xxx etc]# asterisk -vvvvr
Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?)
[root@ip-xxx-xx-xx-xxx etc]# ps -ef | grep aster
root      150754       1  0 03:07 ?        00:00:00 /bin/sh /usr/sbin/safe_asterisk
root      151611   73188  0 03:14 pts/1    00:00:00 grep --color=auto aster

Linux asterisk 第1回なども見つつ類似トラブルでの対応方法を探ったが、結論Asteriskを明示的に上げれば動いた。
Asteriskの専用コマンドはAsteriskの起動と終了を参照。CLIに入るとPBXサーバの動きが見れて面白いので、ぜひ。

[root@ip-xxx-xx-xx-xxx etc]# asterisk
[root@ip-xxx-xx-xx-xxx etc]# asterisk -vvvr
Asterisk 13.38.2, Copyright (C) 1999 - 2014, Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Please note that this version of Asterisk no longer receives bug fixes.
Consult the following URL for Asterisk version support status information:
https://wiki.asterisk.org/wiki/display/AST/Asterisk+Versions
=========================================================================
Connected to Asterisk 13.38.2 currently running on ip-xxx-xx-xx-xxx (pid = 152062)
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2