搭建turnserver(轉) 稍加整理

1.1.1  Turnservergit

1.1.1.1 官網:http://turnserver.sourceforge.net/github

(最新地址http://sourceforge.net/projects/turnserver/json

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)。dom

1.1.1.3 下載源碼:svn

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

我是從http://sourceforge.net/projects/turnserver/下載的源代碼上傳服務器flex

而後ui

tar jxvf XX.tar.bz2spa

若是tar不支持j選項,就用下面方式解壓

bzip2 -d  XX.tar.bz2

tar -xvf  XX.tar.bz2


1.1.1.4 安裝依賴

1.1.1.4.1 libConfuse

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

2.       下載並安裝libconfuse依賴:

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

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

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

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

[root@rlnf-76libconfuse]# make install

3.       安裝依賴:

l  Ubuntu:

sudoapt-get install flex

l  CentOS:

yuminstall flex

   

1.1.1.5 產生配置腳本:

[root@rlnf-76turnserver]# cd turnserver

[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地址寫入,通常只要改這個配置,其它的用默認值就能夠了。

## 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

用戶名:密碼:領域:須要驗證的

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

相關文章
相關標籤/搜索