Kamailio是一个开源的SIP服务器,原名OpenSER ,运行在Linux/Unix平台上的C程序。具有较好的性能,灵活性和安全性。
Web links
· Home page with new project name: http://www.kamailio.org
· Home page with old project name: http://www.openser-project.org
· SourceForge.net Project page: http://sourceforge.net/projects/openser/
本文从网站http://www.kamailio.org下载源程序以及二进制安装程序做的安装,其原因在于二进制安装包缺少db_mysql.so库,而使用源程序安装的不清楚如何编译出kamdbctl命令。
一、安装包
下载安装包kamailio-3.2.2_src.tar.gz,并上传到服务器/opt目录下,解压安装包:
#gunzip kamailio-3.2.2_src.tar.gz
#tar -xvf kamailio-3.2.2_src.tar
二、源代码安装
1、在使用源码的方式安装,必须确认系统中编译器gcc和一些依赖包可用,如果不可用,需要先安装gcc编译器。如果gcc可用,直接跳到下一步。这里给出gcc安装过程。
#rpm -ivh cpp-4.1.2-48.el5.i386.rpm
#rpm -ivh kernel-headers-2.6.18-194.el5.i386.rpm
#rpm -ivh glibc-headers-2.5-49.i386.rpm
#rpm -ivh glibc-devel-2.5-49.i386.rpm
#rpm -ivh libgomp-4.4.0-6.el5.i386.rpm
#rpm -ivh gcc-4.1.2-48.el5.i386.rpm
2、Kamailio源代码编译需要bison、flex包,故在编译kamailio之前,www.linuxidc.com需要先安装这些包:
#rpm -ivh /home/Server/bison-2.3-2.1.i386.rpm
#rpm -ivh /home/Server/bison-devel-2.3-2.1.i386.rpm
#rpm -ivh /home/Server/flex-2.5.4a-41.fc6.i386.rpm
3、修改编译配置文件,以使得包含MySQL module
#vi Makefile.vars
添加下述内容:
MODS_MYSQL=on
4、执行kamailio的编译与安装
# ./make_and_install install “standard mysql” ignore /usr/local
关于make_and_install命令的详细用法,使用不带参数的命令即可:
# ./make_and_install
Usage:
./make_and_install [clean|compile|install|nccompile|ncinstall] “standard|standard-dep|mysql|radius|presence|stable|experimental” [ignore|stop] [installpath]
检查编译安装过程是否有误,可用查看make_and_install_output.txt.
三、二进制安装
由于源码安装不清楚使用什么选项可用生成kamdbctl工具,故直接使用二进制安装方式生成该工具。
将kamailio-3.2.2_linux_i386.tar.gz包上传到服务器根目录下,解压安装包:
#gunzip kamailio-3.2.2_linux_i386.tar.gz
#tar -xvf kamailio-3.2.2_linux_i386.tar
四、启动kamailio服务
1、修改/usr/local/etc/kamailio/kamctlrc文件
DBENGINE=MYSQL
SIP_DOMAIN=pryko.com
2、使用kamctl启动服务
# kamctl start
WARNING: database engine not found – tried ‘MYSQL’
INFO: Starting Kamailio :
ERROR: PID file /var/run/kamailio.pid does not exist — Kamailio start failed
[root@eomcr modules]# kamdbctl create
ERROR: could not load the script in /usr/local/lib/kamailio//kamctl/kamdbctl.mysql for database engine MYSQL
ERROR: database engine not loaded – tried ‘MYSQL’
这是由于未修改配置文件kamailio.cfg导致,所以修改/usr/local/etc/kamailio/kamailio.cfg
在文件头部添加:
#!define WITH_MYSQL
3、重新启动:
# kamctl start
若仍然出错,请检查是否db_mysql.so文件在/usr/local/lib/kamailio/modules下。
若存在,仍然出错,可能是mysql安装存在问题,需检查系统是否存在下述mysql安装程序:
#rpm -qa rpm -qa MySQL-shared
MySQL-shared-5.1.61-1.glibc23
# rpm -qa MySQL-devel
MySQL-devel-5.1.61-1.glibc23
并检查/usr/lib下是否有libmysqlclient.so.16库
#ll /usr/lib|grep libmysqlclient
lrwxrwxrwx 1 root root 26 02-08 17:46 libmysqlclient_r.so -> libmysqlclient_r.so.16.0.0
lrwxrwxrwx 1 root root 26 02-08 17:46 libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
-rwxr-xr-x 1 root root 1969708 12-20 04:21 libmysqlclient_r.so.16.0.0
lrwxrwxrwx 1 root root 24 02-08 17:46 libmysqlclient.so -> libmysqlclient.so.16.0.0
lrwxrwxrwx 1 root root 24 02-08 17:46 libmysqlclient.so.16 -> libmysqlclient.so.16.0.0
-rwxr-xr-x 1 root root 1960456 12-20 04:21 libmysqlclient.so.16.0.0
没有的话,就需要安装前面提到的两个库。
若没有问题,则kamailio可以正常启动,输出如下:
# kamctl start
INFO: Starting Kamailio :
INFO: started (pid: 5937)
五、创建数据库1、创建数据库
# kamdbctl create
MySQL password for root:
INFO: test server charset
INFO: creating database openser …
INFO: Core Kamailio tables succesfully created.
Install presence related tables? (y/n): y
INFO: creating presence tables into openser …
ERROR 1071 (42000) at line 16: Specified key was too long; max key length is 1000 bytes
ERROR: Failed to create presence tables!
该问题是由于字符集导致:将默认字符集改为 Latin1,不然后面生成kamailio数据库的时候会出现错误,提示key太长,这个应该是mysql的一个bug,网上说5.2.0以上版本就没有这个问题了,我没有试验,直接将他的默认字符集改为Latin1就没问题了。
2、修改数据库字符集
修改/etc/my.cnf配置文件
default-character-set=Latin1
3、需要以mysql用户关闭并重启mysql,使得字符集修改生效
#mysqladmin -h 127.0.0.1 -u root -p shutdown
#mysqld_safe&
可以登录数据库查看,修改是否正确:
[root@eomcr230-98 kamailio-3.2.2]# mysql -h localhost -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.45-community MySQL Community Server (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> SHOW VARIABLES LIKE ‘character%’;
+————————–+—————————-+
| Variable_name | Value |
+————————–+—————————-+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+————————–+—————————-+
8 rows in set (0.00 sec)
mysql> quit
4、重新创建数据库
[root@eomcr230-98 kamailio-3.2.2]# kamdbctl create
MySQL password for root:
INFO: test server charset
INFO: creating database openser …
INFO: Core Kamailio tables succesfully created.
Install presence related tables? (y/n): y
INFO: creating presence tables into openser …
INFO: Presence tables succesfully created.
Install tables for imc cpl siptrace domainpolicy carrierroute
userblacklist htable purple uac pipelimit? (y/n): y
INFO: creating extra tables into openser …
INFO: Extra tables succesfully created.
安装后,系统默认创建两个具有不同权限的用户、数据库连接:
– r/w user: openser; passwd: openserrw
– r/o user: openserro; passwd: openserro
– DEFAULT_DB_URL=”mysql://opensips:opensipsrw@localhost/opensips”
5、添加SIP客户端用户
kamctl add <name> <password> <email>
# kamctl add tom pass1
MySQL password for user ‘openser@localhost’: [用到上面提到的openser的密码openserrw]
new user ‘tom’ added
# kamctl add john pass2
MySQL password for user ‘openser@localhost’: [用到上面提到的openser的密码openserrw]
new user ‘john’ added
六、验证服务器可用性
为验证服务器可用,可以安装sip客户端Jitsi进行测试。
Download Jitsi for your preferred operating system from:
http://www.jitsi.org/
在本机上安装jitsi-1.0-beta1-latest.nightly-x86.exe.并启动后,添加与上述服务器信息一致的用户:
选择SIP协议,输入ID和密码:
选择高级,并切换到连接:
注意:注册所填IP必须是SIP服务器的IP;
按照上述内容添加好用户。
在另一台机器上同样安装客户端,并添加用户John,两边即可进行语音,视频,即时消息通话。
SIP服务器工作正常。