搭建ICE(TURN、STUN)服务

此教程操作系统用ubuntu 14.04 64位,最好已经翻墙(Lantern),centos系统请下拉看第二部分

以上命令使用root账号运行,如果非root用户,请自行在命令前加sudo (提示没权限,请输入超级用户密码)

一.Ubuntu 系统

一行一行输入,输入后按回车

1.安装必须的库文件

apt-get update

apt-get install libssl-dev -y

apt-get install libsqlite3 -y

apt-get install libsqlite3-dev -y

apt-get install libpq-dev -y

apt-get install libevent-dev  -y

2.下载&编译

mkdir /usr/local/webrtc/

cd /usr/local/webrtc/

wget http://igustudio.com/coturn.zip

apt-get install unzip

unzip coturn.zip

cd coturn

 ./configure

 make

 make install

安装成功后出现以下信息,则是安装成功:

 

cp ./examples/etc/turn*  ./bin/

cd bin/

mv turnserver.conf turnserver.conf.bak

3.开放端口

在阿里云上添加安全组规则(开放端口,其它云服务器类似):

3478/3478

32355/65535

出方向和入方向配置一样就行

4.启动

nohup /usr/local/webrtc/coturn/bin/turnserver --syslog -a -L 172.18.201.41 -X 134.175.239.29  -E 172.18.201.41 -f --min-port=32355 --max-port=65535 --user=helloworld:helloworld -r helloworld --cert=turn_server_cert.pem --pkey=turn_server_pkey.pm --log-file=stdout -v  > /usr/local/turn.log &

ps

172.18.201.41为内网IP134.175.239.29为外网IP,请自行修改为安装服务器的ip

5.其它

查看日志:tail -f /usr/local/turn.log

查看进程:ps -ef|grep turn

停止:kill -9 xxxx

至此安装完成。

测试方法,请看第三部分。

------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------

二.centos 系统

1.安装centos必须的库文件

yum install -y make gcc cc gcc-c++ wget

yum install -y openssl-devel libevent libevent-devel mysql-devel mysql-server

 

2. 下载并安装 LibEvent modules

wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

(ps:如果文件下载不了,请用以下文件)

libevent-2.0.21-stable.ta

r.gz

830.83KB

tar zxvf libevent-2.0.21-stable.tar.gz

cd libevent-2.0.21-stable && ./configure

sudo make && sudo make install && cd ..

 

3.下载并安装 TURN modules

另外具体版面可以到: http://turnserver.open-sys.org/downloads/ 查看

wget http://turnserver.open-sys.org/downloads/v4.4.5.2/turnserver-4.4.5.2.tar.gz

tar -zxvf turnserver-4.4.5.2.tar.gz

cd turnserver-4.4.5.2 && ./configure

sudo make && sudo make install

 

安装成功后出现以下信息,则是安装成功:

==================================================================

1) If you system supports automatic start-up system daemon services,

the, to enable the turnserver as an automatically started system

service, you have to:

 

        a) Create and edit /etc/turnserver.conf or

        /usr/local/etc/turnserver.conf .

        Use /usr/local/etc/turnserver.conf.default as an example.

 

        b) For user accounts settings: set up SQLite or PostgreSQL or

        MySQL or MongoDB or Redis database for user accounts.

        Use /usr/local/share/turnserver/schema.sql as SQL database schema,

        or use /usr/local/share/turnserver/schema.userdb.redis as Redis

        database schema description and/or

        /usr/local/share/turnserver/schema.stats.redis

        as Redis status & statistics database schema description.

 

        If you are using SQLite, the default database location is in

        /var/db/turndb or in /usr/local/var/db/turndb or in /var/lib/turn/turndb.

 

        c) add whatever is necessary to enable start-up daemon for the

        /usr/local/bin/turnserver.

 

2) If you do not want the turnserver to be a system service,

   then you can start/stop it "manually", using the "turnserver"

   executable with appropriate options (see the documentation).

 

3) To create database schema, use schema in file

/usr/local/share/turnserver/schema.sql.

 

4) For additional information, run:

 

   $ man turnserver

   $ man turnadmin

   $ man turnutils

 

=============================================================

4.开放端口

在阿里云上添加安全组规则(开放端口,其它云服务器类似):

3478/3478

32355/65535

出方向和入方向配置一样就行

5.启动 turn server

nohup turnserver --syslog -a -L 172.18.201.41 -X 134.175.239.29  -E 172.18.201.41 -f --min-port=32355 --max-port=65535 --user=helloworld:helloworld -r helloworld --cert=turn_server_cert.pem --pkey=turn_server_pkey.pm --log-file=stdout -v  > /usr/local/turn.log &

ps172.18.201.41为内网IP134.175.239.29为外网IP,请自行修改为安装服务器的ip。

至此安装完成。

6.其它

查看日志:tail -f /usr/local/turn.log

查看进程:ps -ef|grep turnserver

停止:kill -9 xxxx

测试方法,请看第三部分。

------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------

三.测试方法

测试1在浏览器上输入:http://你的ip或者域名:3478/ ,看到如下信息,则安装成功

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

填写如下:

STUN or TURN URI: turn:134.175.239.29:3478

TURN username:helloworld

TURN username:helloworld

得到结果:

relay地址回来的是你的ip才算穿透成功。

猜你喜欢

转载自blog.csdn.net/qq_41345773/article/details/88965707
今日推荐