SIPサーバFlexisipのビルド・インストール

Ubuntu18.04にSIPサーバであるFlexisipをビルド・インストールします。VoIP電話(050電話、各種SNSメッセンジャーなど)システムでは、SIPプロトコルにより複数の端末間でリアルタイムに音声、テキスト、映像情報などが遣り取りされていますが、これら端末間の繋がりはSIPサーバ(AsteriskなどオープンなSIPサーバは数多く存在します)により確立されています(端末間IPアドレス、ポートの割当、コマンドメッセージ処理など)。

本システムをRaspberry Piなどのシングルボードコンピュータにインストールすることにより、携帯端末に繋がるインターホンを製作することも出来ます。

ソースファイル

GitLab

Github

Flexisipバージョン

$ flexisip -v
flexisip  version: 1.0.13 (git: 1.0.13-247-g3ba0a222)
sofia-sip version 1.13.35bc

Compiled with:
- SNMP
- Transcoder
- Redis
- Soci
- Protobuf
- Presence
- Conference

ビルド・インストール環境

Linux 4.15.0-55-generic/Ubuntu18.04 x86_64 GNU/Linux

事前準備

事前に開発に必要なDockerパッケージの準備、SIPサーバ用にドメイン名を取得します。

  • Docker CE(linphone-sdkのコンテナイメージ作成・コンテナ起動)
    Dockerのインストールについては以下フォーラム記事を参照願います。
    Docker Engine/Docker Composeのインストール
  • ドメイン名を利用すると後の設定が楽になります。ドメイン名を利用しない場合はグローバルIPアドレス(xxx.xxx.xxx.xxx)に置き換えて下さい。
    サブドメインは"sip"でなくても構いません。
    ex) "sip.freedomain.com"でも"test.freedomain.com"でも可

A.ビルド・インストール手順

  1. プロジェクトフォルダの作成
  2. linphone-sdkコンテナイメージの作成とコンテナの起動
  3. ソースファイルのダウンロード(git clone)
  4. prepare.pyによるビルドスクリプトの作成
  5. makeコマンドによるビルド
  6. debパッケージのインストール
  7. パスの指定

B.関連アプリのインストール・設定

  1. Redis Serverのインストール・設定
  2. SNMPのインストール・設定
  3. MariaDBのインストール・SQLデータベース・テーブルの作成

C.起動・動作確認

  1. ルータのポート開放(ポートフォワード)
  2. Flexisipの設定・起動
  3. 携帯端末による動作確認
  4. Netstatによる各セッションの確認

A.ビルド・インストール手順

A-1.プロジェクトフォルダの作成

以下作業ディレクトリを作成、作業ディレクトリ内に移動します。

$ mkdir ~/build_project
$ cd build_project

A-2.linphone-sdkコンテナイメージの作成とコンテナの起動

以下コマンドによりDockerイメージのダウンロード、コンテナlinphone-sdkが起動、そのままコンテナ内シェルに移動します (Linphone-desktopの記事で作成したコンテナをそのまま利用しても構いません)

$ docker run --name bc-flexisip -v $PWD:/home/bc -it gitlab.linphone.org:4567/bc/public/linphone-sdk/bc-dev-ubuntu:18.04

bc@container_id:~$

Dockerファイルは以下参照して下さい。

別のターミナルにより起動コンテナを確認出来ます。

$ docker container ls

CONTAINER ID        IMAGE                                                                 COMMAND             CREATED             STATUS                      PORTS               NAMES
xxxxxxxxxxx        gitlab.linphone.org:4567/bc/public/linphone-sdk/bc-dev-ubuntu:18.04   "/bin/sh -c bash"   15 hours ago        Exited (0) 5 hours ago                          linphone-desktop

以下3,4,5の作業はコンテナ内で実行します。

A-3.ソースファイルのダウンロード(git clone)

コンテナ内シェルで以下コマンドを実行します。

$ cd /home/your_user_name/build_project

$ git clone https://gitlab.linphone.org/BC/public/flexisip.git

$ cd flexisip

$ git submodule sync && git submodule update --init --recursive

A-4.prepare.pyによるビルドスクリプトの作成

prepare.pyによりcmakeスクリプトを作成します。

$ ./prepare.py flexisip-rpm -DENABLE_REDIS=YES -DENABLE_TRANSCODER=YES -DENABLE_UNIT_TESTS=OFF -DENABLE_SOCI=YES -DENABLE_PRESENCE=YES -DENABLE_CONFERENCE=YES -DENABLE_SNMP=YES -DENABLE_DOC=OFF -DENABLE_PROTOBUF=YES -DENABLE_MDNS=NO -DENABLE_JWE_AUTH_PLUGIN=YES -DENABLE_EXTERNAL_AUTH_PLUGIN=YES

上記コマンドにより全オプションのステータスが表示されます。

