openips环境搭建

 

 

 

1 安装环境

 

命令: cat /etc/issue

安装系统: Ubuntu 14.04

软件: openips-2.3

架构: opensips + stun + mediaproxy

 

 

 

2 安装依赖文件

 

sudo apt-get install mysql-server

sudo apt-get install mysql-client

sudo apt-get install libmysqlclient-dev



sudo apt-get install bison gperf libxml2-utils make zip libxml2-dev

 

备注:

如果使用阿里云的服务器,以下安装需要更换一下源。可以直接使用ubuntu 软件源。

apt-get update

apt-get install libncurses5-dev libncursesw5-dev flex

 

 

3 安装opensip

 

(1) 下载安装opensips-2.3

 

安装包地址:

http://opensips.org/Downloads/Downloads

 

 

$ tar -xzvf opensips-2.3tar.gz$ cd opensips-2.3$ sudo make menuconfig

 

在menuconfig中选择—>Configure Compile Options—> Configure Excluded Modules

方向键向下滚动,按空格选中[*] db_mysql

 

按q键返回上一级,选择 —> Save Changes 保存修改。

 

 

按q返回,选择 —> Compile And Install OpenSIPS,回车安装。

安装完成后会将配置文件放在/usr/local/etc/opensips目录下。运行文件在/sbin目录下。

如果出现依赖错误,先通过apt-get安装依赖。

 

 

4 配置opensips依赖

 

(1) 进入/usr/local/etc/opensips目录,运行osipsconfig命令
 

cd /usr/local/etc/opensips

osipsconfig

 

 

(2) 依次选择—> Generate OpenSIPS Script —> Residential Script —> Configure Residential Script

选中如下几项

[*] ENABLE_TCP

[*] USE_ALIASES

[*] USE_AUTH

[*] USE_DBACC

[*] USE_DBUSRLOC

[*] USE_DIALOG

 

(3) 按q返回,选择 —> Generate Residential Script 回车,生成新的配置文件。按q(三次)退出命令。将新生成的opensips_residential_*.cfg文件重命名为opensips.cfg编辑。内容可以直接使用 openips 配置内容。

mv opensips_residential_2014-7-10_16:19:22.cfg opensips.cfg

vi opensips.cfg

 

 

将opensips 配置文件内容复制到该文件

 

 

 

(4) 修改opensipsctlrc文件,去掉相关注释

 

vi opensipsctlrc

 

 

修改为如下内容:

SIP_DOMAIN=xdty.org

DBENGINE=MYSQL

DBHOST=localhost

DBNAME=opensips

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

DBRWUSER=opensips

DBRWPW="opensipsrw"

DBROOTUSER="root"

USERCOL="username"

 

 

(5) 为opensips新建数据库,增加域名及用户

opensipsdbctl create

opensipsctl add 10000 123456

opensipsctl add 10001 123456

 

 

 

5 安装并配置mediaproxy

 

(1) 导入源密钥,增加mediaproxy的源到/etc/apt/sources.list

wget http://download.ag-projects.com/agp-debian-gpg.key 

apt-key add agp-debian-gpg.key

vi /etc/apt/sources.list

t/sources.list

 

最后位置添加

deb    http://ag-projects.com/ubuntu xenial main 

deb-src http://ag-projects.com/ubuntu xenial main

 

 

(2) 安装mediaproxy

apt-get update
apt-get install mediaproxy-dispatcher mediaproxy-relay mediaproxy-web-sessions

 

(3) 进入/etc/mediaproxy/tls目录,拷本密钥文件,修改配置文件

