Coturn 搭建
Coturn
以下保留Coturn4.5.1.3的历史操作与输出,未在本轮部署。出现的公网地址和凭据仅用于识别旧记录,复制时必须替换;测试段另一个地址不是下方配置启动成功的证据。新环境按官方配置注释核对选项与防火墙。
需要下载文件
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生成证书
openssl req -x509 -newkey rsa:2048 -keyout /etc/turn_server_pkey.pem -out /etc/turn_server_cert.pem -days 365 -nodes这是自签名测试证书;客户端信任链仍需单独处理,不能据此承诺turns:可用。-nodes使用ASCII短横线并生成未加密私钥,文件权限应限制到服务账号。
查看主机
ifconfig
eth0
192.0.2.10
192.0.2.20修改配置文件
以下只保留带注释的一份历史配置;地址、用户及口令必须替换。它与下方启动日志来自不同旧记录,不应拼成同一次成功部署。
注释单独成行:4.5.1.3 的配置读取实现只跳过以 # 开头的注释行,不能把行尾说明附在地址、网卡名或凭据后面。
Empty cli-password ... telnet cli interface is disabled表示管理CLI被禁用,不等于TURN中继必然启动失败;不需要CLI时可明确设置no-cli,不要为消除提示启用弱口令管理入口。
# 与前面 ifconfig 查到的网卡名称一致
relay-device=eth0
# 本机网卡实际拥有的内网 IP
listening-ip=192.0.2.10
listening-port=3478
tls-listening-port=5349
relay-ip=192.0.2.10
# 公网/内网映射
external-ip=192.0.2.20/192.0.2.10
realm=example.invalid
relay-threads=50
lt-cred-mech
cert=/etc/turn_server_cert.pem
pkey=/etc/turn_server_pkey.pem
pidfile=/var/run/turnserver.pid
min-port=49152
max-port=65535
# 用户名和密码,创建 IceServer 时使用
user=example-user:example-user
cli-password=qwerty若公网IP直接配置在网卡上,可绑定该公网地址;若位于NAT后则绑定本机私网地址并声明公网映射,不能绑定网卡并未拥有的公网IP。除3478、5349监听端口外,还要按实际传输配置放通并正确映射49152–65535中继端口;仅开放STUN监听端口不能保证TURN媒体可达。
启动
下面两条命令是历史启动方式,不是必须连续执行的步骤。第二条显式读取 /etc/turnserver.conf;旧日志却读取 /usr/local/etc/turnserver.conf,realm 也分别出现 Guangdong、ylbs 与上文 example.invalid。新环境应选定一份配置与 realm 后再启动,不能把这些旧值当作已核实的一致配置。
- turnserver -o -a -f --user=example-user:example-user -r Guangdong
- turnserver -v -r ylbs -a -o -c /etc/turnserver.conf
查看 Coturn 4.5.1.3 历史启动日志(非本轮验证)
[root@demo-host ~]# turnserver -o -a -f -user=example-user:example-user -r Guangdong
0: log file opened: /var/log/turn_11262_2020-07-08.log
0: Listener address to use: 192.0.2.10
0: Relay address to use: 192.0.2.10
0: Config file found: /usr/local/etc/turnserver.conf
0:
RFC 3489/5389/5766/5780/6062/6156 STUN/TURN Server
Version Coturn-4.5.1.3 'dan Eider'
0:
Max number of open files/sockets allowed for this process: 65535
0:
Due to the open files/sockets limitation,
max supported number of TURN Sessions possible is: 32500 (approximately)
0:
==== Show him the instruments, Practical Frost: ====
0: TLS supported
0: DTLS supported
0: DTLS 1.2 supported
0: TURN/STUN ALPN supported
0: Third-party authorization (oAuth) supported
0: GCM (AEAD) supported
0: OpenSSL compile-time version: OpenSSL 1.0.2k-fips 26 Jan 2017 (0x100020bf)
0:
0: SQLite supported, default database location is /usr/local/var/db/turndb
0: Redis supported
0: PostgreSQL supported
0: MySQL supported
0: MongoDB is not supported
0:
0: Default Net Engine version: 3 (UDP thread per CPU core)
=====================================================
0: Domain name:
0: Default realm: Guangdong
0: SSL23: Certificate file found: /etc/turn_server_cert.pem
0: SSL23: Private key file found: /etc/turn_server_pkey.pem
0: TLS1.0: Certificate file found: /etc/turn_server_cert.pem
0: TLS1.0: Private key file found: /etc/turn_server_pkey.pem
0: TLS1.1: Certificate file found: /etc/turn_server_cert.pem
0: TLS1.1: Private key file found: /etc/turn_server_pkey.pem
0: TLS1.2: Certificate file found: /etc/turn_server_cert.pem
0: TLS1.2: Private key file found: /etc/turn_server_pkey.pem
0: TLS cipher suite: DEFAULT
0: DTLS: Certificate file found: /etc/turn_server_cert.pem
0: DTLS: Private key file found: /etc/turn_server_pkey.pem
0: DTLS1.2: Certificate file found: /etc/turn_server_cert.pem
0: DTLS1.2: Private key file found: /etc/turn_server_pkey.pem
0: DTLS cipher suite: DEFAULT
[root@demo-host ~]#配置文件
/usr/local/etc
测试
下面地址和用户名来自旧环境,本轮未连接,读者需换成自己的服务;Trickle ICE页面出现relay候选只证明候选收集,不单独证明端到端媒体连通。
- https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
- stun:192.0.2.10:3478
- turn:192.0.2.10:3478
- username:example-user
- password:example-user
- 结果
rtp host 内网IP rtp srflx 外网IP地址或者外网网管IP地址 rtp relay 中继IP地址 一般为TURN服务服务器地址
参考地址
- https://www.jianshu.com/p/915eab39476d
- https://www.jianshu.com/p/a6a59fb810cb
- https://blog.csdn.net/qq_32435729/article/details/78729093
- http://192.0.2.10:3478/
监听成功到中继可用还有哪些关卡
Coturn监听3478或5349是连接入口,分配的中继地址和端口才承载对应中继流量。位于NAT后的主机必须公布正确公网映射,并让中继端口范围按实际配置可达;客户端拿到relay候选后,仍需执行候选对检查和实际收发。参见Coturn官方配置注释。
排查按层保留证据:进程监听、认证分配结果、返回的relay地址、候选对选择、双向收发。仅看到启动日志或候选列表不能跳过后面步骤。本文保留历史命令,没有执行部署,旧地址与口令不是本轮可用配置。
查看图表代码
继续阅读
- 信令与传输机制
- 信令与传输机制
- 信令与传输机制