-- Enabled features:
 * Redis, Enable hiredis support.
 * Presence, Enable presence server support.
 * Conference, Enable conference server support.
 * SNMP, Enable SNMP support.
 * Transcoder, Enable transcoder support.
 * Protobuf, Enable protobuf for REDIS.
 * Jwe Auth Plugin, Enable JweAuth plugin support.
 * External Auth Plugin, Enable ExternalAuth plugin support
 * SOCI, Enable SOCI support.
 * CXX wrapper, Build the C++ wrapper for Liblinphone.
 * LIME, Enable Linphone IM Encryption support in  Liblinphone.
 * Mbedtls, Crypto stack implementation based on mbeddtls.

-- Disabled features:
 * Unit tests, Enable unit tests support with BCUnit library.
 * Debug logs, Enable debug level logs in libinphone and mediastreamer2.
 * Doc, Enable documentation generation with Doxygen and Sphinx
 * Tools, Enable tools binary compilation.
 * unmaintained, Allow inclusion of unmaintained code in the build.
 * GTK UI, Enable the GTK user interface of Linphone.
 * CSharp wrapper, Build the C# wrapper from Liblinphone.
 * Swift wrapper, Build the Swift wrapper from Liblinphone.
 * Jazzy doc, Build the Swift doc from Liblinphone.
 * Java wrapper, Build the Java wrapper from Liblinphone.
 * LIME X3DH, Enable Linphone IM Encryption version 2 support in  Liblinphone.
 * NLS, Enable internationalization of Linphone and Liblinphone.
 * Update Check, Enable update check.
 * VCARD, Enable vCard 4 support in Linphone and Liblinphone.
 * Relative prefix, liblinphone and mediastreamer will look for their respective ressources relatively to their location.
 * Tunnel, Secure tunnel for SIP/RTP (require license).
 * RTP Map always in SDP, Always include rtpmap in SDP.
 * mDNS, Multicast DNS support
 * GPL third parties, Usage of GPL third-party code (FFmpeg and x264).
 * Non free codecs, Allow inclusion of non-free codecs in the build.
 * SRTP, SRTP media encryption support.
 * ZRTP, ZRTP media encryption support.
 * WebRTC AEC, WebRTC echo canceller support.
 * WebRTC AECM, WebRTC echo canceller for mobile support.
 * WASAPI, Windows Audio Session API (WASAPI) sound card support.
 * AMRNB, AMR narrow-band audio encoding/decoding support (require license).
 * AMRWB, AMR wide-band audio encoding/decoding support (require license).
 * Codec2, Codec2 audio encoding/decoding support.
 * G729, G.729 audio encoding/decoding support.
 * G729B CNG, G.729 annex B confort noise generation.
 * G726, G.726 audio encoding/decoding support.
 * GSM, GSM audio encoding/decoding support.
 * iLBC, iLBC audio encoding/decoding support.
 * ISAC, ISAC audio encoding/decoding support.
 * OPUS, OPUS audio encoding/decoding support.
 * Silk, Silk audio encoding/decoding support.
 * Speex, Speex audio encoding/decoding support.
 * WebRTC VAD, WebRTC voice activation detector support.
 * BV16, BroadVoice 16 audio encoding/decoding support.
 * Video, Ability to capture and display video.
 * jpeg, JPEG support with libjpeg-turbo.
 * qrcode, QRCode support with zxing.
 * FFmpeg, Some video processing features via FFmpeg: JPEG encoding/decoding, video scaling, H264 decoding...
 * H263, H263 video encoding/decoding support (require license).
 * H263p, H263+ video encoding/decoding support (require license).
 * MKV, MKV playing and recording support.
 * MPEG4, MPEG4 video encoding/decoding support (require license).
 * OpenH264, H.264 video encoding/decoding support with the openh264 library (require license).
 * VPX, VPX (VP8) video encoding/decoding support.
 * X264, H.264 video encoding support with the x264 library (require license).
 * AAudio, AAudio Android sound card for Android 8+.
 * PCAP, PCAP support.
 * Polarssl, Crypto stack implementation based on polarssl.

NOTE) Disabled features一覧から有効化したいオプションがある場合、 -DENABLE_XXXXX=ON (YES) を追加します。

上記のprepare.pyスクリプトにより、flexisip/WORKフォルダ内にflexisip-rpmが作成されます。

このままmakeするとmacros関連の次のエラーが発生します (Linphone-desktopの記事で作成したDockerコンテナを利用する場合エラー対策は必要ありません)

エラー

“%cmake error”

https://github.com/BelledonneCommunications/flexisip/issues/64

エラー対策

以下パッケージをダウンロードしてコンテナ内の該当フォルダにコピーします。以下の作業は別ターミナル(コンテナ外)から行う場合です。

https://rpmfind.net/linux/rpm2html/search.php?query=cmake-rpm-macros

https://rpmfind.net/linux/mageia/distrib/cauldron/x86_64/media/core/release/cmake-rpm-macros-3.15.0-0.rc3.1.mga8.x86_64.rpm

$ docker cp cmake.prov container_name:/usr/lib/rpm/cmake.prov
$ docker cp cmake.req container_name:/usr/lib/rpm/cmake.req
$ docker cp cmake.attr container_name:/usr/lib/rpm/fileattrs/cmake.attr
$ docker cp macros.cmake container_name:/usr/lib/rpm/macros.d/macros.cmake

