基于coturn的webrtc iceserver搭建

一、coturn简介

1.原文参考地址

webrtc学习: 部署stun和turn服务器——http://blog.csdn.net/gupar/article/details/52782897

Ubuntu 14.04 coturn 安装 与 配置——http://blog.csdn.net/tanyhuan/article/details/77265349

开源地址——https://github.com/coturn/coturn

2.webrtc的P2P穿透

1. 尝试直连

2. 通过stun服务器进行穿透

3. 无法穿透则通过turn服务器中转

3.coturn的功能

coturn 在原来的turnserver上增加了一些高级特性. (这是作者的描述, 两个项目是同一个作者. 作者更推荐使用coturn);

coturn  支持tcp, udp, tls, dtls 连接;

coturn 支持linux bsd solaris mac os。暂不支持windows (未来会支持);

二、coturn安装

在ubuntu 16的软件库已经带有coturn,直接使用命令安装

sudo apt install coturn

1.配置并启动服务

方法一:

参考:http://blog.csdn.net/gupar/article/details/52782897

通过启动的命令行设置参数

turnserver -o -a -f -v --mobility -m 2 --max-bps=100000 --min-port=32355 --max-port=65535 --user=ling:ling1234 -r demo -L公网ip

方法二:

参考:http://blog.csdn.net/tanyhuan/article/details/77265349

http://blog.csdn.net/u012908515/article/details/54863661

1.修改配置文件(/etc/default/coturn)

TURNSERVER_ENABLED=1

2.修改配置文件(/etc/turnserver.conf)后启动

# Coturn TURN SERVER configuration file



# TURN listener port for UDP and TCP (Default: 3478).

# Note: actually, TLS & DTLS sessions can connect to the 

# "plain" TCP & UDP port(s), too - if allowed by configuration.

#

listening-port=3478



# Alternative listening port for TLS and DTLS protocols.

# Default (or zero) value means "TLS listening port plus one".

#

#alt-tls-listening-port=0

# Listener IP address of relay server. Multiple listeners can be specified.

# If no IP(s) specified in the config file or in the command line options, 

# then all IPv4 and IPv6 system IPs will be used for listening.

#

listening-ip=123.57.174.26

#listening-ip=10.207.21.238

#listening-ip=2607:f0d0:1002:51::4



# Relay address (the local IP address that will be used to relay the 

# packets to the peer).

# Multiple relay addresses may be used.

# The same IP(s) can be used as both listening IP(s) and relay IP(s).

#

# If no relay IP(s) specified, then the turnserver will apply the default

# policy: it will decide itself which relay addresses to be used, and it 

# will always be using the client socket IP address as the relay IP address

# of the TURN session (if the requested relay address family is the same

# as the family of the client socket).

#

relay-ip=123.57.174.26

#relay-ip=2607:f0d0:1002:51::5



# Number of the relay threads to handle the established connections

# (in addition to authentication thread and the listener thread).

# If explicitly set to 0 then application runs relay process in a 

# single thread, in the same thread with the listener process 

# (the authentication thread will still be a separate thread).

#

# If this parameter is not set, then the default OS-dependent 

# thread pattern algorithm will be employed. Usually the default

# algorithm is the most optimal, so you have to change this option

# only if you want to make some fine tweaks. 

#

# In the older systems (Linux kernel before 3.9),

# the number of UDP threads is always one thread per network listening

# endpoint - including the auxiliary endpoints - unless 0 (zero) or 

# 1 (one) value is set.

#

relay-threads=2



# Lower and upper bounds of the UDP relay endpoints:

# (default values are 49152 and 65535)

#

min-port=49152

max-port=65535

# Uncomment to run TURN server in 'normal' 'moderate' verbose mode.

# By default the verbose mode is off.

verbose



# Uncomment to use fingerprints in the TURN messages.

# By default the fingerprints are off.

#

fingerprint



# Uncomment to use long-term credential mechanism.

# By default no credentials mechanism is used (any user allowed).

#

lt-cred-mech



# 'Static' user accounts for long term credentials mechanism, only.

# This option cannot be used with TURN REST API.

# 'Static' user accounts are NOT dynamically checked by the turnserver process, 

# so that they can NOT be changed while the turnserver is running.

#

#user=username1:key1

#user=username2:key2

# OR:

#user=username1:password1

#user=username2:password2

user=ito:ito.000000



# The default realm to be used for the users when no explicit 

# origin/realm relationship was found in the database, or if the TURN

# server is not using any database (just the commands-line settings

# and the userdb file). Must be used with long-term credentials 

# mechanism or with TURN REST API.

#

realm=wonderfulhr.cn



# Max bytes-per-second bandwidth a TURN session is allowed to handle

# (input and output network streams are treated separately). Anything above

# that limit will be dropped or temporary suppressed (within

# the available buffer limits).

# This option can also be set through the database, for a particular realm.

#

max-bps=100000



# Option to set the log file name.

# By default, the turnserver tries to open a log file in 

# /var/log, /var/tmp, /tmp and current directories directories

# (which open operation succeeds first that file will be used).

# With this option you can set the definite log file name.

# The special names are "stdout" and "-" - they will force everything 

# to the stdout. Also, the "syslog" name will force everything to

# the system log (syslog). 

# In the runtime, the logfile can be reset with the SIGHUP signal 

# to the turnserver process.

#

log-file=/var/tmp/turn.log



# Mobility with ICE (MICE) specs support.

#

mobility



# Server relay. NON-STANDARD AND DANGEROUS OPTION. 

# Only for those applications when we want to run 

# server applications on the relay endpoints.

# This option eliminates the IP permissions check on 

# the packets incoming to the relay endpoints.

#

server-relay

3.重启coturn

service coturn restart

三、coturn测试

turnutils_uclient -u ling -w ling1234 公网IP
或者通过在线工具测试。网址:https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/

© 2018, 李德涛博客. 版权所有.

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.