kamailio mysql_Kamailio

本文详细介绍了Kamailio,一个开源SIP服务器的安装、配置过程,特别是与MySQL的集成,用于实现SIP重定向服务器功能。内容包括依赖包安装、源代码编译、MySQL数据库配置、Kamailio核心模块设置以及负载均衡配置。此外,还展示了如何进行号码段重定向网关的配置,以实现智能路由。
摘要由CSDN通过智能技术生成

软件简介

Kamailio是一个开源的SIP服务器,原名OpenSER

Kamailio is an Open Source, GPL2, SIP Server Routing Platform. It is written

in C for Linux/Unix plaforms and focuses on performance, flexibility and

security.

On Nov 04, 2008, Kamailio and SIP Express Router have started the SIP Router

Project.

Kamailio 诞生于 2005 年 7 月,它是从德国 FhG FOKUS 研究所主导的 SIP Express Router(SER)

项目组分裂出来的。新项目建立的目标是创建一个开放的开发环境,以建立一个强大的可扩展的开源 SIP 服务器。Kamailio 是个纯粹的 SIP

服务器,它可以作为 PROXY、注册服务器、重定向服务器,也可作为简单的 PRESENCE 服务器。

Web links

Features

SIP proxy/registrar/redirect server (RFC3261, RFC3263)

UDP/TCP/TLS/SCTP support

Transactional stateful proxy

Modular architecture

Programmable configuration file

ENUM support

Call Processing Language (CPL)

Gateway to sms or xmpp

Authentication, authorization and accounting via Radius or database

NAT traversal system

Least cost routing

Load balancing

Carrier routing

Multiple database backends: MySQL, Postgres, Oracle, BDB or flat files

SIMPLE Presence Server (IETF SIMPLE extensions - rich presence)

Dialog Info Presence - SLA/BLA

XCAP and RLS

Presence User Agent

Dialog Stateful Proxy

Instant Messaging

Offline message storage

Instant messaging conferencing

SNMP support

Perl Programming Interface

Java SIP Servlet Application server

Over 80 modules (extensions)

Documentation

我们使用Kamailio主要用在SIP dispatcher server,即SIP redirect server

安装及配置手册如下

一.安装

1.依赖包:

libmysqlclient & libz (zlib) :mysql DB support (the db_mysql module) Shared

libraries

MySQL-shared-5.1.32-0.glibc23.i386.rpm

MySQL-devel-community-5.1.32-0.rhel5.i386.rpm

libxml2:cpl-c (Call Processing Language) or the presence modules (presence and

pua*)

libperl:perl scripting from you config file (perl module)

2.源代码安装

make,make modules,make install

或者make all,make install

参考:

3.启动:kamctl start

4.重启:kamctl restart

5.监控服务状态:kamctl moni

6.MySQL配置:

1)安装:

edit Makefile.var files to include the MySQL module

vim Makefile.vars

Uncomment the next line in the file:

MODS_MYSQL=on

cp /usr/local/lib/mysql/libmysqlclient.so.16 /usr/lib

Edit now /usr/local/etc/kamailio/kamctlrc and add:

DBENGINE=MYSQL

SIP_DOMAIN=pryko.com

6.1 创建数据库:kamdbctl create

6.2管理员登录:user ‘admin’ with password ‘ openserrw ‘

6.3 添加用户:kamctl add

6.4 默认值:database url, users and passwords

- DEFAULT_DB_URL=”mysql://opensips:opensipsrw@localhost/opensips”

- r/w user: openser; passwd: openserrw

- r/o user: openserro; passwd: openserro

二.配置

1.配置文件 kamailio.cfg

/usr/local/etc/kamailio/kamailio.cfg

2.配置文件 kamctlrc

/usr/local/etc/kamailio/kamctlrc

四.负载均衡Load Balancing

参考:http://www.kamailio.org/dokuwiki/doku.php/asterisk:load-balancing-and-ha

4.1配置文件 kamailio.cfg

loadmodule(“dispatcher.so”)

modparam(“dispatcher”, “list_file”, “/usr/local/etc/kamailio/dispatcher.list”)