A-5.makeコマンドによるビルド

コンテナ内でmakeコマンドを実行します。

$ make

A-6.debパッケージのインストール

コンテナから出てdebパッケージをインストールします。

$ exit

flexisip/WORK/flexisip-rpm/rpmbuild/DEBSフォルダ内にdebパッケージが作成されています。

このフォルダ内でdpkgコマンドによりインストールします。

$ cd WORK/flexisip-rpm/rpmbuild/DEBS
$ sudo dpkg -i linphone-*.deb

A-7.パスの指定

バイナリパスは/opt/belledonne-communications/bin

ライブラリパスは/opt/belledonne-communications/lib

のため、各々のパスを設定ファイルに追加します。

バイナリパスの指定

ホームフォルダ内の.bashrcファイルの最後に以下を追加します。

export PATH=$PATH:/opt/belledonne-communications/bin

ライブラリパスの指定

$ sudo nano /etc/ld.so.conf.d/flexisip.conf

/opt/belledonne-communications/lib

ライブラリパスの有効化

$ sudo ldconfig

暫定的には

$ export PATH=$PATH:/opt/belledonne-communications/bin
$ export LD_LIBRARY_PATH=/opt/belledonne-communications/lib

B.関連アプリのインストール・設定

B-1.Redis Serverのインストール・設定

端末間セッション確立のために必要なIPアドレス情報を一時的に保管するためのサーバ(メモリ内)を用意します。

Redis-serverのインストール

$ sudo apt install redis-server

パスワードにはMD5アルゴリズムを適用します(任意)。

$ echo your_password | md5sum

/etc/redis/redis.confの設定 bind, systemd, パスワードを設定します。

sudo nano /etc/redis/redis.conf

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.

bind 127.0.0.1 ::1


################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.

supervised systemd


################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#

requirepass xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


B-2.SNMPのインストール・設定

SIPサーバ自体の状態(CPU、メモリ、ディスク、ネットワーク使用率)監視のため、SNMPデーモンをインストールします。

SNMP: “Simple Network Management Protocol.” に必要なパッケージは以下の通りです。

$ sudo apt install snmp snmpd snmp-mibs-downloader

SNMPマネージャがMIBファイルを読み取れるように/etc/snmp/snmp.confの"mibs :"をコメントアウト(無効に)します。

# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loading them by commenting out the following line.
#mibs : コメントアウト

snmpd設定ファイル/etc/snmp/snmpd.confを編集します。

sudo pico /etc/snmp/snmpd.conf

agentAddress  udp:127.0.0.1:161
master agentx

rocommunity public localhost
rwcommunity private localhost

rouser   authOnlyUser
rwuser   authPrivUser   priv

B-3.MariaDBのインストール・SQLデータベース・テーブルの作成

登録ユーザを保管するデータベースとして利用します。sociによるSQLデータベース接続の際にはMariadb Client Libraryが必要となります。

(linphone-sdkのDocker File docker-files/bc-dev-ubuntu-rolling · master · BC / public / linphone-sdk · GitLab ではMariadbを指定しているため)。

MariaDBをインストールします。

$ sudo apt install mariadb-server mariadb-client libmariadb3

MariaDBパスワード設定

$ sudo mysql_secure_installation

rootユーザによるログイン

$ mysql -u root -p

flexisipがアクセスできる専用ユーザ"flexisip"と専用データベース"flexisip"を作成、ユーザflexisipで再ログインしてテーブル"accounts"を作成します。

MariaDB [(none)]> create user 'flexisip'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all privileges on flexisip.* to 'flexisip'@'localhost';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> create database flexisip;


MariaDB [(none)]> system mysql -u flexisip -p

MariaDB [(none)]> use flexisip;

MariaDB [flexisip]> create table if not exists accounts ( registerID INT UNSIGNED NOT NULL AUTO_INCREMENT, login VARCHAR(20) NOT NULL DEFAULT 'loginid', domain VARCHAR(20) NOT NULL DEFAULT 'sip.server.com', authid VARCHAR(20) NOT NULL DEFAULT 'authid', password VARCHAR(40) NOT NULL DEFAULT 'dd02c7c2232759874e1c205587017bed', algorithm VARCHAR(10) NOT NULL DEFAULT 'MD5', phone VARCHAR(20) NOT NULL DEFAULT '818012345678', PRIMARY KEY (registerID) );
Query OK, 0 rows affected (0.51 sec)

MariaDB [flexisip]> SHOW TABLES;
+--------------------+
| Tables_in_flexisip |
+--------------------+
| accounts           |
+--------------------+
1 row in set (0.00 sec)

