FreePBX13とasterisk13をCentos7にインストールする

こんにちは。エンジニアの岩間です。

 

目次

はじめに

今回は、FreePBX13とasterisk13をCentos7にインストールする方法をご紹介します。

Centos7は、AWSのEC2で作成したインスタンスを使用しています。

コマンドはすべてrootユーザーで実行しています。

 

初期設定

1.SElinuxとFirewalldの無効化、yumアップデート、アスタリスクユーザーの追加

cat /etc/resolv.conf 
sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/sysconfig/selinux 
sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/selinux/config 
systemctl stop firewalld.service
systemctl disable firewalld.service
yum -y update yum -y groupinstall core base "Development Tools" adduser asterisk -m -c "Asterisk User" reboot

 

2. 必要となるDBサーバーなどインストール

yum -y install lynx tftp-server unixODBC mysql-connector-odbc mariadb-server mariadb httpd ncurses-devel sendmail sendmail-cf sox newt-devel li bxml2-devel libtiff-devel audiofile-devel gtk2-devel subversion kernel-devel git crontabs cronie cronie-anacron wget vim uuid-devel sqlite-devel net-t ools gnutls-devel python-devel texinfo libuuid-devel

 

3.repoのインストール

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum remove php*

 

4.phpのインストール

yum install php56w php56w-pdo php56w-mysql php56w-mbstring php56w-pear php56w-process php56w-xml php56w-opcache php56w-ldap php56w-intl php56w- soap

 

5.サービスの起動

curl -sL https://rpm.nodesource.com/setup_12.x | bash - 
yum install -y nodejs 
systemctl enable mariadb.service 
systemctl start mariadb 
systemctl enable httpd.service 
systemctl start httpd.service

 

asteriskのインストールと設定

asteriskの公式ページ→https://www.asterisk.org/

6.iksemelのインストール

cd /usr/src
wget -c https://src.fedoraproject.org/lookaside/pkgs/iksemel/iksemel-1.4.tar.gz/md5/532e77181694f87ad5eb59435d11c1ca/iksemel-1.4.tar.gz
tar xf iksemel-1.4.tar.gz
cd iksemel*
./configure
make
make install

 

7.libpriとasterisk13のダウンロード

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-current.tar.gz
wget https://downloads.asterisk.org/pub/telephony/asterisk/old-releases/asterisk-13.38.3.tar.gz
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
tar xvfz dahdi-linux-complete-current.tar.gz
cd dahdi-linux-complete-*
make all
make install
make config
cd /usr/src
tar xf libpri-current.tar.gz
cd libpri*
make
make install

 

8.janssonのインストール

cd /usr/src
wget -O jansson.tar.gz https://github.com/akheron/jansson/archive/v2.10.tar.gz
tar xf jansson.tar.gz
cd jansson*
autoreconf -i
./configure --libdir=/usr/lib64
make
make install

 

9.asteriskコンパイル

cd /usr/src 
tar xf asterisk-13.38.3.tar.gz 
cd asterisk-13* 
contrib/scripts/install_prereq install 
./configure --libdir=/usr/lib64 --with-pjproject-bundled 
contrib/scripts/get_mp3_source.sh 
make menuselect 
make 
make install 
make config 
ldconfig 
chkconfig asterisk off

 

10.asteriskのパーミッション設定

cd
chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/lib64/asterisk
chown -R asterisk. /var/www/
sed -i 's/AllowOverride None/AllowOverride All/' /etc/httpd/conf/httpd.conf
systemctl restart httpd.service

 

11.アップロードサイズの変更

vi /etc/php.ini
upload_max_filesize = 120M

 

12.apache設定ファイルのUser とGroup のコメントアウト部分を外す

vi /etc/httpd/conf/httpd.conf
User apacheをUser asteriskに変更
Group apacheをGroup asteriskに変更
User asteriskのコメントを外す
Group asteriskのコメントを外す
systemctl restart httpd.service

 

MariaDBのインストール

13.MariaDBのインストール

mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):  << enterを押す
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y  << Yを押す
New password:  << MariaDBのパスワードを入力
Re-enter new password:   << パスワード確認
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y << Yを押す
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y  << Yを押す
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y << Yを押す
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y << Yを押す
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

