安装COTURN
公共stun服务器
stun:stun1.l.google.com:19302// 273ms
stun:stun2.l.google.com:19302// 280ms
stun:stun3.l.google.com:19302// 262ms
stun:stun4.l.google.com:19302// 268ms
stun:stun.ideasip.com//240ms
stun:stun.schlund.de// 200ms
stun:stunserver.org// 260ms
stun:stun.voiparound.com// 215ms
stun:stun.voipbuster.com // 225ms
响应速度很慢或者ping不通
stun.fwdnet.net
stun:stun.xten.com
stun.voxgratia.org
stun.voipstunt.com
stun.softjoys.com
stun:stun.rixtelecom.se
stun:stun.iptel.org
stun:stun.ekiga.net
stun:stun01.sipphone.com
stun:23.21.150.121 解析失败(unknown host)
stun:stun.fwdnet.net 验证
安装依赖项
sudo apt-get install libssl-dev
sudo apt-get install libevent-dev
sudo apt-get install libpq-dev
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
sudo apt-get install libhiredis-dev 获取源码
sudo apt-get install coturn打开配置
/etc/default/coturn放开:TURNSERVER_ENABLED=1
创建用户
sudo turnadmin -a -u 用户名 -p 密码 -r 可以随便写(一般写stun.xxx.cn)
//示例
sudo turnadmin -a -u testuser -p testpassword -r stun.test.cn生成证书
sudo openssl req -x509 -newkey rsa:2048 -keyout /etc/turn_server_pkey.pem -out /etc/turn_server_cert.pem -days 99999 -nodes 新建配置文件
sudo cp /usr/local/etc/turnserver.conf.default /usr/local/etc/turnserver.conf相关配置
#(必选)监听端口可以不设置会默认的使用3478
listening-port=3478
#(必选)监听的网卡
listening-device=eth0
#(必选)listening-ip,注意必须是你的内网IP地址
listening-ip=172.17.0.12
#(必选)external-ip,注意必须使用你的外网IP地址(云主机的公网IP地址)
external-ip=18.33.65.98
#(必选)设置用户名及密码
user=testuser:testpassword
#(必选)一般和你创建用户名和密码是填写的-r后面的一样
realm=stun.test.cn
把以下的注释取消掉,注意证书的路径根据自己生成的路径填写
cert=/etc/turn_server_cert.pem
pkey=/etc/turn_server_pkey.pemERROR: Empty cli-password, and so telnet cli interface is disabled! Please set a non empty cli-password!错误 需要在vim etc/turnserver.conf.default 添加
cli-password=youpasswd
如果是云主机的话需要打开对应的端口,如阿里云需要在安全组添加规则3478,UDP和TCP,需要同时开启并且如果云服务开启了防火墙需要添加防火墙规则,我这里是Ubuntu,执行以下命令
重启
systemctl restart coturn如果收到这2个,说明成功

遗留
webrtc的stun服务器无法穿透国内三大运营商4G 最近在研究P2P视频通信,由于要集成到APP中,信令服务器与STUN服务器都是部署在公网上(阿里云)。经过测试最终结果如下:
同一个局域网的两台移动设备可以连接进行通信 移动4G与WiFi,移动4G与联通4G,移动4G与电信4G都是可以连通进行通信 联通4G与WiFi,电信4G与WiFi,WiFi与WiFi偶尔可以通信,但是大多数是不可以连通的 以上情况是在STUN穿透服务器下测试的,只要使用TURN服务器进行穿透的话都是可以连通的,但是不太理解STUN服务器为什么不能穿透联通和电信的4G网络。经过后端和前端的debug及查阅相关资料得到如下发现: 运营商的NAT给电信4G或者联通4G分配的内网外网IP映射每次切换数据网络是一直变化的 电信4G与联通4G分配是多IP,而移动的4G分配的公网IP是不变的(在P2P连接使用中),电信、联通4G分配的公网IP一直是变化的且前后端debug到的ip是不同的 当两台移动设备尝试建立连接时,如果通过STUN服务器无法穿透,STUN服务器的日志中显示双方在不断的尝试穿透
Last updated
Was this helpful?