MariaDB [flexisip]> DESCRIBE accounts;
+------------+------------------+------+-----+----------------------------------+----------------+
| Field      | Type             | Null | Key | Default                          | Extra          |
+------------+------------------+------+-----+----------------------------------+----------------+
| registerID | int(10) unsigned | NO   | PRI | NULL                             | auto_increment |
| login      | varchar(20)      | NO   |     | loginid                          |                |
| domain     | varchar(20)      | NO   |     | sip.server.com                   |                |
| authid     | varchar(20)      | NO   |     | authid                           |                |
| password   | varchar(40)      | NO   |     | dd02c7c2232759874e1c205587017bed |                |
| algorithm  | varchar(10)      | NO   |     | MD5                              |                |
| phone      | varchar(20)      | NO   |     | 818012345678                     |                |
+------------+------------------+------+-----+----------------------------------+----------------+
7 rows in set (0.00 sec)

MariaDB [flexisip]> SHOW CREATE TABLE accounts \G
*************************** 1. row ***************************
       Table: accounts
Create Table: CREATE TABLE `accounts` (
  `registerID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `login` varchar(20) NOT NULL DEFAULT 'loginid',
  `domain` varchar(20) NOT NULL DEFAULT 'sip.server.com',
  `authid` varchar(20) NOT NULL DEFAULT 'authid',
  `password` varchar(40) NOT NULL DEFAULT 'dd02c7c2232759874e1c205587017bed',
  `algorithm` varchar(10) NOT NULL DEFAULT 'MD5',
  `phone` varchar(20) NOT NULL DEFAULT '818012345678',
  PRIMARY KEY (`registerID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
1 row in set (0.01 sec)

MariaDB [flexisip]> INSERT INTO accounts VALUES (1001, 'friend1','sip.server.com', 'friend1', '', '', '');
Query OK, 1 row affected (0.06 sec)

MariaDB [flexisip]> select * from accounts;
+------------+---------+----------------------+---------+----------+------------+-------+
| registerID | login   | domain               | authid  | password | algorithm | phone |
+------------+---------+----------------------+---------+----------+------------+-------+
|       1001 | friend1 | sip.server.com       | friend1 |          |            |       |
+------------+---------+----------------------+---------+----------+------------+-------+
1 row in set (0.00 sec)

C.起動・動作確認

C-1.ルータのポート開放(ポートフォワード)

ルータのfirewall設定メニューでポートフォワードを設定します。WANからの5070/tcp,udpアクセスをLANのIPアドレス(flexisipのIP192.168.x.xxx:5070 tcp/udp)へ導きます。ルータにより設定方法・名称が異なります。

RTP用ポート(flexisip.confの[module::mediarelay]で設定する ポート10000-10100 udp)も同様に開放します。

C-2.Flexisipの設定・起動

Flexisipの設定ファイルの雛形を/etc/flexisip/flexisip.confにコピーします。

$ sudo /opt/belledonne-communications/bin/flexisip --dump-default all > /etc/flexisip/flexisip.conf

/etc/flexisip/flexisip.confを編集します。設定項目が多く本設定が最適とは限りません。必要であれば変更・修正して下さい。

[global]
log-directory=/var/opt/belledonne-communications/log/flexisip
log-level=error
syslog-level=error
user-errors-logs=false
contextual-log-filter=
contextual-log-level=debug
dump-corefiles=true
auto-respawn=true
aliases=sip.testsite.com localhost
default-servers=proxy presence

transports=sip:sip.testsite.com:5070;maddr=192.168.x.xxx

idle-timeout=3600
keepalive-interval=1800
proxy-to-proxy-keepalive-interval=0
require-peer-certificate=false
transaction-timeout=32000
udp-mtu=1460
enable-snmp=true
unique-id=
plugins-dir=/opt/belledonne-communications/lib/flexisip/plugins
plugins=

[stun-server]
enabled=true
bind-address=0.0.0.0
port=3478

[presence-server]
enabled=true
transports=sip:127.0.0.1:5065;transport=tcp
expires=600
notify-limit=200
leak-detector=false
long-term-enabled=true
bypass-condition=false
external-list-subscription-request=
soci-connection-string=db=flexisip user=flexisip password='password' host=localhost
max-thread=50
max-thread-queue-size=50

[conference-server]
enabled=true
transport=sip:127.0.0.1:6064;transport=tcp
conference-factory-uri=
enable-one-to-one-chat-room=true
outbound-proxy=sip:127.0.0.1:5070;transport=tcp
database-backend=mysql
database-connection-string=db=flexisip user=flexisip password='password' host=localhost
check-capabilities=true

[module::DoSProtection]
enabled=true
filter=
time-period=15000
packet-rate-limit=20
ban-time=1
iptables-chain=FLEXISIP

[module::SanityChecker]
enabled=true
filter=

[module::NatHelper]
enabled=true
filter= !(user-agent contains 'No NatHelper')
contact-verified-param=verified
fix-record-routes=false
fix-record-routes-policy=safe

[module::Authentication]
enabled=true
filter=
auth-domains=sip.testsite.com localhost
disable-qop-auth=false
no-403=false
nonce-expires=3600
realm-regex=
trusted-hosts=127.0.0.1
db-implementation=soci
cache-expire=1800
reject-wrong-client-certificates=false
new-auth-on-407=false
enable-test-accounts-creation=false
trust-domain-certificates=false
soci-password-request=select password from accounts where login = :id and domain = :domain
soci-user-with-phone-request=select login from accounts where phone = :phone
soci-users-with-phones-request=select login, domain, phone from accounts where phone in (:phones)
soci-poolsize=100
soci-backend=mysql
soci-connection-string=db=flexisip user=flexisip password='password' host=localhost
soci-max-queue-size=1000

[module::Presence]
enabled=true
filter=is_request && (request.method-name == 'PUBLISH' || request.method-name == 'NOTIFY' || request.method-name == 'SUBSCRIBE')
presence-server=sip:127.0.0.1:5065;transport=tcp
only-list-subscription=false
check-domain-in-presence-results=false

[module::Registrar]
enabled=true
filter=
reg-domains=sip.testsite.com
reg-on-response=false
max-contacts-by-aor=12
unique-id-parameters=+sip.instance pn-tok line
max-expires=86400
min-expires=60
force-expires= -1
static-records-file=
static-records-timeout=600
db-implementation=redis
redis-server-domain=localhost
redis-server-port=6379
redis-auth-password=xxxxxxxxxxxxxxxxxxxxxxxxxx
redis-server-timeout=1500
redis-record-serializer=protobuf
redis-slave-check-period=60
service-route=
name-message-expires=message-expires
register-expire-randomizer-max=0

[module::StatisticsCollector]
enabled=true
filter=is_request && request.method-name == 'PUBLISH'
collector-address=sip:sip.testsite.com:5070

[module::Router]
enabled=true
filter=
use-global-domain=false
fork=true
stateful=true
fork-late=false
fork-no-global-decline=false
treat-decline-as-urgent=false
treat-all-as-urgent=false
call-fork-timeout=20
call-fork-urgent-timeout=5
call-fork-current-branches-timeout=10
call-push-response-timeout=0
message-fork-late=true
message-delivery-timeout=60
message-accept-timeout=15
fallback-route=
allow-target-factorization=false
permit-self-generated-provisional-response=true
generated-contact-route=
generated-contact-expected-realm=
generate-contact-even-on-filled-aor=false
preroute=
resolve-routes=true
parent-domain-fallback=false

[module::MediaRelay]
enabled=true
filter=
nortpproxy=nortpproxy
sdp-port-range-min=10000
sdp-port-range-max=10500
bye-orphan-dialogs=false
max-calls=0
force-relay-for-non-ice-targets=true
prevent-loops=true
early-media-relay-single=true
max-early-media-per-call=0
inactivity-period=3600
force-public-ip-for-sdp-masquerading=false
drop-telephone-event=false

[module::Forward]
enabled=true
filter=
route=
add-path=true
rewrite-req-uri=false
default-transport=udp
params-to-remove=pn-tok pn-type app-id pn-msg-str pn-call-str pn-call-snd pn-msg-snd pn-timeout pn-silent

Flexisipをサービスデーモンとして起動します。

$ sudo service flexisip-proxy start

ステータス確認

$ sudo service flexisip-proxy status

● flexisip-proxy.service - Flexisip proxy server
   Loaded: loaded (/lib/systemd/system/flexisip-proxy.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-07-22 11:06:43 JST; 7h ago
     Docs: http://www.linphone.org/technical-corner/flexisip/overview
  Process: 26504 ExecStart=/opt/belledonne-communications/bin/flexisip --server proxy --daemon --syslog --pidfile /var/run/flexisip-proxy.pid (code=exited, status=0/SUCCESS)
 Main PID: 26527 (flexisipwd-prox)
    Tasks: 110 (limit: 4915)
   CGroup: /system.slice/flexisip-proxy.service
           ├─26527 /opt/belledonne-communications/bin/flexisip --server proxy --daemon --syslog --pidfile /var/run/flexisip-proxy.pid
           └─26528 /opt/belledonne-communications/bin/flexisip --server proxy --daemon --syslog --pidfile /var/run/flexisip-proxy.pid

 7月 22 11:06:42 thinkpad-e450 systemd[1]: Starting Flexisip proxy server...
 7月 22 11:06:42 thinkpad-e450 flexisip[26504]: Writing logs in : /var/opt/belledonne-communications/log/flexisip/flexisip-proxy.log
 7月 22 11:06:42 thinkpad-e450 flexisip[26504]: [LAUNCHER] Watchdog PID: 26527
 7月 22 11:06:43 thinkpad-e450 flexisip[26504]: NET-SNMP version 5.7.3 AgentX subagent connected
 7月 22 11:06:43 thinkpad-e450 systemd[1]: Started Flexisip proxy server.

C-3.携帯端末による動作確認

2つの異なる外部ネットワークの端末から接続を試みます。SIP-VoIPアプリとしてLinphone、ZoiPerなどを利用します。

  • SIPポートは5070/tcpを指定(flexisip.confの設定による)
  • DTMF:SIP
  • STUNサーバーとプロキシサーバのドメインとポート番号は同一
  • Outbound Proxyを指定(SIPプロキシ経由で呼び出し)

C-4.Netstatによる確立したセッションの確認

Netstatにより両者間のIPアドレスによるセッション確立状態を確認します。

$ sudo netstat -antpu | grep flexisip

tcp        0      0 192.168.x.xxx:5070      0.0.0.0:*               LISTEN      8515/flexisip       
tcp        0      0 127.0.0.1:39338         127.0.0.1:6379          ESTABLISHED 8515/flexisip       
tcp        0      0 127.0.0.1:39336         127.0.0.1:6379          ESTABLISHED 8515/flexisip       
tcp        0      0 192.168.x.xxx:5070      39.122.226.44:63008     ESTABLISHED 8515/flexisip       
tcp        0      0 192.168.x.xxx:5070      150.66.94.119:45470     ESTABLISHED 8515/flexisip       
udp        0      0 0.0.0.0:10036           0.0.0.0:*                           8515/flexisip       
udp        0      0 0.0.0.0:10037           0.0.0.0:*                           8515/flexisip       
udp        0      0 0.0.0.0:10492           0.0.0.0:*                           8515/flexisip       
udp        0      0 0.0.0.0:10493           0.0.0.0:*                           8515/flexisip       
udp        0      0 0.0.0.0:3478            0.0.0.0:*                           8515/flexisip       
udp        0      0 192.168.x.xxx:5070      0.0.0.0:*                           8515/flexisip

SNMPの補足説明

https://wiki.debian.org/SNMP

SNMP MIB

MIB: Management Information Base

ネットワーク内のデバイス(PC,プリンタ、モバイルなど)の中で管理されているオブジェクト(CPU,メモリ、ハードディスク、プリンタカートリッジ、ネットワークデバイスなど)とそれらの属性情報(ステータス)を細かく階層化して纏めたもの。

SNMP OID

OID: Object Identifiers

上記オブジェクトの認識ID 例) 1.3.6.1.4.1.343
OIDの各番号に対応したテキスト表記、ベンダー情報など最新のMIBを取得するため、snmp-mibs-downloaderが必要になります。

最新MIBSへのアップデート

 $ sudo download-mibs

SNMPの起動・停止

$ sudo /etc/init.d/snmpd start
$ sudo /etc/init.d/snmpd stop

データベース接続エラー

[SOCI] connection pool open MySQL error: 2002 Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

リンク設定

$ sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

AppArmorによるMariaDBシェアライブラリ読み取りエラー

インストール後のシステムではサービス起動しますが、再起動後シェアライブラリ読み取りエラーが発生し起動しない。(ライブラリへのパスエラー、ファイルが無いことが原因ではない)

エラー対策

MySQLからMariaDBへと移行した際にAppArmorの設定も引き継がれるようです。
MariaDBではAppArmorの使用は推奨していないため無効にします。

$ sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/usr.sbin.mysqld

/etc/apparmor.d/cache/usr.sbin.mysqldも削除します。

$ sudo rm /etc/apparmor.d/cache/usr.sbin.mysqld

設定を反映

$ sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld

再起動後動作を確認して下さい。

参考:AppArmorとMySQL

Flexisip Dockerfie, Composeファイル(Ubuntu18.04、Debian9 Stretch)追加

Dockerfile and Docker-Compose(with nginx-proxy) files for Ubuntu and Debian

Flexisip DEB Pakages for Ubuntu 18.04

ネットワークアクティブポートの確認

netstatに加えてlsof、nmapコマンドを使用します。

lsof

$ sudo lsof -i -P -n
$ sudo lsof -i -P -n | grep LISTEN
$ sudo lsof -i:22 ## see a specific port such as 22 ##

netstat

$ netstat -tulpn | grep LISTEN

ss

$ sudo ss -tulw
$ sudo ss -tulwn

  • -t : Show only TCP sockets on Linux
  • -u : Display only UDP sockets on Linux
  • -l : Show listening sockets. For example, TCP port 22 is opened by SSHD server.
  • -p : List process name that opened sockets
  • -n : Don’t resolve service names i.e. don’t use DNS

nmap

$ sudo nmap -sT -O localhost
$ sudo nmap -sU -O 192.168.2.13 ##[ list open UDP ports ]##
$ sudo nmap -sT -O 192.168.2.13 ##[ list open TCP ports ]##

Flexisip is the name of a general purpose SIP proxy server developed by BC, which
includes specific features for mobile phones, like a push gateway.

Main features :

  • SIP over UDP, TCP, TLS
  • NAT helper, media relay
  • STUN server
  • Digest authentication based on external SQL password database or static file.
  • Registrar
  • Audio transcoding
  • High level event logging for activity monitoring.
  • High availability and cluster mode operation for large deployments.
  • Interconnected with push notifications systems for reliably notifying mobile apps of
  • incoming calls or messages.

アカウントのパスワードにMD5またはSHA-256の暗号化を導入する場合、以下書式で暗号化

データベースへの平文でのパスワード格納は一般的でないため必ず暗号化すること。
FlexisipではMD5とSHA-256に対応しているがSHA-256がベター。

Flexisipのパスワードは、(ユーザID:ドメイン:平文パスワード)をセットにして暗号化している。

MD5

MD5(‘acountID:domain:password’)

SHA-256

SHA2(‘acountID:domain:password’,256)

examples)

