OpenSIPSをCentOS5.5にインストールする方法

超久々の更新はOpenSIPSをCentOS5.5にインストールする方法です。
まだあれこれテスト中なので、とりあえず備忘録です。間違ってたら教えてください。

CentOS5.5を準備したらコンパイルに必要な物をいれておきます。
とりあえず"Development tools"を入れておけば問題ないでしょう。他にもパッケージが必要っぽいので入れておきます。


yum -y groupinstall "Development tools"
yum -y install zlib-devel openssl-devel mysql mysql-devel gcc bison flex subversion

OpenSIPSからソースを取得します。
色々な方法が可能ですが、今回は最新版をSVNでチェックアウトします。
今日現在では1.6.4が最新ぽいので1.6を取得。


cd /usr/src/
svn co https://opensips.svn.sourceforge.net/svnroot/opensips/branches/1.6 opensips

あとはコンパイルですが、mysqlを利用する場合はMakefileの52行目あたりを修正します。


cd opensips
vi Makefile

52行目付近の「db_mysql」を削除します。
修正前
# if not set on the cmd. line or the env, exclude this modules:
exclude_modules?= b2b_logic jabber cpl-c xmpp rls mi_xmlrpc xcap_client \
db_mysql db_postgres db_unixodbc db_oracle db_berkeley aaa_radius \
osp perl snmpstats perlvdb carrierroute mmgeoip \
presence presence_xml presence_mwi presence_dialoginfo \
pua pua_bla pua_mi pua_usrloc pua_xmpp pua_dialoginfo \
ldap h350 identity regex memcached db_http json dialplan

修正後
# if not set on the cmd. line or the env, exclude this modules:
exclude_modules?= b2b_logic jabber cpl-c xmpp rls mi_xmlrpc xcap_client \
db_postgres db_unixodbc db_oracle db_berkeley aaa_radius \
osp perl snmpstats perlvdb carrierroute mmgeoip \
presence presence_xml presence_mwi presence_dialoginfo \
pua pua_bla pua_mi pua_usrloc pua_xmpp pua_dialoginfo \
ldap h350 identity regex memcached db_http json dialplan

上を保存したら
make clean
make
make install

でインストールが完了します。

インストールが完了したら、起動テストを行います。


[root@OpenSIPS 1.6]# opensipsctl start

INFO: Starting OpenSIPS :
INFO: started (pid: 17413)

起動したらプロセスをチェックするとこんな感じです。
[root@OpenSIPS 1.6]# ps aux | grep opensips
root 17413 0.0 0.5 38240 2872 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17415 0.0 0.1 38244 676 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17416 0.0 0.1 38240 584 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17417 0.0 0.1 38240 580 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17418 0.0 0.1 38240 580 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17419 0.0 0.1 38240 580 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17420 0.0 0.1 38240 584 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17421 0.0 0.1 38240 584 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17422 0.0 0.1 38240 584 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17423 0.0 0.1 38240 584 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17424 0.0 0.0 38240 464 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17425 0.0 0.1 38240 592 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17426 0.0 0.1 38240 668 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17427 0.0 0.1 38240 668 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17428 0.0 0.1 38240 668 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17429 0.0 0.1 38240 668 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17430 0.0 0.1 38240 656 ? S 23:19 0:00 /usr/local/sbin/opensips -P /var/run/opensips.pid
root 17435 0.0 0.1 5080 760 pts/0 R+ 23:20 0:00 grep opensips


次に、インストールするだけでは起動スクリプトが入っていないのでコピーして持ってきます。


cp /usr/src/opensips/packaging/fedora/opensips.init /etc/init.d/opensips
chmod +x /etc/init.d/opensips

この起動スクリプトもこのままでは動きませんので修正します。
修正は4箇所です。


#!/bin/bash
#
# Startup script for OpenSIPS
#
# chkconfig: - 85 15 <=ココを下行に書き換え
# chkconfig: 345 96 15
# description: OpenSIPS is a fast SIP Server.
#
# processname: opensips
# pidfile: /var/run/opensips.pid
# config: /etc/opensips/opensips.cfg
#
### BEGIN INIT INFO
# Provides: opensips
# Required-Start: $local_fs $network $named
# Should-Start: mysqld postgresql
# Short-Description: start, stop OpenSIPS
# Description: OpenSIPS is a very fast and flexible SIP (RFC3261) server.
## END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

#oser=/usr/sbin/opensips <=ココを下行に書き換え
oser=/usr/local/sbin/opensipsctl
PATH=/sbin:/bin:/usr/local/sbin:/usr/local/bin <=追記
prog=opensips
RETVAL=0

[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

start() {
echo -n $"Starting $prog: "
# there is something at end of this output which is needed to
# report proper [ OK ] status in Fedora scripts
#daemon $oser $OPTIONS 2>/dev/null | tail -1 <=ココを下行に書き換え
daemon $oser $OPTIONS >/dev/null 2>/dev/null
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/$prog

あとはchkconfigで起動出来るように追加


[root@OpenSIPS 1.6]# chkconfig --add opensips
[root@OpenSIPS 1.6]# chkconfig opensips on
[root@OpenSIPS 1.6]# chkconfig --list opensips
opensips 0:off 1:off 2:on 3:on 4:on 5:on 6:off

これで完了です。
起動はstartです。stop|reload|restart|condrestart|status|helpも利用できます


opensipsctl start

service opensips start