搭建turnserver

1.1.1  Turnserver

1.1.1.1 官网:http://turnserver.sourceforge.net/

1.1.1.2 支持协议:

TURN and STUN Request For Comments (respectively RFC 5766 and RFC5389)。RFC6156 namely TURN-IPV6 (relay between IPv4-IPv6, IPv6-IPv4 andIPv6-IPv6 addresses) and RFC6062 namely TURN-TCP (relay data with TCP)。

1.1.1.3 下载源码:

[root@rlnf-76home]# svn co svn://svn.code.sf.net/p/turnserver/code/trunk turnserver

1.1.1.4 安装依赖

1.1.1.4.1 libConfuse

1.       官网: http://www.nongnu.org/confuse/

2.       下载:

[root@rlnf-76 home]# git clone https://github.com/martinh/libconfuse.git

3.       安装依赖:

l  Ubuntu:

sudo apt-get install flex

sudo apt-get install libconfuse-dev

l  CentOS:

yum install flex

4.       编译:

[root@rlnf-76home]# cd turnserver/

[root@rlnf-76libconfuse]# ./autogen.sh

[root@rlnf-76libconfuse]# ./configure --prefix=/usr

[root@rlnf-76libconfuse]# make isntall

 

1.1.1.5 产生配置脚本:

[root@rlnf-76turnserver]# autoreconf --install

1.1.1.6 编译

[root@rlnf-76turnserver]# ./configure --enable-debug-build

--enable-debug-build:允许编译调试信息,用于调试。发行版本不需要这个参数。

[root@rlnf-76turnserver]# make

[root@rlnf-76turnserver]# make install

1.1.1.7  编译时可能会出现的问题

l  在CentOS下可能会出现下面错误:

编译json-c arm版本 可以顺利通过, 但是链接json-c动态库的时候会有提示: undefined reference to rpl_malloc

 

按照网上的搜索结果在configure的时候加上--with-gnu-ld和config.h里加上#undefine rpl_malloc都不能解决问题。

 

后来发现config.h.in里定义了  

#undef malloc

#undef realloc

 

把这两个去掉,编译顺利通过。

 

l  Ubuntu下可能会出现的下面错误:

util_sys.c:259:14: error: ignoring returnvalue of ‘setegid’, declared with attribute warn_unused_result[-Werror=unused-result]

      setegid(gid_real);

              ^

util_sys.c:270:14: error: ignoring returnvalue of ‘setegid’, declared with attribute warn_unused_result[-Werror=unused-result]

      setegid(user.pw_gid);

              ^

util_sys.c: In function‘sys_gain_privileges’:

util_sys.c:291:10: error: ignoring returnvalue of ‘setegid’, declared with attribute warn_unused_result[-Werror=unused-result]

  setegid(gid_eff);

         ^

cc1: all warnings being treated as errors

 

解决方法:

把src/Makefile.am文件中的下面警告标志去掉:

-Wall -Wextra -Werror

 

1.1.1.8   配置

在源码根目录下的extra目录下有配置模板可以参考。

[root@rlnf-76extra]# ls

turnserver.fedora.initd #fedora平台的启动脚本

turnserver.spec         #fedora平台的启动脚本

turnserver.debian.initd #debian平台的启动脚本

turnserver.conf.template#配置文件

turnusers.txt.template  #用户名、密码配置文件

 

1.1.1.9  建立配置文件:

[root@rlnf-76turnserver]# cd extra/

[root@rlnf-76extra]# cp turnserver.conf.template /usr/local/etc/turnserver.conf

[root@rlnf-76extra]# cp turnusers.txt.template /usr/local/etc/turnusers.txt

[root@rlnf-76extra]# cd /usr/local/etc

1.1.1.10      修改配置文件:

[root@rlnf-76etc]# vi turnserver.conf

listen_address = {"183.62.225.76" }           #把对应公网网卡的IP地址写入(如果公网地址是用镜像的,则用镜像的那个IP地址),一般只要改这个配置,其它的用默认值就可以了。

## Account method.

account_method = "file"                        #配置账户数据为文件

 

## Account file (if account_method = file).

account_file ="/usr/local/etc/turnusers.txt" #指定账户文件位置

 

[root@rlnf-76etc]# vi turnusers.txt

foo:bar:domain.org:authorized

用户名:密码:领域:需要验证的

领域的值应与配置文件(turnserver.conf)中的

## Realm value.
realm = "domain.org"

的值相同.这个值用于密码确认的.

1.1.1.11      启动turnserver:

 

[root@rlnf-76etc]# cd ../sbin

[root@rlnf-76sbin]# ./turnserver -c /usr/local/etc/turnserver.conf

1.1.在1.12      启动回显服务:

在服务器上启动回显测试服务端程序:

[root@rlnf-76bin]# ./test_echo_server

UDP Echo server started on port 4588

1.1.1.13      测试服务器是否正常

在其它机器上(客户机器)启动测试程序:

rdc@rdc-Virtual-Machine:/home/turnserver/src$./test_turn_client -t udp -s 183.62.225.76 -p 183.62.225.76 -w 4588 -u foo -g 1234-d domain.org        

Protocol: udp (17) use TLS: 0.

sock: 3 speer: (nil) connected!