MD5

mysql> update table_name set password = MD5('user1:test.site.com:secretpass') where id=1;

SHA-256

mysql> update table_name set password = SHA2('user1:test.site.com:secretpass', 256) where id=1;

参考:Flexisip soci code

https://github.com/BelledonneCommunications/flexisip/blob/master/src/authdb-soci.cc


php インタラクティブシェルにより確認

$ php -a
Interactive shell
php > $ha1 = md5("user_id:sip.example.com:password");
php > echo $ha1;
1d2d9f48ac0213e239764b44ea6cfc0f
php > exit

prepare.pyの各機能表示

bc@xxxxxxxxx:~/flexisip$ ./prepare.py -h
usage: prepare.py [-h] [-c] [-cc] [-d] [-dv] [-f] [-G GENERATOR] [-g] [-L]
                  [-lf] [--tunnel] [-sys]
                  [target [target ...]]

Prepare build of Linphone and its dependencies.

positional arguments:
  target                The target(s) to build for (default is 'flexisip').
                        Space separated targets in list: flexisip-rpm,
                        flexisip.

optional arguments:
  -h, --help            show this help message and exit
  -c, --clean           Clean a previous build instead of preparing a build.
  -cc, --ccache         Use ccache to speed up the build process.
  -d, --debug           Prepare a debug build, eg. add debug symbols and use
                        no optimizations.
  -dv, --debug-verbose  Activate ms_debug logs.
  -f, --force           Force preparation, even if working directory already
                        exist.
  -G GENERATOR, --generator GENERATOR
                        CMake build system generator (default: let CMake
                        choose, use cmake -h to get the complete list).
  -g, --group           Group Linphone related builders.
  -L, --list-cmake-variables
                        List non-advanced CMake cache variables.
  -lf, --list-features  List optional features and their default values.
  --tunnel, --no-tunnel
                        Enable/Disable Tunnel.
  -sys, --use-system-dependencies
                        Find dependencies on the system.

