webrtc应用turn服务器搭建

系统平台:

推荐使用debian搭建turn服务器,理由是使用coturn有apt的安装源,不需要自行编译下载许多依赖项解决众多的冲突问题。

root安装:

apt-get update
<pre>apt-get install gdebi-core
apt-get install coturn
 安装完成后可以直接使用turnserver启动服务,在/etc目录下有turnserver.conf和turnuserdb.conf两个文件,第一个是turnserver服务器运行配置文件,第二个是turnserver服务的用户数据文件,这个文件只在未使用mysql、postsql、redis、mongodb等一系列数据库时起作用。

配置:

webrtc使用需要有几个特殊配置,

// 当TURN Server用于WebRTC时,必须使用long-term credential mechanism
lt-cred-mech而lt-cred-mech模式如果不使用用户验证的话,服务会报出一个incacessible的警告。所以还要添加一个用户coturn可以配置为stun服务器,但是机器需要两个对外公共ip,所以在阿里云上只能搭建turn服务器。注意,如果是阿里云服务器,答复服务器和监听服务器需要都配置到外网ip上。
// 设定服务的域名范围
realm=xxxx.xx//设定外网ipexternal-ip=xxx.xxx.xxx.xxx

服务启动:

简单启动:turnserver

后台启动:turnserver --daemon

webrtc应用:

webrtc的ice服务器配置需要配置为如下,如果没有sturn服务器,使用turn服务器也可以打通webrtc的p2p通信
"iceServers": [{
    "url": "stun:stun.xxxx.xxx:端口号",
    "username": "配置的用户名",//可选
    "credential": "配置的用户密码或者密匙"//可选
 }, 
{ "url": "turn:turn.xxx.xxx:端口号",
  "username": "配置的用户名",//可选
  "credential": "配置的用户密码或者密匙"//可选
}
]

资源:

turnserver服务器下载地址

http://turnserver.open-sys.org/downloads/

用于支持穿透服务架设

公共传统服务器:

stun.ideasip.com

stun.iptel.org

stun.voxgratia.org

未测试以下

stun.voipstunt.com

stun.voipbuster.com

相关文档:

网络与协议
http://turnserver.open-sys.org/downloads/extradocs/TurnNetworks.pdf
调用接口、类说明
http://turnserver.open-sys.org/downloads/extradocs/turn.extra.docs-2.0.0.1.tar.gz

安装说明,版本号部分根据使用的版本而变化

http://turnserver.open-sys.org/downloads/v4.4.5.4/INSTALL

debian下相关文档

https://sources.debian.net/src/coturn/4.4.5.4-2/

你可能感兴趣的:(webrtc应用turn服务器搭建)