Send Allocate request.

Send Allocate request.

Probably wrong credentials or requestedfamily not supported.

这个是说权限错误,一般是用户或密码不对。修改用户和密码,再次运行:

rdc@rdc-Virtual-Machine:/home/turnserver/src$./test_turn_client -t udp -s 183.62.225.76 -p 183.62.225.76 -w 4588 -u foo -gbar -d domain.org

Protocol: udp (17) use TLS: 0.

sock: 3 speer: (nil) connected!

Send Allocate request.

Send Allocate request.

Allocate an address!

Send CreatePermission request.

Permission installed!

Send Send indication.

Receive data: 1024

Send CreatePermission request.

Channel bound to 16393.

Send ChannelData.

Received ChannelData: 1024 bytes

Send Refresh request.

Cleanup and exit.

1.1.1.14      服务端打印的日志:

15:44:26.632297 [turnserver_main:4509]  Received UDP on listening address

15:44:26.632336[turnserver_listen_recv:3273]   Nomessage integrity

15:44:26.636506 [turnserver_main:4509]  Received UDP on listening address

15:44:26.636534[turnserver_listen_recv:3581]   OK basicvalidation are done, process the TURN message

15:44:26.636546 [turnserver_process_turn:2942]  Process a TURN message

15:44:26.636559[turnserver_process_allocate_request:2302]     Allocate request received!

15:44:26.636573[turnserver_process_allocate_request:2536]     lifetime: 165 seconds

15:44:26.636667 [turnserver_process_allocate_request:2767]      Account foo, allocations used: 3

15:44:26.636719[turnserver_process_allocate_request:2903]     Allocation successful, send success allocate response

15:44:26.640733 [turnserver_main:4509]  Received UDP on listening address

15:44:26.640758[turnserver_listen_recv:3581]   OK basicvalidation are done, process the TURN message

15:44:26.640770[turnserver_process_turn:2942]  Process aTURN message

15:44:26.640781[turnserver_process_createpermission_request:1627]      CreatePermission request received

15:44:26.640807[turnserver_process_createpermission_request:1767]      Install permission for 183.62.225.76 4588

15:44:26.640828[turnserver_process_createpermission_request:1806]      CreatePermission successful, send successCreatePermission response

15:44:26.645088 [turnserver_main:4509]  Received UDP on listening address

15:44:26.645110[turnserver_listen_recv:3581]   OK basicvalidation are done, process the TURN message

15:44:26.645121[turnserver_process_turn:2942]  Process aTURN message

15:44:26.645131[turnserver_process_send_indication:1414]      Send indication received!

15:44:26.645143[turnserver_check_bandwidth_limit:503] Tokendown bucket available: 150000, tokens requested: 1024

15:44:26.645154[turnserver_process_send_indication:1536]      Will not set DF flag

15:44:26.645166[turnserver_process_send_indication:1567]      Send data to peer

15:44:26.645224 [turnserver_main:4686]  Received UDP on a relayed address

15:44:26.645241[turnserver_check_bandwidth_limit:477] Tokenup bucket available: 150000, tokens requested: 1024

15:44:26.645314[turnserver_relayed_recv:3722]  Send datato client

15:44:26.649140 [turnserver_main:4509]  Received UDP on listening address

15:44:26.649165[turnserver_listen_recv:3581]   OK basicvalidation are done, process the TURN message

15:44:26.649177[turnserver_process_turn:2942]  Process aTURN message

15:44:26.649187[turnserver_process_channelbind_request:1860]  ChannelBind request received!

15:44:26.649199[turnserver_process_channelbind_request:1936]  Client request a ChannelBinding for 183.62.225.76 4588

15:44:26.649234[turnserver_process_channelbind_request:2055]  ChannelBind successful, send success ChannelBind response

15:44:26.653515 [turnserver_main:4509]  Received UDP on listening address

15:44:26.653532[turnserver_process_channeldata:1239]  ChannelData received!

15:44:26.653544[turnserver_check_bandwidth_limit:503] Tokendown bucket available: 150000, tokens requested: 1024

15:44:26.653557[turnserver_process_channeldata:1366]  Send ChannelData to peer

15:44:26.653596 [turnserver_main:4686]  Received UDP on a relayed address

15:44:26.653611[turnserver_check_bandwidth_limit:477] Tokenup bucket available: 150000, tokens requested: 1024

15:44:26.653623[turnserver_relayed_recv:3722]  Send datato client

15:44:26.657563 [turnserver_main:4509]  Received UDP on listening address

15:44:26.657586[turnserver_listen_recv:3581]   OK basicvalidation are done, process the TURN message

15:44:26.657598[turnserver_process_turn:2942]  Process aTURN message

15:44:26.657608[turnserver_process_refresh_request:2101]      Refresh request received!

15:44:26.657618[turnserver_process_refresh_request:2146]      lifetime: 0 seconds

15:44:26.657664[turnserver_process_refresh_request:2201]      Account foo, allocations used: 2

15:44:26.657677[turnserver_process_refresh_request:2203]      Explicit delete of allocation

15:44:26.657692[turnserver_process_refresh_request:2245]      Refresh successful, send success refresh response

你可能感兴趣的:(IM,Linux编程)