一:下载编译安装coturn
mkdir wlx
cd wlx
git clone https://github.com/coturn/coturn.git
cd coturn
./configure
make
make install
查看是否安装成功 which turnserver
二:解决报错
2.1 OpenSSL 错误
执行安装 yum -y install openssl-devel
2.2 Libevent2错误
安装 下载 libevent
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable && ./configure
make && make install
三:配置文件
3.1 在/usr/local/etc/目录下有turnserver.conf.default,复制为turnserver.conf
cd /usr/local/etc/
cp turnserver.conf.default turnserver.conf
3.2 cert和pkey配置的自签名证书用Openssl命令生成,生成的两个文件在/etc/目录下
openssl req -x509 -newkey rsa:2048 -keyout /etc/turn_server_pkey.pem -out /etc/turn_server_cert.pem -days 99999 -nodes
3.3 修改配置信息(文件内容太长了,还是下载来下使用 Notepad++ 编辑吧)
vi /usr/local/etc/turnserver.conf
listening-ip与relay-ip采用内网ip,external-ip是外网的ip ,配置如下(相关的IP用户名什么的要替换成自己的)
relay-device=eth0 #与前ifconfig查到的网卡名称一致
listening-ip=172.31.156.145 #内网IP
listening-port=3478
tls-listening-port=5349
relay-ip=172.31.156.145
external-ip=47.105.104.4 #公网IP
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
user=wlx:123456 #用户名密码,创建IceServer时用
cli-password=qwerty #不开启会报CONFIG ERROR: Empty cli-password, and so telnet cli interface is disabled! Please set a non empty cli-password!错误
#创建IceServer
IceServer turnIceServer = new IceServer("turn:47.105.104.4:3478","wlx","123456");
IceServer stunIceServer = new IceServer("stun:47.105.104.4:19302","","");
3.4 启动
turnserver -o -a -f -user=wlx:123456 -r Guangdong
3.5 关闭防火墙
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld
四:测试
测试地址:https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/