せでぃのブログ

ブログ初心者おいどんのどうでもいい愚痴やどうでもいい愚痴やどうでもいいマメ知識などを披露するチラシの裏です。

CentOS6.5にasterisk11.10.0インストール設定中

asterisk11.10.0インストール設定中。日本語パッチがここまでしかなかった。
f:id:Sediment:20140814124703p:plain

本体ソースダウンロード

 11.10.0のソースはこの辺。old-releaseにある。
 全体の流れは次のインストールで。
http://downloads.asterisk.org/pub/telephony/asterisk/old-releases/

インストール

configure,make

 基本設定ガイドの方が単純でわかりやすいけど、結局、voip-info.jpを参考にして書き直したような感じだね。インストール全体については、x-liteの設定以外はvoip-info.jpの方が良さそう。
 configureはデフォルトで。configure--help見たけどあんまわからず。
 現在のところ、インストールして、日本語パッチを当てて、既存のconfの上から1.6のサンプルconfをダバっと入れて上書きして(既存のconfはサンプルconfよりも遥かに種類が多い。上書きするので、confのバックアップは忘れずに。)、セキュリティ関連の設定をしただけ。
 PC周辺がズル林でなかなか近寄れない作業進まないww
Asterisk基本設定ガイド!
Asterisk 11 - VOIP-Info.jp Wiki
Asterisk サンプル設定ファイル - VOIP-Info.jp Wiki

日本語パッチ適用

本体のソースをmake installまでやったら、パッチをダウンロードして、
Index of /asterisk/patch/11.10.0

# patch -p0 < パッチファイル名

でパッチ2つ適用。再度、
# make
# make install
Asterisk パッチ - VOIP-Info.jp Wiki

日本語音声ファイルダウンロード

 ver1.8もあったが、何故かエコーテストのファイルが入ってなかったので、ver1.6をそのまま入れた方が楽。
 soundsディレクトリの配下にjaディレクトリがあればおk。voip-info.jpのconfサンプルファイルで周辺の設定は終わってるので、ここでは配置するだけでいい。
# cd /var/lib/asterisk/sounds
# wget 'ダウンロードリンク'
Asterisk 1.8 - VOIP-Info.jp Wiki

asterisk.confサンプル修正

  1. 「astrundir」の位置を修正。
  2. 「live_dangerously = no」追加

[root@centos spool]# vi /etc/asterisk/asterisk.conf

[directories]
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir => /var/run/asterisk
astlogdir => /var/log/asterisk
[options]
languageprefix=yes
live_dangerously = no
(END)

 理由はこの辺。
起動時のerror 「does /var/run/asterisk.ctl exist?」 : 小型PC・H8のメモ
電算機孝行: asterisk 1.8.25.0 へアップグレード(重要項目あり)

iptables

 続いて、セキュリティ関連の設定をば。iptablesはザックリこんな感じ。まぁ、後で問題が出てきたらまた追加する。
ポート5060はSIPなのでsip.confで指定してる。
ポート10000-20000はRTPなのでrtp.conf。
[root@centos ~]# vi /etc/sysconfig/iptables

  • A INPUT -p udp -m udp --dport 5060 -j ACCEPT
  • A INPUT -p udp -m udp --dport 10000:20000 -j ACCEPT

IAX2用ポート。これ、開けてなくてもasteriskとIAX2の通信できるから不思議。wikiを読むにそういうFW越えできるパケットらしい。お好みで。敢えて不思議体験するのもあり。
ポート4569の指定はiax.conf。

  • A INPUT -p udp -m udp --dport 4569 -j ACCEPT

SELinux

 初期起動時は、audit.logにはこんな感じのメッセージが多数。

type=AVC msg=audit(1407985224.106:5): avc: denied { create } for pid=1735 comm="asterisk" name="asterisk.ctl" scontext=system_u:system_r:asterisk_t:s0 tcontext=system_u:object_r:var_run_t:s0 tclass=sock_file

 voip-info.jpを始め、SELinux無効で!という記事が多くて困った。無効にはしたくない。
 インストールしたversionのせいかはわからんが、ユーザにもグループにもasteriskという人間はいないので、chownは必要なさそう。これでアクセス権に問題があれば、取り敢えずSELinux=chconである。asteriskSELinux関連の方針はこちら。
man asterisk_selinux howto selinux-policy-3.7.19-155.el6_3.noarch.rpm

DESCRIPTION