cmake3.11を有効にするためパッケージリストからインストールするcmakeを削除。

# Install development tools
RUN apt-get update && \
    apt-get install -y alien at autoconf bison ccache clang doxygen elfutils g++ gdb git graphviz intltool libtool lsb-release make nasm ninja-build openssh-client patch python-pip python-pystache python-six yasm && \
    apt-get clean && \
    pip install sphinx javasphinx sphinx_csharp
 .........................................

# Install CMake 3.11
RUN curl -o cmake.tar.gz https://cmake.org/files/v3.11/cmake-3.11.4.tar.gz && \
    tar xvzf cmake.tar.gz && rm cmake.tar.gz && cd cmake-3.11.4 && cmake . && make -j5 install && cd .. && rm -rf cmake-3.11.4

linphone-sdkコンテナ内で以下リンクを作成。

$ sudo ln -s /usr/local/bin/cmake /usr/bin/cmake

A-4.prepare.pyによるビルドスクリプトの作成

以下A-4の内容修正

  • cmake-rpm-macrosのインストールは必要なくなりました。
  • flexisipのrpmファイル作成時のエラー対応のためsystemd-rpm-macrosのインストールが必要になります。

flexisipのrpmファイル作成時のエラー
https://github.com/BelledonneCommunications/flexisip/issues/64

