搭建turn服务器

编译环境搭建

Vagrant

Windows用户要想在Windows下编译rfc5766-turn-server的话,需安装虚拟机,我推荐程序员专用的虚拟机——Vagrant,Linux用户请忽略。其配置文件如下:

Vagrantfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# -*- mode: ruby -*-
# vi: set ft=ruby :
  
VAGRANTFILE_API_VERSION = "2"
  
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
   config.vm.box = "hashicorp/precise64"
   config.vm.box_url = "virtualbox.box"
    
   config.vm.provider "virtualbox" do |vb|
     vb.memory = 2048
     vb.cpus = 2
   end
end

使用命令行启动它:

1
2
vagrant up
vagrant  ssh

安装编译工具链

1
sudo  apt-get  install  build-essential

确认安装成功:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
vagrant@precise64:~$ gcc - v
Using built- in  specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER= /usr/lib/gcc/x86_64-linux-gnu/4 .6 /lto-wrapper
Target: x86_64-linux-gnu
Configured with: .. /src/configure  - v  --with-pkgversion='Ubuntu /Linaro  4.6.3-1ubu
ntu5' --with-bugurl= file : ///usr/share/doc/gcc-4 .6 /README .Bugs -- enable -languages
=c,c++,fortran,objc,obj-c++ --prefix= /usr  --program-suffix=-4.6 -- enable -shared
-- enable -linker-build- id  --with-system-zlib --libexecdir= /usr/lib  --without-incl
uded-gettext -- enable -threads=posix --with-gxx-include- dir = /usr/include/c ++ /4 .6
--libdir= /usr/lib  -- enable -nls --with-sysroot=/ -- enable -clocale=gnu -- enable -li
bstdcxx-debug -- enable -libstdcxx- time = yes  -- enable -gnu-unique-object -- enable -pl
ugin -- enable -objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic -
- enable -checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --targ
et=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu /Linaro  4.6.3-1ubuntu5)
vagrant@precise64:~$  make  - v
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is  free  software; see the  source  for  copying conditions.
There is NO warranty; not even  for  MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
  
This program built  for  x86_64-pc-linux-gnu
vagrant@precise64:~$

安装依赖项

1
2
3
4
5
6
sudo  apt-get  install  libssl-dev
sudo  apt-get  install  libevent-dev
sudo  apt-get  install  libpq-dev
sudo  apt-get  install  mysql-client
sudo  apt-get  install  libmysqlclient-dev
sudo  apt-get  install  libhiredis-dev

其中SQL相关的依赖项可能会失败,不过这也没什么大不了的,SQL库是为了支持更多用户而准备的,如果你不是生产环境的话,忽略也行。

检出代码

Vagrantfile的同一目录检出https://code.google.com/p/rfc5766-turn-server/source/checkout 到任意目录,我检出到了stun,下文脚本请注意自行对号入座。

cd进去

1
2
3
4
5
6
7
8
9
10
11
vagrant@precise64:~$  cd  /vagrant
vagrant@precise64: /vagrant ls
down.cmd  stun  up.cmd  Vagrantfile
vagrant@precise64: /vagrant cd  stun
vagrant@precise64: /vagrant/stun ls
AUTHORS    examples  LICENSE.OpenSSL  NOTE               rpm
bin        include   Makefile         postinstall.txt    src
build      INSTALL   Makefile. in       README.turnadmin   STATUS
ChangeLog  lib        make - man .sh      README.turnserver  TODO
configure  LICENSE    man               README.turnutils   turndb
vagrant@precise64: /vagrant/stun $

开始编译

生成makefile文件,编译,安装

1
2
3
. /configure
make
sudo  make  install

测试

试试看是否编译成功,先看看turnserver支持哪些功能

1
turnserver -h > help.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
0: log file opened: /var/tmp/turn_1313_2014-11-04.log
0: 
RFC 3489/5389/5766/5780/6062/6156 STUN/TURN Server
Version Citrix-3.2.4.6 'Marshal West'
0: 
Max number of open files/sockets allowed for this process: 4096
0: 
Due to the open files/sockets limitation,
max supported number of TURN Sessions possible is: 2000 (approximately)
0: 
  
==== Show him the instruments, Practical Frost: ====
  
0: TLS supported
0: DTLS supported
0: Redis supported
0: PostgreSQL is not supported
0: MySQL is not supported
0: OpenSSL compile-time version 0x1000100f: fresh enough
0: Default Net Engine version: 2 (UDP thread per network endpoint)
  
=====================================================
  
  
Usage: turnserver [options]
Options:
  -d, --listening-device   <device-name>     Listener interface device (NOT RECOMMENDED. Optional, Linux only).
  -p, --listening-port     <port>        TURN listener port (Default: 3478).
                         Note: actually, TLS & DTLS sessions can connect to the "plain" TCP & UDP port(s), too,
                         if allowed by configuration.
                         省略……

支持协议

测试各基础协议是否支持

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  cd  examples
  vagrant@precise64: /vagrant/stun/examples $ . /scripts/rfc5769 .sh
RFC 5769 message fingerprint  test (0) result: success
RFC 5769 simple request short-term credentials and integrity  test  result: succes
s
RFC 5769 NEGATIVE fingerprint  test (0) result: success
RFC 5769 message structure, long-term credentials and integrity  test  result: suc
cess
RFC 5769 message encoding  test  result: success
RFC 5769 NEGATIVE long-term credentials  test  result: success
RFC 5769 message fingerprint  test (1) result: success
RFC 5769 IPv4 response short-term credentials and integrity  test  result: success
  
RFC 5769 NEGATIVE fingerprint  test (1) result: success
RFC 5769 IPv4 encoding result: success
RFC 5769 message fingerprint  test (2) result: success
RFC 5769 IPv6 response short-term credentials and integrity  test  result: success
  
RFC 5769 NEGATIVE fingerprint  test (2) result: success
RFC 5769 IPv6 encoding result: success
vagrant@precise64: /vagrant/stun/examples $

TURN测试

先安装screen

1
sudo  apt-get  install  screen

这样我们就能在一个终端里运行多个窗口了,使用快捷键Ctrl+a+c新建一个窗口,通过执行命令

1
. /scripts/basic/relay .sh

把TURN服务器运行起来:

然后执行命令:

1
. /scripts/basic/udp_c2c_client .sh

把客户端跑起来,可以看到它在通过中转服务器自己给自己发数据:

通过Ctrl+a+n来切回服务器的窗口,观察到它的确在收发数据:

至此,说明一切完全正常。

Reference

http://www.cnblogs.com/Haijunzhu/p/3833350.html

http://www.cnblogs.com/mchina/archive/2013/01/30/2880680.html

https://code.google.com/p/rfc5766-turn-server/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值