coturn在centos7安装部署配置测试

mac2024-05-13  32

目录

coturn安装

coturn配置

coturn测试


1.coturn安装

操作环境:centos7

安装openssl和openssl-devel

yum install openssl yum -y install openssl-devel

 

下载并安装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

下载编译按照coturn

git clone https://github.com/coturn/coturn cd coturn ./configure --prefix=/usr/local/coturn make -j 4 make install

 查看是否安装成功

which turnserver

注:如果按照的时候指定自己的安装目录,需要配置环境变量PATH,否则找不到turnserver服务

2.coturn配置

在/usr/local/coturn/etc/目录下有turnserver.conf.default,复制为turnserver.conf

cd /usr/local/coturn/etc/ cp turnserver.conf.default turnserver.conf

查看网卡,记录网卡名称和内网地址

外网地址查看自己的外网IP,我这是阿里云服务器

修改配置信息

vi /usr/local/coturn/etc/turnserver.conf

 listening-ip与relay-ip采用内网ip,external-ip是外网的ip user主要用于turn服务  取消cli-password注释,否则运行服务会报错。

cli-password=qwerty relay-device=eth0 listening-ip=172.17.42.39 listening-port=3478 tls-listening-port=5349 external-ip=39.105.44.xx relay-ip=172.17.42.39 relay-threads=50 lt-cred-mech cert=/usr/local/coturn/etc/turn_server_cert.pem pkey=/usr/local/coturn/etc/turn_server_pkey.pem user=test:123456

cert和pkey配置的自签名证书用openssl命令生成:

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

生成的时候相关信息可以随便写。

开启turnserver,执行命令

turnserver -o -a -f -user=test:123456 -r test

一定要在阿里云后台的安全组规则中添加用到的端口,包括3478端口的tcp/udp,udp一定要配置

看其他人写的文章,在浏览器打开外网ip:3478会显示一个TURN SERVER,我本人没有成功显示网络无连接,可能是少某些配置,如果某位大神知道,请在评论区注上o(∩_∩)o 哈哈

3.ICE测试

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

打开上面的测试地址,分别测试stun和turn服务器,只有relay地址回来的是你的ip才算穿透成功。

添加stun和turn服务器,然后点击 

其中turn需要用户名和密码,如:

测试结果:

注:本人服务器只有一个ip地址,服务在探测nat类型的时候,需要至少有两个ip地址

最新回复(0)