linux opensips配置

来源:互联网 发布:c语言中default 编辑:程序博客网 时间:2024/06/03 06:35

使用de环境

VMware虚拟环境下的Red hat enterprise linux

(其他版本也可以,安装时对于新手,建议软件包全部安装,避免后期有好多工具都没有。避免补安装时会出现连锁的问题,这个很麻烦)

 

版本

Opensips-1.4.3(官方网站 http://www.opensips.org/

 

前期准备:

LINUX基本指令的熟悉

Mysql:我们选用的数据库,使用系统自带的mysql就可以,注意安装系统时选上mysql安装包。

mysql一些指令:

show databases

use opensips

show tables

select * from subscribers

drop

create

and so on

Opensips的安装:

1、  官方网站http://www.opensips.org/download中下载opensips软件包

2、  编译:

tar zxvf opensips-1.4.3-tls_src.tar.gz

cd opensips-1.4.3-tls

 

3、安装之前更改makefile

删除Makefile中的exclude_modules db-mysql ,为了使opensips支持mysql

 

4、  安装

make all

make install

默认安装路径/usr/local

5、  创建opensips的数据库

 

vi /usr/local/opensips/etc/opensips/opensipsctlrc mysql的相关的注释去掉

## database type: MYSQL, PGSQL, ORACLE, DB_BERKELEY, or DBTEXT, by default none is loaded

# If you want to setup a database with opensipsdbctl, you must at least specify

# this parameter.

 DBENGINE=MYSQL

## database host

 DBHOST=localhost

## database name (for ORACLE this is TNS name)

 DBNAME=opensips

# database path used by dbtext or db_berkeley

 DB_PATH="/usr/local/etc/opensips/dbtext"

## database read/write user

 DBRWUSER=opensips

## password for database read/write user

 DBRWPW="opensipsrw"

## database read only user

 DBROUSER=opensipsro

## password for database read only user

 DBROPW=opensipsro

## database super user (for ORACLE this is 'scheme-creator' user)

 DBROOTUSER="root"

# user name column

 USERCOL="username"


  
执行opensips/sbin/下的opensipsdbctl

   ./opensipsdbctl create (生成opensips数据库)

 

5.opensips的运行

  opensips/sbin/下的opensipsctl start来启动opensips

  ps -efw  opensips 检查应该已经运行了。

opensips/sbin/下的opensipsctl stop来停止opensips

到此完成了opensips的安装。

 

Opensips.cfg文档的配置

 

1、  实现注册,认证功能

debug=4

fork=yes

log_stderror=yes # (cmd line: -E)

port=5060

children=4

dns=no

rev_dns=no

# ------------------ module loading ----------------------------------

#set module path

mpath="/usr/local/lib/opensips/modules/"

loadmodule "db_mysql.so"

loadmodule "sl.so"

loadmodule "tm.so"

loadmodule "rr.so"

loadmodule "maxfwd.so"

loadmodule "usrloc.so"

loadmodule "registrar.so"

loadmodule "textops.so"

loadmodule "mi_fifo.so"

loadmodule "uri_db.so"

loadmodule "auth.so"

loadmodule "auth_db.so"

# ----------------- setting module-specific parameters ---------------

# -- mi_fifo params --

modparam("mi_fifo","fifo_name","/tmp/opensips_fifo")

# -- usrloc params --

# modparam("usrloc", "db_mode", 0)

# Uncomment this if you want to use SQL database

# for persistent storage and comment the previous line

modparam("usrloc", "db_mode", 2)

modparam("auth_db", "calculate_ha1", yes)

modparam("auth_db", "password_column", "password")

modparam("rr", "enable_full_lr", 1)

# ------------------------- request routing logic -------------------

# main routing logic

route{

# initial sanity checks -- messages with

# max_forwards==0, or excessively long requests

if (!mf_process_maxfwd_header("10"))

{

sl_send_reply("483","Too Many Hops");

exit;

};

if (msg:len > max_len )

{

sl_send_reply("513", "Message too big");

exit;

};

if (method!="REGISTER")

{

record_route();

}

if (loose_route())

{

append_hf("P-hint: rr-enforced/r/n");

route(1);

exit;

};

if (uri!=myself)

{

# mark routing logic in request

append_hf("P-hint: outbound/r/n");

# if you have some interdomain connections via TLS

# if(uri=~"@tls_domain1.net") {

# t_relay("tls:domain1.net");

# exit;

#} else if(uri=~"@tls_domain2.net") {

# t_relay("tls:domain2.net");

# exit;

#}

route(1);

exit;

};

# if the request is for other domain use UsrLoc

# (in case, it does not work, use the following command

# with proper names and addresses in it)

if (uri==myself)

{    

if (method=="REGISTER")

{

# Uncomment this if you want to use digest authentication

# if (!www_authorize("","subscriber")) {

# www_challenge("", "0");

# exit;

#};

save("location");

#route(2);

exit;

};

#---------added from book

if (!proxy_authorize("","subscriber"))

{

proxy_challenge("","0");

exit;

};

consume_credentials();

#---------add end

lookup("aliases");

if (uri!=myself)

{

append_hf("P-hint: outbound alias/r/n");

route(1);

exit;

};

# native SIP destinations are handled using our USRLOC DB

if (!lookup("location"))

{

sl_send_reply("404", "User Not Found");

exit;

};

append_hf("P-hint: usrloc applied/r/n");

};

route(1);

}

route[1] {

# send it out now; use stateful forwarding as it works

# reliably even for UDP2TCP

if (!t_relay()) {

sl_reply_error();

};

#exit;

}

#route[2] {

# ------------------------------------------------------------------------

# REGISTER Message Handler

# ------------------------------------------------------------------------

#if (!save("location")) {

#sl_reply_error();

#};

#}

为实现注册和认证功能,除了配置好opensips.cfg,还需改动opensipsctl中的一些地方,记录如下:

默认文档中为:

## path to FIFO file

OSIPS_FIFO="FIFO" (路径不对)

改为:

OSIPS_FIFO="/tmp/opensips_fifo"

 

运行:

1、运行mysql

Service mysqld start

2、开启opensips

opensipsctl restart

3configure two users accounts.(格式:opensipsctl add user password)

opensipsctl add 1001 1001

opensipsctl add 1002 1002

注:opensipsctl rm -------remove users

    opensipsctl passwd-----change a password

4、  用已有用户和密码注册两个sip softphone(我用的X-liteeyebeam

5、  检查是否注册成功

opensipsctl ul show

6、  检查是否在线

opensipsctl online

注:两个sip softphone注册必须使用数据库中已有的用户名和密码,否则将不能通过认证。

7make a call from one phone to the other

原创粉丝点击