Ubuntu服务器安装WebRTC 网络中继 Coturn 服务,这里使用apt install coturn安装,配置看文章内容

admin 2024-10-02 16:11:54 1434

安装命令

apt install coturn
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libintl-perl libintl-xs-perl libmodule-find-perl libmodule-scandeps-perl libproc-processtable-perl libsort-naturally-perl
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  libhiredis0.14
Suggested packages:
  sip-router xmpp-server
The following NEW packages will be installed:
  coturn libhiredis0.14
0 upgraded, 2 newly installed, 0 to remove and 56 not upgraded.
Need to get 402 kB of archives.
After this operation, 1644 kB of additional disk space will be used.
Do you want to continue?   [Y/n] Y
Get:1 http://ap-east-1.ec2.archive.ubuntu.com/ubuntu jammy/universe amd64 libhiredis0.14 amd64 0.14.1-2   [32.8 kB]
Get:2 http://ap-east-1.ec2.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 coturn amd64 4.5.2-3.1~ubuntu22.04.1   [369 kB]
Fetched 402 kB in 1s (549 kB/s)  
Selecting previously unselected package libhiredis0.14:amd64.
(Reading database ... 84187 files and directories currently installed.)
Preparing to unpack .../libhiredis0.14_0.14.1-2_amd64.deb ...
Unpacking libhiredis0.14:amd64 (0.14.1-2) ...
Selecting previously unselected package coturn.
Preparing to unpack .../coturn_4.5.2-3.1~ubuntu22.04.1_amd64.deb ...
Unpacking coturn (4.5.2-3.1~ubuntu22.04.1) ...
Setting up libhiredis0.14:amd64 (0.14.1-2) ...
Setting up coturn (4.5.2-3.1~ubuntu22.04.1) ...
Adding group `turnserver' (GID 122) ...
Done.
Adding system user `turnserver' (UID 115) ...
Adding new user `turnserver' (UID 115) with group `turnserver' ...
Not creating home directory `/'.
I: Creating /var/lib/turn/turndb from /usr/share/coturn/schema.sql
Created symlink /etc/systemd/system/multi-user.target.wants/coturn.service → /lib/systemd/system/coturn.service.
Processing triggers for ufw (0.36.1-4ubuntu0.1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.8) ...

安装完成后会自动设置为开机启动和系统服务,系统服务命令如下:

systemctl start coturn
systemctl stop coturn
systemctl status coturn
systemctl status coturn
# 这是“systemctl status coturn”输出的状态,我们可以看到已经启动了,用的配置文件是:/etc/turnserver.conf
● coturn.service - coTURN STUN/TURN Server
     Loaded: loaded (/lib/systemd/system/coturn.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2024-10-02 08:03:02 UTC; 4min 7s ago
       Docs: man:coturn(1)
             man:turnadmin(1)
             man:turnserver(1)
   Main PID: 51798 (turnserver)
      Tasks: 7 (limit: 9355)
     Memory: 7.3M
        CPU: 153ms
     CGroup: /system.slice/coturn.service
             └─51798 /usr/bin/turnserver -c /etc/turnserver.conf --pidfile=

Oct 02 08:03:02 ip-172-31-9-121 turnserver  [51798]: 0: : IO method (general relay thread): epoll (with changelist)
Oct 02 08:03:02 ip-172-31-9-121 turnserver  [51798]: 0: : turn server id=0 created
Oct 02 08:03:02 ip-172-31-9-121 turnserver  [51798]: 0: : IO method (general relay thread): epoll (with changelist)
Oct 02 08:03:02 ip-172-31-9-121 turnserver  [51798]: 0: : turn server id=1 created
Oct 02 08:03:02 ip-172-31-9-121 turnserver  [51798]: 0: : Total General servers: 2
Oct 02 08:03:02 ip-172-31-9-121 turnserver  [51798]: 0: : IO method (auth thread): epoll (with changelist)
Oct 02 08:03:02 ip-172-31-9-121 turnserver  [51798]: 0: : IO method (auth thread): epoll (with changelist)
Oct 02 08:03:02 ip-172-31-9-121 turnserver  [51798]: 0: : IO method (admin thread): epoll (with changelist)
Oct 02 08:03:02 ip-172-31-9-121 turnserver  [51798]: 0: : SQLite DB connection success: /var/lib/turn/turndb
Oct 02 08:03:02 ip-172-31-9-121 systemd  [1]: Started coTURN STUN/TURN Server.

对了,创建一下证书文件

openssl req -x509 -newkey rsa:2048 -keyout /etc/turn_server_pkey.pem -out /etc/turn_server_cert.pem -days 99999 -nodes


# key
/etc/turn_server_pkey.pem 
# cert
/etc/turn_server_cert.pem

这时候,我们需要编辑一下配置文件,把下面的信息修改为你的信息,放到文件尾即可。

# 监听器接口设备(可选,仅适用于Linux)。
listening-device=eth0
# 指定侦听的端口。
listening-port=3478
tls-listening-port=5349
# 用于中继接口设备(可选,仅适用于Linux)。
relay-device=eth0

#中继地址(将用于中继的本地IP地址向对等方发送的数据包数量)。
#可以使用多个中继地址。
#相同的IP可用作监听IP和中继IP。
#如果没有指定中继IP,则turnserver将应用默认值
#策略:它将自己决定使用哪些中继地址,并且它将始终使用客户端套接字IP地址作为中继IP地址TURN会话的#如果请求的中继地址族相同作为客户端套接字的系列)。
relay-ip=172.22.112.86

#  云主机内网 IP 地址。
listening-ip=xxx.xxx.xxx.xxx

#  云主机的公网 IP 地址。
external-ip=xxx.xxx.xxx.xxx
# 这个很重要,如果没有配置这个就服务使用中转服务。
# 云主机的公网 IP 地址或域名。
realm=xxx.xxx.xxx.xxx
#realm=stun.ikam.cn
relay-threads=10
min-port=49152
max-port=65535
fingerprint
lt-cred-mech
# 访问 STUN/TURN 服务的用户名和密码。
user=admin:123456
cert=/etc/turn_server_cert.pem
pkey=/etc/turn_server_pkey.pem
syslog
web-admin-ip=0.0.0.0
web-admin-port=3479

云主机端口配置

        如果是阿里云、腾讯云的云主机,需要到控制中的安全策略组或者防火墙中允许 3478、49152-65535 端口 UDP/TCP通行。

  • 测试 STUN/TURN 服务,使用火狐浏览器(其他浏览器有问题)打开以下连接
  • Trickle ICE 出现 relay 说明配置成功。


  • 完成。。。
最后于 1月前 被admin编辑 ,原因:
可爱猫?Telegram电报群 https://t.me/ikeaimao

社区声明 1、本站提供的一切软件、教程和内容信息仅限用于学习和研究目的
2、本站资源为用户分享,如有侵权请邮件与我们联系处理敬请谅解!
3、本站信息来自网络,版权争议与本站无关。您必须在下载后的24小时之内,从您的电脑或手机中彻底删除上述内容
最新回复 (1)
  • 我都用ChatGPT,报个错问一次
    0

您可以在 登录 or 注册 后,对此帖发表评论!

返回