一:下载turnserver服务器
[root@iZ28d8mzdwrZ src]#wget http://ncu.dl.sourceforge.net/project/turnserver/turnserver-0.7.3.tar.bz2
[root@iZ28d8mzdwrZ src]#tar -xvf turnserver-0.7.3.tar.bz2
#下载并安装libconfuse依赖:
[root@iZ28d8mzdwrZ src]#wget
[root@iZ28d8mzdwrZ src]#tar -zxvf confuse-2.7.tar.gz
[root@iZ28d8mzdwrZ src]#cd confuse-2.7
[root@iZ28d8mzdwrZ confuse-2.7]#./configure --prefix=/usr
[root@iZ28d8mzdwrZ confuse-2.7]#maek && make install
[root@iZ28d8mzdwrZ confuse-2.7]#yuminstall flex #安装flex依赖
[root@iZ28d8mzdwrZ confuse-2.7]#cd ../turnserver-0.7.3
[root@iZ28d8mzdwrZ turnserver-0.7.3]#./configure --enable-debug-build
[root@iZ28d8mzdwrZ turnserver-0.7.3]#make && make install
二:配置
[root@iZ28d8mzdwrZ turnserver-0.7.3]# cd extra/
[root@iZ28d8mzdwrZ extra]# ls
Makefile Makefile.in turnserver.conf.template turnserver.fedora.initd turnusers.txt.template
Makefile.am packet-stun2-turn.diff turnserver.debian.initd turnserver.spec
[root@iZ28d8mzdwrZ extra]# cp turnserver.conf.template /usr/local/etc/turnserver.conf
[root@iZ28d8mzdwrZ extra]# cp turnusers.txt.template /usr/local/etc/turnusers.txt
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