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/
tar xcf opensips-1.11.2_src.tar.gz
cd opensips-1.11.2-tls/
make menuconfig
在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命令
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编辑
vi opensips.cfg
修改为如下内容
log_stderror=no
log_facility=LOG_LOCAL0
fork=yes
children=4
/* uncomment the following lines to enable debugging */
#debug=6
#fork=no
#log_stderror=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
alias=xdty.org # 增加alias,修改为你的域名
listen=udp:域名对应ip地址:6060 # CUSTOMIZE ME
disable_tcp=no
listen=tcp:域名对应ip地址:6060 # CUSTOMIZE ME
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("tm", "fr_inv_timer", 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)
#增加这一行,不然报错
modparam("uri", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
#### 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")
modparam("registrar", "received_avp", "$avp(received_nh)")
/* 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", "failed_transaction_flag", "ACC_FAILED")
/* account triggers (flags) */
modparam("acc", "db_flag", "ACC_DO")
modparam("acc", "db_missed_flag", "ACC_MISSED")
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", "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
#### 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
#### NAT modules
loadmodule "nathelper.so"
modparam("nathelper", "natping_interval", 10)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "received_avp", "$avp(received_nh)")
loadmodule "rtpproxy.so"
modparam("rtpproxy", "rtpproxy_sock", "udp:localhost:22222") # 修改端口
#增加下边这一段
#### 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")
修改opensipsctlrc文件
去掉所有DB相关的注释。
DBENGINE=MYSQL
DBHOST=localhost
DBNAME=opensips
DB_PATH="/usr/local/etc/opensips/dbtext"
DBRWUSER=opensips
DBRWPW="opensipsrw"
DBROOTUSER="root"
USERCOL="username"
为opensips新建数据库,增加域名及用户
opensipsctl domain add xdty.org
opensipsctl add 10000 123456
opensipsctl add 10001 123456
3.安装rtpproxy并配置
vi /etc/default/rtpproxy
修改为如下内容
# Additional options that are passed to the daemon.
EXTRA_OPTS=""
LISTEN_ADDR=你的域名对应ip地址
EXTRA_OPTS="-l ${LISTEN_ADDR}"
启动rtpproxy
/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
apt-key add agp-debian-gpg.key
vi /etc/apt/sources.list
最后位置添加
deb-src http://ag-projects.com/ubuntu precise main
安装mediaproxy
apt-get install mediaproxy-dispatcher mediaproxy-relay mediaproxy-web-sessions
进入/etc/mediaproxy/tls目录,拷本密钥文件,修改配置文件
cp /usr/share/doc/mediaproxy-common/tls/* .
cd ..
vi config.ini
修改为类似如下内容
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-relay restart
5.启动服务并检验
修改日志文件配置,是opensips的日志保存在/var/log/opensips.log
chmod 777 /var/log/opensips.log
vi /etc/rsyslog.d/opensips.conf
增加如下内容
为opensips.log文件增加vim的颜色自动化
增加如下内容
重启syslog服务,启动opensips
opensipsctl start
如果启动失败,查看/var/log/opensips.log文件查找错误。
服务启动后,防火墙开启tcp及udp的端口
iptables -I INPUT -p udp --dport 6060 -j ACCEPT
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 install log
更改权限
进入config/tools/admin/add_admin/目录,导入数据表
mysql -uroot opensips
INSERT INTO ocp_admin_privileges (username,password,ha1,available_tools,permissions) values ('admin','admin',md5('admin:admin'),'all','all');
进入config/tools/system/cdrviewer/目录
mysql -Dopensips -p<opensips_cdrs.mysql
进入cron_job目录,修改文件配置数据库信息
注意,generate-cdrs_mysql.sh这个文件里的“call opensips_cdrs_1_6()”可能要改为“call opensips_cdrs()”,必须要与opensips_cdrs.mysql里定义的名称一致。
进入config/tools/system/smonitor/目录,导入数据库并添加定时任务。
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.html
http://www.docin.com/p-163183480.html
http://www.linuxidc.com/Linux/2014-01/95847.htm
Tags: mediaproxy opensips opensips web opensips-cp rtpproxy voip
评论:21