本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/47109183 未经博主允许不得转载。
1,关于stun和turn
STUN(Simple Traversal of UDP over NATs,NAT 的UDP简单穿越)是一种网络协议,它允许位于NAT(或多重NAT)后的客户端找出自己的公网地址,查出自己位于哪种类型的NAT之后以及NAT为某一 个本地端口所绑定的Internet端端口。这些信息被用来在两个同时处于NAT 路由器之后的主机之间建立UDP通信。该协议由RFC 3489定义。目前RFC 3489协议已被RFC 5389协议所取代,新的协议中,将STUN定义为一个协助穿越NAT的工具,并不独立提供穿越的解决方案。它还有升级版本RFC 7350,目前正在完善中。
http://baike.baidu.com/view/884586.htm
TURN的全称为Traversal Using Relay NAT,即通过Relay方式穿越NAT,TURN应用模型通过分配TURNServer的地址和端口作为客户端对外的接受地址和端口,即私网用户发出的报文都要经过TURNServer进行Relay转发。
http://baike.baidu.com/subview/351571/10359693.htm
2,安装
参考:
http://www.hankcs.com/program/network/compile-rfc5766-turn-server-to-build-turn-server.html
代码下载:
https://github.com/coturn/rfc5766-turn-server/releases
下载最新的tar.gz包。rfc5766-turn-server-3.2.5.9.tar.gz
安装依赖环境
##ssl 需要yum安装
yum install openssl openssl-libs libevent libevent-devel
如果还是报错,就手动安装libevent。
centos Libevent2 development libraries are not installed properly in required location
下载:http://libevent.org/ 官网,下载
https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz
然后解压缩编译安装即可
编译turn-server
tar -zxvf rfc5766-turn-server-3.2.5.9.tar.gz
cd rfc5766-turn-server-3.2.5.9
./configure
make
make install
configure成功:
more is /usr/bin/more
install is /usr/bin/install
pkill is /usr/bin/pkill
Use TMP dir /var/tmp
Compiler: cc
Do not use -lsocket
Do not use -lwldap32
Do not use -lwldap64
Do not use -lintl
Sockets code is fine: no sin_len field present
Ignore IP_RECVERR
Crypto SSL lib found.
SSL lib found.
Libevent2 development found.
Libevent2 runtime found.
Libevent2 openssl found.
Libevent2 pthreads found.
POSTGRESQL DEVELOPMENT LIBRARY (libpq.a) AND/OR HEADER (libpq-fe.h)
ARE NOT INSTALLED PROPERLY ON THIS SYSTEM.
THAT'S OK BUT THE TURN SERVER IS BUILDING WITHOUT POSTGRESQL DATABASE SUPPORT.
MYSQL DEVELOPMENT LIBRARY (libmysqlclient) AND/OR HEADER (mysql.h)
ARE NOT INSTALLED PROPERLY ON THIS SYSTEM.
THAT'S OK BUT THE TURN SERVER IS BUILDING WITHOUT MYSQL DATABASE SUPPORT.
HIREDIS DEVELOPMENT LIBRARY (libhiredis.*) AND/OR HEADERS (hiredis/*.h)
ARE NOT INSTALLED PROPERLY ON THIS SYSTEM.
THAT'S OK BUT THE TURN SERVER IS BUILDING WITHOUT REDIS SUPPORT.
PREFIX=/usr/local OSLIBS= -L/usr/local/lib/ -L/usr/local/lib/ -L/usr/local/lib64/ -L/usr/local/lib64/ -lrt -pthread -lcrypto -lssl -levent_core -levent_openssl -levent_pthreads -Wl,-rpath,/usr/local/lib/ -Wl,-rpath,/usr/local/lib/ -Wl,-rpath,/usr/local/lib64/ -Wl,-rpath,/usr/local/lib64/ -Wl,-rpath,/usr/lib64/mysql -Wl,-rpath,/usr/local/lib DBLIBS= OSCFLAGS=-g -Wall -Wno-deprecated-declarations -Wextra -Wformat-security -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -I/usr/local/include -I/usr/local/include/ -I/usr/local/include -DTURN_HAS_DAEMON -DINSTALL_PREFIX=/usr/local DBCFLAGS=
只是说没有数据库支持的库,暂时不需要。
安装之后说明:
1) If you system supports automatic start-up system daemon services,
the, to enable the turnserver as an automatically started system
service, you have to:
a) Create and edit /etc/turnserver.conf or
/usr/local/etc/turnserver.conf .
Use /usr/local/etc/turnserver.conf.default as an example.
b) For user accounts settings, if using the turnserver
with authentication: create and edit /etc/turnuserdb.conf
file, or set up PostgreSQL or MySQL or Redis database for user accounts.
Use /usr/local/etc/turnuserdb.conf.default as example for flat file DB,
or use /usr/local/share/turnserver/schema.sql as SQL database schema,
or use /usr/local/share/turnserver/schema.userdb.redis as Redis
database schema description and/or /usr/local/share/turnserver/schema.stats.redis
as Redis status & statistics database schema description.
c) add whatever is necessary to enable start-up daemon for the /usr/local/bin/turnserver.
2) If you do not want the turnserver to be a system service,
then you can start/stop it "manually", using the "turnserver"
executable with appropriate options (see the documentation).
3) To create database schema, use schema in file /usr/local/share/turnserver/schema.sql.
4) For additional information, run:
$ man turnserver
$ man turnadmin
$ man turnutils
在根目录创建一个user.db文件
使用turnserver启动:
turnserver --userdb /root/turnuser.db
里面是webrtc用户名密码:
webrtc:secret
3,页面调用
https://github.com/EricssonResearch/openwebrtc-examples/tree/master/web
安装node参考之前文章:
http://blog.csdn.net/freewebsys/article/details/46649667#t1
修改main.js
// must use 'url' here since Firefox doesn't understand 'urls'
var configuration = {
"iceServers": [
{
"url": "stun:mmt-stun.verkstad.net"
},
{
"url": "turn:mmt-turn.verkstad.net",
"username": "webrtc",
"credential": "secret"
}
]
};
将stun服务器和turn服务器替换。
4,总结
本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/47109183 未经博主允许不得转载。
stun和trun是webrtc打通的关键服务器,但是资源有限没有在公网测试。