FreePBXのインストール

14.FreePBXのダウンロード

FreePBXの公式ページ→https://www.freepbx.org/

reboot
getenforce ←disabledになっているのを確認する。
cd /usr/src
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-13.0-latest.tgz
tar xf freepbx-13.0-latest.tgz
cd freepbx* 
./start_asterisk start
./install
Database engine [mysql]: << enterを押す
Database name [asterisk]: << enterを押す
CDR Database name [asteriskcdrdb]: << enterを押す
Database username [root]: << enterを押す
Database password: passw0rd << rootパスワードを入力
File owner user [asterisk]: << enterを押す
File owner group [asterisk]: << enterを押す
Filesystem location from which FreePBX files will be served [/var/www/html]: << enterを押す
Filesystem location from which Asterisk configuration files will be served [/etc/asterisk]: << enterを押す
Filesystem location for Asterisk modules [/usr/lib64/asterisk/modules]: << enterを押す
Filesystem location for Asterisk lib files [/var/lib/asterisk]: << enterを押す
Filesystem location for Asterisk agi files [/var/lib/asterisk/agi-bin]: << enterを押す
Location of the Asterisk spool directory [/var/spool/asterisk]: << enterを押す
Location of the Asterisk run directory [/var/run/asterisk]: << enterを押す
Location of the Asterisk log files [/var/log/asterisk]: << enterを押す
Location of the FreePBX command line scripts [/var/lib/asterisk/bin]: << enterを押す
Location of the FreePBX (root) command line scripts [/usr/sbin]: << enterを押す
Location of the Apache cgi-bin executables [/var/www/cgi-bin]: << enterを押す
Directory for FreePBX html5 playback files [/var/lib/asterisk/playback]: << enterを押す

このメッセージが出ればインストール成功です。

Finished setting permissions
Generating default configurations...
Finished generating default configurations
You have successfully installed FreePBX

 

サイトにアクセスする

今回はEC2のインスタンスを使用しているので、セキュリティグループのインバウンドルートを以下のように編集します。

※x.x.x.x/x→任意のIPアドレスです。

※UDPの5060-5161ポートは通話ができなくなるため0.0.0.0/0を設定します。

 

タイプ ポート範囲 CIDRブロック 目的
カスタムUDP 10000-20000 x.x.x.x/x SIPコールの実際の音声部分に使用
カスタムUDP 5060-5061 0.0.0.0/0 chan_SIPシグナリングに使用される標準ポート
カスタムUDP 5160-5161 x.x.x.x/x chan_PJSIPシグナリングに使用される標準ポート
カスタムTCP 8089 x.x.x.x/x UCPのWebRTC部分で使用
カスタムTCP 80-85 x.x.x.x/x PBXのGUI画面へのアクセス許可
カスタムTCP 5060-5061 x.x.x.x/x  chan_SIPシグナリングに使用される標準ポート
カスタムTCP 5160-5161 x.x.x.x/x chan_PJSIPシグナリングに使用される標準ポート
カスタムTCP 1443 x.x.x.x/x 電話のHTTPSプロビジョニングで使用
SSH 22 x.x.x.x/x 外部からPBXへのSSH接続を許可
HTTPS 443 x.x.x.x/x SSL暗号化通信でPBXのGUI画面へアクセス許可

http://xx.xx.xx.xx/ipアドレスにアクセスします。

ユーザーとパスワードを設定後ログインできるようになります。

 

セキュリティ対策

sipのデフォルトのポートを使うと攻撃対象になることがあります。そのため以下のような対策をしましょう。

  • デフォルトのSIPポート(5060/udp)を別のポート番号にする
  • FireWallなどでアクセス元を制限する
  • SIPのパスワードをわかりにくくする
  • 外線prefixを特殊なものにする

これらの対策をすることで、ユーザ/パス総当たり→外線プレフィックス総当たりの両方を破って外に出られてしまうという危険性はかなり低くなります。

 

まとめ

以上、FreePBX13とasterisk13をCentos7にインストールする方法でした。

ぜひ参考にしていただければと思います。

この記事が気に入ったら
いいね ! しよう

Twitter で

【採用情報】一緒に働く仲間を募集しています

採用情報
ページトップへ