modparam(“dispatcher”, “force_dst”, 1)

4.2 —dispatcher.list----文件

group sip addresses of your * units

1 sip:221.5.152.171:5060

1 sip:221.5.152.170:5060

4.3 kamctl命令:kamctl dispatcher show

-- command ‘dispatcher’ - manage dispatcher

Examples: dispatcher addgw 1 sip:1.2.3.1:5050 1 ‘outbound gateway’ dispatcher addgw 2 sip:1.2.3.4:5050 3 ‘’

* dispatcher rmgw 4

dispatcher show ..................... show dispatcher gateways

dispatcher reload ................... reload dispatcher gateways

dispatcher dump ..................... show in memory dispatcher gateways

dispatcher addgw

.......................... add gateway

dispatcher rmgw................ delete gateway

查看载入的配置:kamctl dispatcher dump

修改后重新载入配置:kamctl dispatcher reload

如需使用,需安装MySQL-client-community-5.1.32-0.rhel5.i386.rpm

否则报错:ERROR: This command requires a database engine - none was loaded

五.与Asterisk对接负载均衡

注意事项:sip.conf

注释如下行

;canreinvite=no ; Asterisk by default tries to redirect

Asterisk#1 10.10.10.56

配置sip.conf

[5000]

type=friend

;username=5000

secret=5000_phone2

callerid=5000

qualify=yes ; Qualify peer is no more than 2000 ms away

nat=no ; This phone is natted

host=dynamic ; This device registers with us

;canreinvite=no ; Asterisk by default tries to redirect

配置extension.conf

[default]

exten => 6000,1,Dial(SIP/6000@10.10.10.57,60)

exten => 5000,1,Dial(SIP/5000,60)

Asterisk#2 10.10.10.57

配置sip.conf

[6000]

type=friend

;username=6000

secret=6000_phone2

callerid=6000

qualify=yes ; Qualify peer is no more than 2000 ms away

nat=no ; This phone is natted

host=dynamic ; This device registers with us

;canreinvite=no ; Asterisk by default tries to redirect

配置extension.conf

[default]

exten => 6000,1,Dial(SIP/6000,60)

exten => 5000,1,Dial(SIP/5000@10.10.10.136,60)

Kamailio 10.10.10.136

配置kamailio.cfg

loadmodule “dispatcher.so”

modparam(“dispatcher”, “list_file”, “/usr/local/etc/kamailio/dispatcher.list”)

route{

if ( !mf_process_maxfwd_header(“10”) )

{

sl_send_reply(“483”,”To Many Hops”);

drop();

};

ds_select_dst(“1”, “0”);

forward();

}

配置dispatcher.list

line format

setit(integer) destination(sip uri) flags (integer, optional)

1 sip:10.10.10.56:5060

测试 :

登录10.10.10.57上的6000,登录10.10.10.56上的5000

从6000呼叫5000,会呼叫10.10.10.136上的5000,10.136重定向到10.56

六.按号码段重定向网关

配置kamailio.cfg

使用正则表达式

route{

if (!mf_process_maxfwd_header(“10”)) {

sl_send_reply(“483”,”Too Many Hops”);

exit;

}

if (uri=~”^sip:5[0-9]+@10.10.10.136$”) {

if (is_method(“INVITE”)) {

ds_select_dst(“1”, “0”);

forward();

exit;

}

}

if (uri=~”^sip:8[0-9]+@10.10.10.136$”) {

if (is_method(“INVITE”)) {

ds_select_dst(“2”, “0”);

forward();

exit;

}

}

sl_send_reply(“404”,”Not here”);

exit;

}

配置dispatcher.list

line format

setit(integer) destination(sip uri) flags (integer, optional)

1 sip:10.10.10.56:5060 #1

2 sip:10.10.10.54:5060

测试 :

登录10.10.10.57上的6000,登录10.10.10.56上的5000

从6000呼叫5000,会呼叫10.10.10.136上的5000,10.136重定向到10.56

从6000呼叫8002,会呼叫10.10.10.136上的8002,10.136重定向到10.54

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值