cd /etc/mediaproxy/tls/
cp /usr/share/doc/mediaproxy-common/tls/* .
cd ..
vi config.ini

 

 

修改为类似如下内容

[Relay]

dispatchers = 110.76.220.183

passport = None

relay_ip = 110.76.220.183

port_range = 50000:60000

log_level = DEBUG

stream_timeout = 90

on_hold_timeout = 7200

reconnect_delay = 10

traffic_sampling_period = 15



[Dispatcher]

socket_path = dispatcher.sock

listen = 110.76.220.183

listen_management = 120.76.220.183

management_use_tls = yes

passport = None

management_passport = None

log_level = DEBUG

relay_timeout = 5



[TLS]

certs_path = tls

verify_interval = 300



[Database]

[Radius]



[OpenSIPS]

socket_path = /var/run/opensips/socket

max_connections = 10

 

(4) 启动mediaproxy服务

 

echo 1 > /proc/sys/net/ipv4/ip_forward
media-dispatcher restart
media-relay restart

 

备注:

  如果仅仅是想临时改变某个系统参数的值,可以用两种方法来实现,例如想启用IP路由转发功能:

    (1) echo 1 > /proc/sys/net/ipv4/ip_forward

    (2) sysctl -w net.ipv4.ip_forward=1

    以上两种方法都可能立即开启路由功能,但如果系统重启,或执行了 service network restart

 命令,所设置的值即会丢失,如果想永久保留配置,可以修改/etc/sysctl.conf文件

 将 net.ipv4.ip_forward=0改为net.ipv4.ip_forward=1

 

media-relay 的启动需要依赖ip_forward=1

(3) 如果启动失败需要查看路径是否正确

 

 

 

 

 

 

 

6 opensips配置stun和mediaproxy模块

 

 

(1) stun

#### STUN module

loadmodule "stun.so"

modparam("stun", "primary_ip", "110.76.220.183") #opensips服务器的ip地址

modparam("stun", "primary_port", "5060") #必须与opensips的udp端口相同(一般是5060)

modparam("stun", "alternate_ip", "127.0.0.1") #另一网卡的ip地址

modparam("stun", "alternate_port", "3478") #另一端口号

 

(2) mediaproxy

#### mediaproxy module

loadmodule "mediaproxy.so"

modparam("mediaproxy", "disable", 0)

modparam("mediaproxy", "mediaproxy_socket", "/var/run/mediaproxy/dispatcher.sock")

modparam("mediaproxy", "mediaproxy_timeout", 1000)

modparam("mediaproxy", "signaling_ip_avp", "$avp(nat_ip)")

modparam("mediaproxy", "media_relay_avp", "$avp(media_relay)")

modparam("mediaproxy", "ice_candidate", "low-priority")

 

路由策略需要加上,具体情况查看最后面的整个配置文件

if (is_method("INVITE") && !has_totag()) {

engage_media_proxy();

}

 

 

(3) opensips 配置文件

 

可以直接复制下述内容到 opensips.cfg,然后修改自己的ip

 

 

#
# OpenSIPS residential configuration script
#     by OpenSIPS Solutions <team@opensips-solutions.com>
#
# This script was generated via "make menuconfig", from
#   the "Residential" scenario.
# You can enable / disable more features / functionalities by
#   re-generating the scenario with different options.#
#
# Please refer to the Core CookBook at:
#      http://www.opensips.org/Resources/DocsCookbooks
# for a explanation of possible statements, functions and parameters.
#


####### Global Parameters #########

log_level=3
log_stderror=no
log_facility=LOG_LOCAL0

children=4

/* uncomment the following lines to enable debugging */
#debug_mode=yes

/* uncomment the next line to enable the auto temporary blacklisting of 
   not available destinations (default disabled) */
#disable_dns_blacklist=no

/* uncomment the next line to enable IPv6 lookup after IPv4 dns 
   lookup failures (default disabled) */
#dns_try_ipv6=yes

/* comment the next line to enable the auto discovery of local aliases
   based on revers DNS on IPs */
auto_aliases=no


listen=udp:110.76.220.183:5060   # CUSTOMIZE ME

listen=tcp:110.76.220.183:5060   # CUSTOMIZE ME 


####### Modules Section ########

#set module path
mpath="/usr/local//lib64/opensips/modules/"

#### SIGNALING module
loadmodule "signaling.so"

#### StateLess module
loadmodule "sl.so"

