opensips的配置

使用 de 环境
VMware 虚拟环境下的 Red hat enterprise linux
( 其他版本也可以,安装时对于新手,建议软件包全部安装,避免后期有好多工具都没有。避免补安装时会出现连锁的问题,这个很麻烦 )
 
版本
Opensips-1.4.3 (官方网站 [url]http://www.opensips.org/[/url]
 
前期准备:
LINUX 基本指令的熟悉
Mysql :我们选用的数据库,使用系统自带的 mysql 就可以,注意安装系统时选上 mysql 安装包。
mysql 一些指令:
show databases
use opensips
show tables
select * from subscribers
drop
create
and so on
Opensips 的安装 :
1、  官方网站 [url]http://www.opensips.org/[/url] 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
3 configure 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-lite eyebeam
5、  检查是否注册成功
opensipsctl ul show
6、  检查是否在线
opensipsctl online
注:两个 sip softphone 注册必须使用数据库中已有的用户名和密码,否则将不能通过认证。
7 make a call from one phone to the other
 

你可能感兴趣的:(职场,休闲,opensips)