ubuntu12.04安装配置opensips,搭建voip服务器

前端之家收集整理的这篇文章主要介绍了ubuntu12.04安装配置opensips,搭建voip服务器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

通过部署opensips,opensips-cp,rtpproxy,mediaproxy实现voip通话。测试可以通过安卓原生客户端验证,CSipSimple客户端通话(拨打/接收)

1.安装opensips
opensips需要编译源码安装
官网:http://opensips.org
文件目录:http://opensips.org/pub/opensips/1.11.2/src/

wgethttp: //opensips.org /pub /opensips /1.11.2 /src /opensips-1.11.2_src.tar.gz
tarxcf opensips-1.11.2_src.tar.gz
cdopensips-1.11.2-tls /
makemenuconfig

在menuconfig中选择—>Configure Compile Options—> Configure Excluded Modules
方向键向下滚动,按空格选中[*] db_MysqL

按q键返回上一级,选择—> Configure Install Prefix,输入/回车表示安装在/目录下的配置目录而不是/usr/local目录下。

选择 —> Save Changes 保存修改

按q返回,选择 —> Compile And Install OpenSIPS,回车安装。
安装完成后会将配置文件放在/etc/opensips目录下。运行文件在/sbin目录下。
如果出现依赖错误,先通过apt-get安装依赖。

2.配置opensips
进入/etc/opensips目录,运行osipsconfig命令

cd /etc /opensips
osipsconfig

依次选择—> Generate OpenSIPS Script —> Residential Script —> Configure Residential Script
选中如下几项
[*] ENABLE_TCP
[*] USE_ALIASES
[*] USE_AUTH
[*] USE_DBACC
[*] USE_DBUSRLOC
[*] USE_DIALOG
[*] USE_NAT
按q返回,选择 —> Generate Residential Script 回车,生成新的配置文件。按q(三次)退出命令
将新生成的opensips_residential_*.cfg文件重命名为opensips.cfg编辑

mvopensips_residential_2014- 7- 10_16: 19: 22.cfg opensips.cfg
viopensips.cfg

修改为如下内容

debug= 3
log_stderror=no
log_facility=LOG_LOCAL0

fork= yes
children= 4

/*uncomment the following lines to enabledebugging */
#debug=6
#fork=no
#log_stderror=yes

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

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

/*comment the next line to enablethe auto discovery of localaliases
based on revers DNS on IPs */
auto_aliases=no

alias=xdty.org # 增加alias,修改为你的域名

listen=udp:域名对应 ip地址: 6060 # CUSTOMIZE ME

disable_tcp=no
listen=tcp:域名对应 disable_tls= yes


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

#set module path
mpath= "/lib64/opensips/modules/" # 增加一个斜杠

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

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

#### Transaction Module
loadmodule "tm.so"
modparam ( "tm","fr_timer",5 )
modparam ( "fr_inv_timer",60);">30 )
modparam ( "restart_fr_on_each_reply",60);">0 )
modparam ( "onreply_avp_mode",60);">1 )

#### Record Route Module
loadmodule "rr.so"
/* donot append from tag to the RR (no need forthis script ) */
modparam ( "rr",60);">"append_fromtag",60);">0 )

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

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

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


#### URI module
loadmodule "uri.so"
modparam ( "uri",60);">"use_uri_table",60);">0 )
#增加这一行,不然报错
modparam ( "db_url",60);">"MysqL://opensips:opensipsrw@localhost/opensips" )

#### MysqL module
loadmodule "db_MysqL.so"

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

#### REGISTRAR module
loadmodule "registrar.so"
modparam ( "registrar",60);">"tcp_persistent_flag"
,60);">"TCP_PERSISTENT" )
modparam ( "received_avp",60);">"$avp(received_nh)" )
/*uncomment the next line not to allow morethan 10contacts per AOR */
#modparam("registrar","max_contacts",10)

#### ACCounting module
loadmodule "acc.so"
/*what special events should be accounted ? */
modparam ( "acc",60);">"early_media",60);">"report_cancels",60);">0 )
/*by default we donot adjust the direct of the sequential requests.
ifyou enablethis parameter,be sure the enable "append_fromtag"
in "rr"module */
modparam ( "detect_direction",60);">"Failed_transaction_flag",60);">"ACC_Failed" )
/*account triggers (flags ) */
modparam ( "db_flag",60);">"ACC_DO" )
modparam ( "db_missed_flag",60);">"ACC_MISSED" )
modparam ( #### AUTHentication modules
loadmodule "auth.so"
loadmodule "auth_db.so"
modparam ( "auth_db",60);">"calculate_ha1",yes )
modparam ( "password_column",60);">"password" )
modparam ( # CUSTOMIZE ME
modparam ( "load_credentials",60);">"" )

#### ALIAS module
loadmodule "alias_db.so"
modparam ( "alias_db",174);"># CUSTOMIZE ME

#### DIALOG module
loadmodule "dialog.so"
modparam ( "dialog",60);">"dlg_match_mode",60);">1 )
modparam ( "default_timeout",60);">21600 ) # 6 hours timeout
modparam ( # CUSTOMIZE ME


#### NAT modules
loadmodule "nathelper.so"
modparam ( "nathelper",60);">"natping_interval",60);">10 )
modparam ( "ping_nated_only",60);">"$avp(received_nh)" )

loadmodule "rtpproxy.so"
modparam ( "rtpproxy",60);">"rtpproxy_sock",60);">"udp:localhost:22222" ) # 修改端口

