Kamailio是一个开源Sip服务器,支持很多的功能并且有很好的扩展性。在ubuntu系统上,Kamailio有两种安装方式,一种是通过apt-get安装,另一种是源码安装。本文记录了笔者通过源码安装kamailio的过程,如有安装问题,欢迎留言交流。
1.下载源码
$ git clone git://git.sip-router.org/kamailio kamailio
$ cd kamailio
$ git checkout -b 4.2 origin/4.2 or
git checkout -b 4.3 origin/4.3
注:刚下载的代码是主分支上的代码,可以通过上面的git checkout命令切换到4.2分支或者4.3分支。
2.编译配置
$ make include_modules="db_mysql mi_fifo" cfg
打开modules.lst文件,可以看到如下内容
include_modules= db_mysql mi_fifo
3.编译
$make all
4.安装
$sudo make install
安装完成后可看到下面这些文件:
/usr/local/sbin/kamctl
/usr/local/sbin/kamailio
/usr/local/etc/kamailio/kamailio.cfg
/usr/local/etc/kamailio/kamctlrc
5.修改配置文件
/usr/local/etc/kamailio/kamailio.cfg:
文件头添加4行:
#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_ALIASDB
#!define WITH_USRLOCDB
#!ifndef DBURL
#!define DBURL "mysql://root:hello@localhost/kamailio" //root是用户名,hello是密码
#!endif
启动时如果出现如下错误:
ERROR: Error opening Kamailio's FIFO /tmp/kamailio_fifo
ERROR: Make sure you have the line 'modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")' in your config
解决办法:
#modparam("mi_fifo", "fifo_name", "/var/run/kamailio/kamailio_fifo")改成下面这一行
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
/usr/local/etc/kamailio/kamctlrc:
#SIP_DOMAIN=127.0.0.1
SIP_DOMAIN=192.168.40.132 //kamailio所在的域
# If you want to setup a database with kamdbctl, you must at least specify
# this parameter.
DBENGINE=MYSQL
## database host
DBHOST=localhost
## database name (for ORACLE this is TNS name)
DBNAME=kamailio
## database access host (from where is kamctl used)
DBACCESSHOST=127.0.0.1
## database read/write user
DBRWUSER="kamailio"
## database super user (for ORACLE this is 'scheme-creator' user)
DBROOTUSER="root"
## database access host (from where is kamctl used)
DBACCESSHOST=127.0.0.1
## database super user (for ORACLE this is 'scheme-creator' user)
DBROOTUSER="root"
6.创建kamailio数据库
首先要保证系统已经安装Mysql数据库,通过运行如下命令创建kamailio数据库。
$kamdbctl create
密码设为hello,遇选项按回车设为默认
7.增加用户
$kamctl add 5555 4444
其中5555是用户名,4444是密码
8.启动kamailio
$sudo kamctl start
9.其它命令
$kamctl stop
$kamctl restart
$kamctl ps //查看运行状态
$tail /var/log/syslog //查看运行日志,例如启动失败日志。