SELinux Linux securesasterisk(Asterisk IP telephony server)processes via flexible mandatory accesscontrol.

FILE CONTEXTS

SELinux requires files to have an extended attribute to define the file type.
You can see the context of a file using the -Z option to lsPPolicy governs the access confined processes have to these files. SELinux asterisk policy is very flexible allowing users to setup their asterisk processes in as secure a method as possible.

The following file types are defined for asterisk:

asterisk_etc_t

  • Set files with the asterisk_etc_t type, if you want to store asterisk files in the /etc directories.

asterisk_exec_t

  • Set files with the asterisk_exec_t type, if you want to transition an executable to the asterisk_t domain.

asterisk_initrc_exec_t

  • Set files with the asterisk_initrc_exec_t type, if you want to transition an executable to the asterisk_initrc_t domain.

asterisk_log_t

  • Set files with the asterisk_log_t type, if you want to treat the data as asterisk log data, usually stored under the /var/log directory.

asterisk_spool_t

  • Set files with the asterisk_spool_t type, if you want to store the asterisk files under the /var/spool directory.

asterisk_tmp_t

  • Set files with the asterisk_tmp_t type, if you want to store asterisk temporary files in the /tmp directories.

asterisk_tmpfs_t

  • Set files with the asterisk_tmpfs_t type, if you want to store asterisk files on a tmpfs file system.

asterisk_var_lib_t

  • Set files with the asterisk_var_lib_t type, if you want to store the asterisk files under the /var/lib directory.

asterisk_var_run_t

  • Set files with the asterisk_var_run_t type, if you want to store the asterisk files under the /run directory.

Note: File context can be temporarily modified with the chcon command. If you want to permanently change the file context you need to use thesemanage fcontext command. This will modify the SELinux labeling database. You will need to userestoreconto apply the labels.

tail -n 50 /var/log/audit/audit.log | grep denied
ls -Z
で表示されるものを片っ端から潰していく。表示しきれないので、1つ2つ潰したらasterisk再起動が手っ取り早いすな。こちらは「/var/run」「/var/lib」「/var/spool」の3つだけでしたが。
「var_hoge_t」を「asterisk_var_hoge_t」に直すだけ。

[root@centos run]# cd /var/lib
[root@centos lib]# pwd
/var/lib
root@centos lib]# ls -Z | grep asterisk
drwxr-xr-x. root root unconfined_u:object_r:var_lib_t:s0 asterisk
[root@centos lib]# chcon -R unconfined_u:object_r:asterisk_var_lib_t:s0 asterisk
[root@centos lib]# ls -Z | grep asterisk
drwxr-xr-x. root root unconfined_u:object_r:asterisk_var_lib_t:s0 asterisk
[root@centos lib]#

[root@centos asterisk]# cd /var/run
[root@centos run]# pwd
/var/run
[root@centos run]# ls -Z | grep asterisk
drwxr-xr-x. root root unconfined_u:object_r:var_run_t:s0 asterisk

[root@centos run]# chcon -R unconfined_u:object_r:asterisk_var_run_t:s0 asterisk

[root@centos run]# ls -Z | grep asterisk
drwxr-xr-x. root root unconfined_u:object_r:asterisk_var_run_t:s0 asterisk

[root@centos ~]# cd /var/spool
[root@centos spool]# pwd
/var/spool
[root@centos spool]# ls -Z | grep asterisk
drwxr-xr-x. root root unconfined_u:object_r:var_spool_t:s0 asterisk
[root@centos spool]# chcon -R unconfined_u:object_r:asterisk_spool_t:s0 asterisk
[root@centos spool]# ls -Z | grep asterisk
drwxr-xr-x. root root unconfined_u:object_r:asterisk_spool_t:s0 asterisk


これで再起動すれば解決してるはず。

[root@centos ~]# service asterisk restart
Stopping safe_asterisk: [ OK ]
Shutting down asterisk: [ OK ]
asterisk を起動中:


[root@centos ~]# tail -n 50 /var/log/audit/audit.log | grep denied
[root@centos ~]#

ダイヤルプラン

基本設定ガイド!がわかりやすい。
下記の課題が解決できたら、設計と一緒に記事にする。

目下の課題

  1. ビジー音を鳴らしたい
  2. active-passiveモードの移行に慣れない
  3. 電番の滑りの設定を入れたい
  4. VoIPルータにアナログ電話を繋ぐ