#增加下边这一段
#### MediaProxy module
loadmodule "mediaproxy.so"
modparam ( "mediaproxy",60);">"disable",60);">"mediaproxy_socket",60);">"/var/run/mediaproxy/dispatcher.sock" )
modparam ( "mediaproxy_timeout",60);">1000 )
modparam ( "signaling_ip_avp",60);">"$avp(nat_ip)" )
modparam ( "media_relay_avp",60);">"$avp(media_relay)" )
modparam ( "ice_candidate",60);">"low-priority" )

修改opensipsctlrc文件

viopensipsctlrc

去掉所有DB相关的注释。

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"

为opensips新建数据库增加域名及用户

opensipsdbctl create
opensipsctl domain add xdty.org
opensipsctl add 10000 123456
opensipsctl add 10001 123456

3.安装rtpproxy并配置

apt-get installrtpproxy
vi /etc /default /rtpproxy

CONTROL_SOCK=udp:127.0.0.1: 22222

# Additional options that are passed to the daemon.
EXTRA_OPTS= ""
LISTEN_ADDR=你的域名对应 ip地址
"-l${LISTEN_ADDR}"

启动rtpproxy

killallrtpproxy
/etc /init.d /rtpproxy start

如果rtpproxy启动失败,请检查/etc/init.d/rtpproxy脚本DAEMON路径是否正确,默认为DAEMON=/usr/sbin/$NAME,可能要改为DAEMON=/usr/bin/$NAME

4.安装并配置mediaproxy
导入源密钥,增加mediaproxy的源到/etc/apt/sources.list

wgethttp: //download.ag-projects.com /agp-debian-gpg.key
apt-key addagp-debian-gpg.key
vi /etc /apt /sources.list

最后位置添加

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

安装mediaproxy

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

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

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

修改为类似如下内容

[Relay ]
dispatchers = 106.186.23.149
passport = None
relay_ip = 106.186.23.149
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 = 106.186.23.149
listen_management = 106.186.23.149
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

启动mediaproxy服务

media-dispatcher restart
media-relay restart

5.启动服务并检验
修改日志文件配置,是opensips的日志保存在/var/log/opensips.log

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

增加如下内容

local0. * /var /log /opensips.log

为opensips.log文件增加vim的颜色自动

vi~ /.vim /filetype.vim

au BufNewfile,BufRead /var /log /* set filetype=messages

重启syslog服务,启动opensips

service rsyslog restart
opensipsctl start

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

服务启动后,防火墙开启tcp及udp的端口

iptables -IINPUT -ptcp --dport 6060 -jACCEPT
iptables -IINPUT -pudp --dport 6060 -jACCEPT
iptables-save

然后在http://www.yougetsignal.com/tools/open-ports/查看端口是否打开

手机测试端安装CSipSimple或其他sip客户端测试。注意CSipSimple服务器输入为类似xdty.org:6060 域名:端口的形式,拨打对方电话时直接输入帐号名10001而不需要输入域名。如果可以通话就表示配置成功了。

或者使用原生的系统拨号盘,在设置->通话设置->互联网电话设置|账户->接听来电(勾选)|添加账户->保存。当显示为”主账户。接听电话”时即配置成功。拨打电话时需要加入类似邮箱地址的后缀即10001@xdty.org,如果不能输入非数字字符可以粘贴或者添加一个新的联系人,在“增加其他字段”中添加“互联网电话”,输入10001@xdty.org,之后点击此联系人拨打互联网电话即可。

下文增加网页管理功能

6.安装配置opensips-cp
下载最新版本的opensips-cp,位置在http://sourceforge.net/projects/opensips-cp/
可以根据INSTALL文件安装,主要配置一些数据库的操作。
文件解压,复制到/var/www/目录下重命名为opensips
安装一些依赖关系

pear installMDB2 #MysqL
pear installlog

更改权限

chownwww-data:www-data web -R

进入config/tools/admin/add_admin/目录,导入数据表

MysqL -Dopensips-p <ocp_admin_privileges.MysqL
MysqL -urootopensips
INSERT INTO ocp_admin_privileges (username,password,ha1,available_tools,permissions )values ( 'admin',( 'admin:admin' ),60);">'all',60);">'all' );

进入config/tools/system/cdrviewer/目录

MysqL -Dopensips -p <cdrs.MysqL
MysqL -Dopensips-p <opensips_cdrs.MysqL

进入cron_job目录,修改文件配置数据库信息

vigenerate-cdrs_MysqL.sh

注意,generate-cdrs_MysqL.sh这个文件里的“call opensips_cdrs_1_6()”可能要改为“call opensips_cdrs()”,必须要与opensips_cdrs.MysqL里定义的名称一致。
进入config/tools/system/smonitor/目录,导入数据库添加定时任务。

MysqL -Dopensips -p <tables.MysqL
vi /etc /crontab
*/ 3 * * * *root /var /www /opensips /cron_job /generate-cdrs_MysqL.sh
* * * * *root PHP /var /www /opensips-cp /cron_job /get_opensips_stats.PHP > /dev /null

打开浏览器访问http://网址/opensips,使用admin/admin登录登录后可以修改用户名和密码。

参考资料:http://www.cnblogs.com/bjzhanghao/archive/2013/02/13/2910903.htmlhttp://www.docin.com/p-163183480.htmlhttp://www.linuxidc.com/Linux/2014-01/95847.htm

猜你在找的Ubuntu相关文章