由于FreePBX和Nextcloud均需使用到stun和turn服务,实现WebRTC视频通话功能,于是在Debian10上部署一套自用。

  1. 系统升级

    apt update apt upgrade
  2. 设置主机名

    hostnamectl set-hostname stun.xinlon.cc
  3. 设置时区

    timedatectl set-timezone Asia/Shanghai
  4. 配置ntp

    apt-get install ntpdate
ntpq -p
  1. 安装coturn apt install coturn
  2. 配置coturn,有现成配置文件直接上传

    nano /etc/turnserver.conf

生成随机秘钥命令

openssl rand -hex 32

cddd664ea8aa0c2e6c1d02a14b31ac3ea769f2ebf325508a54341b0bbdd61cdb

  1. 配置内容

listening-port=<yourChosenPortNumber>

fingerprint lt-cred-mech # Only on coTURN below v4.5.0.8! 版本超过,无需配置

use-auth-secret static-auth-secret=<yourChosen/GeneratedSecret>

realm=your.domain.org

total-quota=0

bps-capacity=0

stale-nonce no-loopback-peers # Only on coTURN below v4.5.1.0! 版本超过 无需配置

no-multicast-peers

7.启动coturn服务,查看服务状态

systemctl start coturn
systemctl status coturn

正常回显

root@stun:~# systemctl status coturn

● coturn.service - coTURN STUN/TURN Server

Loaded: loaded (/lib/systemd/system/coturn.service; enabled; vendor preset: enabled)

Active: active (running) since Sun 2022-03-06 13:28:56 CST; 14min ago

 Docs: man:coturn(1)

       man:turnadmin(1)

       man:turnserver(1)

Process: 464 ExecStart=/usr/bin/turnserver --daemon -c /etc/turnserver.conf --pidfile /run/turnserver/turnserver.pid (

Process: 486 ExecStartPost=/bin/sleep 2 (code=exited, status=0/SUCCESS)

Main PID: 485 (turnserver)

Tasks: 7 (limit: 1167)

Memory: 15.5M

CGroup: /system.slice/coturn.service

       └─485 /usr/bin/turnserver --daemon -c /etc/turnserver.conf --pidfile /run/turnserver/turnserver.pid

Mar 06 13:28:54 stun.xinlon.cc turnserver[485]: 0: IO method (general relay thread): epoll (with changelist)

Mar 06 13:28:54 stun.xinlon.cc turnserver[485]: 0: turn server id=1 created

Mar 06 13:28:54 stun.xinlon.cc turnserver[485]: 0: IO method (general relay thread): epoll (with changelist)

Mar 06 13:28:54 stun.xinlon.cc turnserver[485]: 0: turn server id=0 created

Mar 06 13:28:54 stun.xinlon.cc turnserver[485]: 0: Total General servers: 2

Mar 06 13:28:54 stun.xinlon.cc turnserver[485]: 0: IO method (auth thread): epoll (with changelist)

Mar 06 13:28:54 stun.xinlon.cc turnserver[485]: 0: IO method (admin thread): epoll (with changelist)

Mar 06 13:28:54 stun.xinlon.cc turnserver[485]: 0: IO method (auth thread): epoll (with changelist)

Mar 06 13:28:54 stun.xinlon.cc turnserver[485]: 0: SQLite DB connection success: /var/lib/turn/turndb

Mar 06 13:28:56 stun.xinlon.cc systemd[1]: Started coTURN STUN/TURN Server.

8.配置开机启动

sed -i '/TURNSERVER_ENABLED/c\TURNSERVER_ENABLED=1' /etc/default/coturn

9.网页端测试

https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/

10.重启服务器,确认开机启动,完成。

Last modification:March 6th, 2022 at 02:16 pm