#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 5)
modparam("tm", "fr_inv_timeout", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
modparam("tm", "onreply_avp_mode", 1)

#### Record Route Module
loadmodule "rr.so"
/* do not append from tag to the RR (no need for this script) */
modparam("rr", "append_fromtag", 0)

#### MAX ForWarD module
loadmodule "maxfwd.so"

#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"

#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)


#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)







#### MYSQL module
loadmodule "db_mysql.so"



#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", "NAT")
modparam("usrloc", "db_mode",   2)
modparam("usrloc", "db_url",
	"mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME


#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")

/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)

#### ACCounting module
loadmodule "acc.so"
/* what special events should be accounted ? */
modparam("acc", "early_media", 0)
modparam("acc", "report_cancels", 0)
/* by default we do not adjust the direct of the sequential requests.
   if you enable this parameter, be sure the enable "append_fromtag"
   in "rr" module */
modparam("acc", "detect_direction", 0)
modparam("acc", "db_url",
	"mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME


#### AUTHentication modules
loadmodule "auth.so"
loadmodule "auth_db.so"
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("auth_db|uri", "db_url",
	"mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME
modparam("auth_db", "load_credentials", "")


#### ALIAS module
loadmodule "alias_db.so"
modparam("alias_db", "db_url",
	"mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME


#### STUN module
loadmodule "stun.so"
modparam("stun", "primary_ip", "110.76.220.183")      #opensips服务器的ip地址
modparam("stun", "primary_port", "5060")            #必须与opensips的udp端口相同(一般是5060)
modparam("stun", "alternate_ip", "127.0.0.1")       #另一网卡的ip地址
modparam("stun", "alternate_port", "3478")          #另一端口号



#### DIALOG module
loadmodule "dialog.so"
modparam("dialog", "dlg_match_mode", 1)
modparam("dialog", "default_timeout", 21600)  # 6 hours timeout
modparam("dialog", "db_mode", 2)
modparam("dialog", "db_url",
	"mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME

    #### mediaproxy module
loadmodule "mediaproxy.so"
modparam("mediaproxy", "disable", 0)
modparam("mediaproxy", "mediaproxy_socket", "/var/run/mediaproxy/dispatcher.sock")
modparam("mediaproxy", "mediaproxy_timeout", 1000)
modparam("mediaproxy", "signaling_ip_avp", "$avp(nat_ip)")
modparam("mediaproxy", "media_relay_avp", "$avp(media_relay)")
modparam("mediaproxy", "ice_candidate", "low-priority")







loadmodule "proto_udp.so"

loadmodule "proto_tcp.so" 


####### Routing Logic ########

# main request routing logic

route{
	

	if (!mf_process_maxfwd_header("10")) {
		sl_send_reply("483","Too Many Hops");
		exit;
	}

	if (is_method("INVITE") && !has_totag()) {
		engage_media_proxy();
	}

	if (has_totag()) {
		# sequential request withing a dialog should
		# take the path determined by record-routing
		if (loose_route()) {
			
			# validate the sequential request against dialog
			if ( $DLG_status!=NULL && !validate_dialog() ) {
				xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog\n");
				## exit;
			}
			
			if (is_method("BYE")) {
				# do accounting even if the transaction fails
				do_accounting("db","failed");
				
			} else if (is_method("INVITE")) {
				# even if in most of the cases is useless, do RR for
				# re-INVITEs alos, as some buggy clients do change route set
				# during the dialog.
				record_route();
			}

			

			# route it out to whatever destination was set by loose_route()
			# in $du (destination URI).
			route(relay);
		} else {
			
			if ( is_method("ACK") ) {
				if ( t_check_trans() ) {
					# non loose-route, but stateful ACK; must be an ACK after 
					# a 487 or e.g. 404 from upstream server
					t_relay();
					exit;
				} else {
					# ACK without matching transaction ->
					# ignore and discard
					exit;
				}
			}
			sl_send_reply("404","Not here");
		}
		exit;
	}

	# CANCEL processing
	if (is_method("CANCEL"))
	{
		if (t_check_trans())
			t_relay();
		exit;
	}

	t_check_trans();

	if ( !(is_method("REGISTER")  ) ) {
		
		if (from_uri==myself)
		
		{
			
			# authenticate if from local subscriber
			# authenticate all initial non-REGISTER request that pretend to be
			# generated by local subscriber (domain from FROM URI is local)
			if (!proxy_authorize("", "subscriber")) {
				proxy_challenge("", "0");
				exit;
			}
			if (!db_check_from()) {
				sl_send_reply("403","Forbidden auth ID");
				exit;
			}
		
			consume_credentials();
			# caller authenticated
			
		} else {
			# if caller is not local, then called number must be local
			
			if (!uri==myself) {
				send_reply("403","Rely forbidden");
				exit;
			}
		}

	}

	# preloaded route checking
	if (loose_route()) {
		xlog("L_ERR",
		"Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
		if (!is_method("ACK"))
			sl_send_reply("403","Preload Route denied");
		exit;
	}

	# record routing
	if (!is_method("REGISTER|MESSAGE"))
		record_route();

	# account only INVITEs
	if (is_method("INVITE")) {
		
		# create dialog with timeout
		if ( !create_dialog("B") ) {
			send_reply("500","Internal Server Error");
			exit;
		}
		
		do_accounting("db");
		
	}

	
	if (!uri==myself) {
		append_hf("P-hint: outbound\r\n"); 
		
		route(relay);
	}

	# requests for my domain
	
	if (is_method("PUBLISH|SUBSCRIBE"))
	{
		sl_send_reply("503", "Service Unavailable");
		exit;
	}

	if (is_method("REGISTER"))
	{
		# authenticate the REGISTER requests
		if (!www_authorize("", "subscriber"))
		{
			www_challenge("", "0");
			exit;
		}
		
		if (!db_check_to()) 
		{
			sl_send_reply("403","Forbidden auth ID");
			exit;
		}

		if ( proto==TCP ||  0 ) setflag(TCP_PERSISTENT);

		

		if (!save("location"))
			sl_reply_error();

		exit;
	}

	if ($rU==NULL) {
		# request with no Username in RURI
		sl_send_reply("484","Address Incomplete");
		exit;
	}

	
	# apply DB based aliases
	alias_db_lookup("dbaliases");

	

	 

	# do lookup with method filtering
	if (!lookup("location","m")) {
		if (!db_does_uri_exist()) {
			send_reply("420","Bad Extension");
			exit;
		}
		
		t_newtran();
		t_reply("404", "Not Found");
		exit;
	} 

	

	# when routing via usrloc, log the missed calls also
	do_accounting("db","missed");
	
	route(relay);
}


route[relay] {
	# for INVITEs enable some additional helper routes
	if (is_method("INVITE")) {
		
		

		t_on_branch("per_branch_ops");
		t_on_reply("handle_nat");
		t_on_failure("missed_call");
	}

	

	if (!t_relay()) {
		send_reply("500","Internal Error");
	};
	exit;
}




branch_route[per_branch_ops] {
	xlog("new branch at $ru\n");
}


onreply_route[handle_nat] {
	
	xlog("incoming reply\n");
}


failure_route[missed_call] {
	if (t_was_cancelled()) {
		exit;
	}

	# uncomment the following lines if you want to block client 
	# redirect based on 3xx replies.
	##if (t_check_status("3[0-9][0-9]")) {
	##t_reply("404","Not found");
	##	exit;
	##}

	
}



local_route {
	if (is_method("BYE") && $DLG_dir=="UPSTREAM") {
		
		acc_db_request("200 Dialog Timeout", "acc");
		
	}
}

 


 

 

7 修改日志

 

opensips的日志保存在/var/log/opensips.log,修改日志文件配置。

sudo touch /var/log/opensips.log
sudo chmod 777 /var/log/opensips.log
sudo vi /etc/rsyslog.d/opensips.conf

 

增加如下内容

local0.* /var/log/opensips.log

 

重启syslog服务,启动opensips

sudo service rsyslog restart

sudo /usr/local/sbin/opensipsctl start

 

如果启动失败,查看/var/log/opensips.log文件查找错误。

 

 

 

 

8 测试

 

(1) 查看mediaproxy服务

 

如果没有启动,则需要启动

 

 

(2) 启动opensips

opensipsctl start

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

参考地址:

http://www.docin.com/p-154354628.html

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值