WebRTC network relay Coturn service installation and deployment

overview

In the WebRTC network transmission module, when the NAT cannot be connected, the TURN protocol will be used to realize the communication between the end and the end through the transfer method. Coturn is an open source STUN/TURN server that allows you to easily build a real-time communication system that can run behind NAT firewalls and proxy servers. Coturn supports various protocols and technologies, including STUN (Session Traversal Utilities for NAT), TURN (Traversal Using Relays around NAT) and ICE (Interactive Connectivity Establishment). Coturn can be used to provide a TURN server to WebRTC applications that need to dump traffic in P2P communication. This article mainly introduces the steps to deploy Coturn under Linux and Windows systems.

Deploy under Linux system (take CentOS8.0 as an example)

  • Download libevent2, because Coturn will use libevent2 when compiling.
wget https://github.com/libevent/libevent/releases/download/release-2.1.10-stable/libevent-2.1.10-stable.tar.gz
  • unpack libevent-2.1.10-stable.tar.gz
tar -zxvf libevent-2.1.10-stable.tar.gz
  • Compile and install libevent2
cd libevent-2.1.10-stable
./configure && make && make install
  • Download the Coturn installation package through the wget command (the new version may cause unknown compilation problems, so the old version 4.5.1.1 is downloaded here).
wget https://github.com/coturn/coturn/archive/4.5.1.1.tar.gz
  • Use the tar -zxvf command to decompress 4.5.1.1.tar.gz
tar -zxvf 4.5.1.1.tar.gz
  • Compile and install Coturn
cd coturn-4.5.1.1
./configure --prefix=/usr/local/coturn
make && make install

Configure Coturn

  • Switch to the etc directory of coturn, copy a copy of turnserver.conf.default and modify it.
cd /usr/local/coturn/etc
cp ./turnserver.conf.default ./turnserver.conf
vi ./turnserver.conf
  • Modify the configuration content of the turnserver.conf file. Realm needs to specify an IP or domain name, otherwise it cannot be used in the WebRTC local library. Although trickle-ice can be used to access normally, it cannot be used in the WebRTC local library.
// 指定侦听的端口。
listening-port=3478
// 云主机内网 IP 地址。
listening-ip=xxx.xxx.xxx.xxx
// 云主机的公网 IP 地址。
external-ip=xxx.xxx.xxx.xxx
// 这个很重要,如果没有配置这个就服务使用中转服务。
// 云主机的公网 IP 地址或域名。
realm=xxx.xxx.xxx.xxx
// 访问 STUN/TURN 服务的用户名和密码。
user=admin:123456

Cloud host port configuration

If it is a cloud host of Alibaba Cloud or Tencent Cloud, it is necessary to allow UDP/TCP ports 3478 and 49152-65535 to pass through in the security policy group under control or in the firewall.

Start Coturn

  • Add environment variables
vi ~/.bashrc
export PATH=$PATH:/usr/local/coturn/bin
source ~/.bashrc
  • Start with configuration file
turnserver -c /usr/local/coturn/etc/turnserver.conf

Test the STUN/TURN service, use the Firefox browser (other browsers have problems) to open the following connection  Trickle ICE  shows a relay, indicating that the configuration is successful.

Set up Coturn as a system service

Set Coturn as a system service, so that it can be started automatically after booting, so there is no need to start it manually.

  • Execute the following command:
touch /usr/lib/systemd/system/coturn.service
  • Then edit the coturn.service file
vi coturn.service
  • Set coturn.service file content
[Unit]
Description=Coturn Server
After=network.target
 
[Install]
WantedBy=multi-user.target
 
[Service]
User=root
Group=root
ExecStart=/usr/local/coturn/bin/turnserver -c /usr/local/coturn/etc/turnserver.conf
LimitNOFILE = 5000
  • Set coturn to boot
systemctl enable coturn

Start coturn service

systemctl start coturn

Deploy under Windows system

Originally, Coturn could only run on the Linux system. When we were developing a project, we still had a Linux cloud host and wanted to use the TURN service. At this time, we needed to use the Cygwin tool to install Coturn. Cygwin is a UNIX-like emulation environment running on the Windows platform.

  • Download Cygwin
https://cygwin.com/install.html

  • To install Cygwin, you need to set Devel to install when installing, because the gcc compilation tool is required .

  • Download libevent2 and coturn, and extract them to the bin directory of Cygwin.
https://github.com/libevent/libevent/releases/download/release-2.1.10-stable/libevent-2.1.10-stable.tar.gz
https://github.com/coturn/coturn/archive/4.5.1.1.tar.gz
  • Run the installation command and configure the method referring to the top " deployment under Linux system ".

summary

The above is the installation and deployment of coturn in Linux and Windows systems. If you encounter any problems during installation and deployment, you can private message me through the WeChat public account, and I will answer them one by one.

Original WebRTC Network Relay Coturn Service Installation and Deployment-Knowledge

★The business card at the end of the article can receive audio and video development learning materials for free, including (FFmpeg, webRTC, rtmp, hls, rtsp, ffplay, srs) and audio and video learning roadmaps, etc.

see below!

 

Guess you like

Origin blog.csdn.net/yinshipin007/article/details/132307947