AWSでKamailioを構築

こんにちは、エンジニアのリリアンです。

過去の記事(Kamailioとはなにか)でKamailio SIP Serverについて、ご紹介しました。今回は、CentOS 7を利用してKamailioを構築する手順をまとめようと思います。

目次

前提条件

  • CentOS 7
  • Kamailio 5.4
  • MariaDB

インスタンスを作成

AWSでKamailioをインストールので、まずはEC2のCentOS7のインスタンスを作成します。

MariaDBをインストール

事前設定

インスタンスの作成が完了すれば、MariaDBをインストールします。

Databaseをインストール前に、以下のモジュールを無効にしましょう。

・SELinuxを無効にします。

# sudo setenforce 0
# sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
# sudo reboot

→ SELinuxステータスを確認
# sestatus

・EC2のセキュリティーグループを使うので、IPtablesとFail2banも無効にします。

# sudo systemctl stop fail2ban 
# sudo systemctl disable fail2ban 
# sudo systemctl status fail2ban
# sudo systemctl stop iptables
# sudo systemctl disable iptables
# sudo systemctl status iptables

MariaDB Database server

次、MariaDB Database serverをインストールします。

sudo yum -y install mariadb-server
sudo systemctl enable --now mariadb
sudo systemctl status mariadb
sudo 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):
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
New password:
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
... 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
... 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
- 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
... 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!

MariaDBのインストールは完了です。

Kamailioをインストール

事前準備

必要なパッケージをインストールします。

sudo yum -y update
sudo yum -y groupinstall core
sudo yum -y groupinstall base

Kamailio PRMリポジトリを追加

/etc/yum.repos.dkamailio.repoを作って、以下の内容をkamailio.repoにコピペします:

[kamailio]
name=Kamailio - latest - Packages for the Kamailio latest release
baseurl=https://rpm.kamailio.org/centos/$releasever/latest/$basearch/
enabled=1
metadata_expire=30d
repo_gpgcheck=1
gpgkey=https://rpm.kamailio.org/rpm-pub.key
type=rpm
skip_if_unavailable=True

[kamailio-master]
name=Kamailio - master - Developmental packages for the next
Kamailio release
baseurl=https://rpm.kamailio.org/centos/$releasever/master/master/$basearch/
enabled=0
metadata_expire=12h
repo_gpgcheck=1
type=rpm
gpgcheck=1
gpgkey=https://rpm.kamailio.org/rpm-pub.key
skip_if_unavailable=True

[kamailio-5.4]
name=Kamailio - 5.4 - Packages for the latest Kamailio 5.4 release
baseurl=https://rpm.kamailio.org/centos/$releasever/5.4/5.4/$basearch/
enabled=0
metadata_expire=30d
repo_gpgcheck=1
gpgkey=https://rpm.kamailio.org/rpm-pub.key
type=rpm
skip_if_unavailable=True

[kamailio-5.4.2]
name=Kamailio - 5.4.2 - Packages for the Kamailio 5.4.2 release
baseurl=https://rpm.kamailio.org/centos/$releasever/5.4/5.4.2/$basearch/
enabled=0
metadata_expire=30d
repo_gpgcheck=1
gpgkey=https://rpm.kamailio.org/rpm-pub.key
type=rpm
skip_if_unavailable=True

[kamailio-5.4.1]
name=Kamailio - 5.4.1 - Packages for the Kamailio 5.4.1 release
baseurl=https://rpm.kamailio.org/centos/$releasever/5.4/5.4.1/$basearch/
enabled=0
metadata_expire=30d
repo_gpgcheck=1
gpgkey=https://rpm.kamailio.org/rpm-pub.key
type=rpm
skip_if_unavailable=True

[kamailio-5.4.0]
name=Kamailio - 5.4.0 - Packages for the Kamailio 5.4.0 release
baseurl=https://rpm.kamailio.org/centos/$releasever/5.4/5.4.0/$basearch/
enabled=0
metadata_expire=30d
repo_gpgcheck=1
gpgkey=https://rpm.kamailio.org/rpm-pub.key
type=rpm
skip_if_unavailable=True

Kamailio SIP Serverをインストール

リポジトリを追加したら、CentOS 7に Kamailio SIP Server をインストールします。

sudo yum install kamailio kamailio-presence kamailio-mysql

/usr/lib/systemd/system/kamailio.serviceの内容を確認します。kamailio.serviceが存在しない場合、以下の内容で作りましょう:

[Unit]
Description=Kamailio (OpenSER) - the Open Source SIP Server
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=kamailio
Group=kamailio
Environment='CFGFILE=/etc/kamailio/kamailio.cfg'
Environment='SHM_MEMORY=64'
Environment='PKG_MEMORY=4'
EnvironmentFile=-/etc/sysconfig/kamailio
ExecStart=/usr/sbin/kamailio -DD -P /run/kamailio/kamailio.pid -f $CFGFILE -m $SHM_MEMORY -M $PKG_MEMORY
Restart=on-failure

[Install]
WantedBy=multi-user.target

Databaseを起動します。

# sudo systemctl start mariadb.service

vim /etc/kamailio/kamctlrcを実行して、以下の項目を変更します:

# SIP_DOMAINをKamailioのサーバーIPに変更する。例:
SIP_DOMAIN=111.222.123.123

# コメントアウトを外す
DBENGINE=MYSQL

# DBRWPWは後で使うので、メモします。

Kamailio databaseを作成します。

sudo kamdbctl create

MySQL root パスワードの入力を求められたら、mysql_secure_installation で作成された MySQL root ユーザーのパスワードを入力します。

すべての質問にYesで答えます。

続いて、Kamailio設定ファイルを編集します。

sudo vim /etc/kamailio/kamailio.cfg

→ `listen=`の内容を変更する。
→ udpはプライベートIP、advertiseはパブリックIPを設定する。
listen=udp:xxx.xxx.xxx.xxx:5060 advertise yyy.yyy.yyy.yyy:5060

→ 以下の行もkamailioサーバーのパブリックIPに変更します。
modparam("dispatcher", "ds_ping_from", "sip:proxy@yyy.yyy.yyy.yyy")

Kamailioを起動します。

sudo systemctl start kamailio

自動起動の設定

sudo systemctl enable kamailio

設定反映はKamailioを再起動する必要があります。

sudo systemctl restart kamailio

おわりに

ここまで、Kamailioのインストール完了しましたが、いかがでしたでしょうか。また機会があれば、Kamailioのサーバーでdispatcherの設定と確認手順を紹介します。是非、ご参考にしていただければ幸いです。

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

Twitter で
The following two tabs change content below.

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

採用情報
ページトップへ