flexisip/build/rpm/flexisip.spec.cmake内の%{systemd_requires}

Unknown tag: %{systemd_requires}

<対策>
systemd-rpm-macros をダウンロード・インストールします。

https://rpmfind.net/linux/rpm2html/search.php?query=systemd-rpm-macros

今回は以下のバージョンを採用しました。

https://rpmfind.net/linux/fedora/linux/releases/30/Everything/x86_64/os/Packages/s/systemd-rpm-macros-241-7.gita2eaa1c.fc30.noarch.rpm

flexisip-sdkコンテナ内でmacros.systemdをコピーします。

$ sudo cp macros.systemd /usr/lib/rpm/macros.d

prepare.pyによるビルドオプション(デフォルト)の確認

bc@xxxxxxxxxxxx:~/flexisip$ ./prepare.py -lf
INFO: Searching for available features...
cmake install rpath: /home/bc/flexisip/OUTPUT/lib
cmake install rpath: /home/bc/flexisip/OUTPUT/lib
cmake install rpath: /home/bc/flexisip/OUTPUT/lib
cmake install rpath: /home/bc/flexisip/OUTPUT/lib
cmake install rpath: /home/bc/flexisip/OUTPUT/lib
INFO: Here are available features:
	ENABLE_XML2=ON
	ENABLE_LIME_X3DH=OFF
	ENABLE_AMRNB=OFF
	ENABLE_DB_STORAGE=ON
	ENABLE_H263=OFF
	ENABLE_RTP_MAP_ALWAYS_IN_SDP=OFF
	ENABLE_PROTOBUF=OFF
	ENABLE_CXX_WRAPPER=OFF
	ENABLE_AMRWB=OFF
	ENABLE_VCARD=OFF
	ENABLE_ZLIB=ON
	ENABLE_MBEDTLS=ON
	ENABLE_ILBC=OFF
	ENABLE_JAVA_WRAPPER=OFF
	ENABLE_CSHARP_WRAPPER=OFF
	ENABLE_SQLITE=ON
	ENABLE_UNMAINTAINED=OFF
	ENABLE_JAZZY_DOC=OFF
	ENABLE_UPDATE_CHECK=OFF
	ENABLE_LIME=OFF
	ENABLE_TRANSCODER=ON
	ENABLE_H263P=OFF
	ENABLE_SILK=OFF
	ENABLE_CAMERA2=OFF
	ENABLE_V4L=OFF
	ENABLE_FFMPEG=OFF
	ENABLE_NON_FREE_CODECS=OFF
	ENABLE_QRCODE=OFF
	ENABLE_TOOLS=OFF
	ENABLE_SOCI=ON
	ENABLE_OPENH264=OFF
	ENABLE_BV16=OFF
	ENABLE_ISAC=OFF
	ENABLE_SRTP=OFF
	ENABLE_REDIS=ON
	ENABLE_WEBRTC_VAD=OFF
	ENABLE_MKV=OFF
	ENABLE_MPEG4=OFF
	ENABLE_ASSETS=OFF
	ENABLE_G729B_CNG=OFF
	ENABLE_SWIFT_WRAPPER=OFF
	ENABLE_JWE_AUTH_PLUGIN=ON
	ENABLE_PCAP=OFF
	ENABLE_GSM=OFF
	ENABLE_DEBUG_LOGS=OFF
	ENABLE_GPL_THIRD_PARTIES=OFF
	ENABLE_OPUS=OFF
	ENABLE_MDNS=OFF
	ENABLE_DOC=OFF
	ENABLE_G726=OFF
	ENABLE_SNMP=OFF
	ENABLE_VPX=OFF
	ENABLE_G729=OFF
	ENABLE_RELATIVE_PREFIX=OFF
	ENABLE_X264=OFF
	ENABLE_CONFERENCE=ON
	ENABLE_VIDEO=OFF
	ENABLE_ADVANCED_IM=ON
	ENABLE_SPEEX=ON
	ENABLE_POLARSSL=OFF
	ENABLE_UNIT_TESTS=ON
	ENABLE_SOCI_MYSQL=OFF
	ENABLE_WEBRTC_AECM=OFF
	ENABLE_EXTERNAL_AUTH_PLUGIN=OFF
	ENABLE_ZRTP=OFF
	ENABLE_CODEC2=OFF
	ENABLE_WEBRTC_AEC=OFF
	ENABLE_PRESENCE=ON
	ENABLE_JPEG=OFF
	ENABLE_TUNNEL=OFF
	ENABLE_GTK_UI=OFF
	ENABLE_NLS=OFF
