centos安装coturn搭建穿透服务器

Centos 安装coturn

依赖(若已有则无需重复安装,由于自带openssl有兼容问题,所以openssl、libevent2、turnserver均安装在自定义路径,需要添加一些环境变量)

1)安装gcc

yum install gcc

2)安装perl(安装openssl需要)

yum install perl

3)安装openssl

从openssl.org下载,解压

./config —prefix=/opt

make

make install

4)安装libevent2

从libevent.org下载,解压

./configure —prefix=/opt

make

make install

注:若报错则添加环境变量(修改~/.bash_profile,仅当前用户生效)

PATH=$PATH:$HOME/bin:/opt/bin

PKG_CONFIG_PATH=/opt/lib/pkgconfig

LD_LIBRARY_PATH=/opt/lib

export PKG_CONFIG_PATH

export LD_LIBRARY_PATH

export PATH

使修改生效 source ~/.bash_profile

5)安装coturn

下载https://coturn.net/turnserver/v4.5.2/turnserver-4.5.2.tar.gz,解压

./configure —prefix=/opt

make

make install

6)生成证书

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

7)复制turnserver.conf.default 为 turnserver.conf ,修改配置文件

cp /opt/etc/turnserver.conf.default /opt/etc/turnserver.conf

vi /opt/etc/turnserver.conf

listening-ip=172.xx.xx.xx  #内网IP

external-ip=xx.xx.xx.xx  #外网IP

user=username1:password1

cert=/opt/etc/turn_server_cert.pem

pkey=/opt/etc/turn_server_pkey.pem

tls-listening-port=5349

cli-password=password1

8)启动turnserver(端口号若为默认的3478则可不写端口号)

turnserver -v -r 外网IP:端口 -a -o -c /opt/etc/turnserver.conf

注意:云服务器需要在云平台开放相应的端口,TCP和UDP均开放

9)测试

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

填写内容:

STUN or TURN URI:  turn:外网IP:端口

TURN username:  username1

TURN password:  password1

点击“Add Server”

点击”Gather candidates”

10)停止turnserver

ps -ef | grep turnserver

kill -9 PID

你可能感兴趣的:(centos安装coturn搭建穿透服务器)