INFO: To enable some feature, please use -DENABLE_SOMEOPTION=ON (example: -DENABLE_OPUS=ON)
INFO: Similarly, to disable some feature, please use -DENABLE_SOMEOPTION=OFF (example: -DENABLE_OPUS=OFF)

srtp, zrtp, lime, lime-x3dh, qrcodeなどのサブモジュールを有効にしてビルド
(rpmパッケージでのビルドではエラーとなるため、バイナリとライブラリ等を直接出力)

bc@xxxxxxxxxx:~/flexisip$ ./prepare.py -DENABLE_REDIS=YES -DENABLE_TRANSCODER=YES -DENABLE_UNIT_TESTS=OFF -DENABLE_SOCI_MYSQL=YES -DENABLE_PRESENCE=YES -DENABLE_CONFERENCE=YES -DENABLE_SNMP=YES -DENABLE_DOC=OFF -DENABLE_PROTOBUF=YES -DENABLE_MDNS=NO -DENABLE_JWE_AUTH_PLUGIN=YES -DENABLE_EXTERNAL_AUTH_PLUGIN=YES -DENABLE_LIME=ON -DENABLE_LIME_X3DH=ON -DENABLE_SRTP=ON -DENABLE_ZRTP=ON -DENABLE_QRCODE=ON -DCMAKE_PREFIX_PATH=/opt/belledonne-communications -DCMAKE_INSTALL_PREFIX=/opt/belledonne-communications -DSYSCONF_INSTALL_DIR=/etc
bc@xxxxxxxxxx:~/flexisip$ sudo make

flexisip-sdkコンテナ内の /opt/belledonne-communications にバイナリ、ライブラリが出力されます。

bc-flexisipコンテナ内でビルドした出力ファイルをホスト側へコピーします。

$ mkdir opt
$ docker cp bc-flexisip:/opt/belledonne-communications ./opt

Flexisip(Ubunu18.04) Docker System

DockerコンテナによるFlexisip:SIPシステムの構築例です。
optフォルダにflexisip-sdkによりビルドしたバイナリファイルと関連ライブラリが格納されています。

docker-compose.yml nginx-lets.ymlの内容については、各々の環境により変更する必要があります。

$ cd nginx+letsencrypt_ver3
$ docker-compose up -f nginx-lets.yml -d
$ cd ..
$ sudo make flexisip-ubuntu-build
$ docker-compose up -d