參考文件:git
http://blog.csdn.net/kl222/article/details/20145423shell
爲何要搭建TURN服務器?windows
由於咱們編寫的sip客戶端再和南瑞的sip服務器進行通訊的時候,中間通過一個安全平臺,這個安全平臺具備NAT和防火牆功能。RTP和RTCP包傳遞不了。因此要增長一個TURN服務器。同時在sip客戶端側要實現TURN客戶端功能。安全
搭建TURN服務器的步驟:服務器
要安裝兩個軟件 libConfuse和TURN serverdom
1,下載ide
別人說經過svn和git方式下載,可是這個地址都下載不下來,提示地址錯誤。我是在windows下訪問下面的兩個網站,直接下載的文件。svn
官網:http://turnserver.sourceforge.net/測試
官網: http://www.nongnu.org/confuse/網站
下載的兩個文件以下:
confuse-2.7.tar.gz
turnserver-0.7.3.tar.bz2
2,傳輸
我在windows下面使用的是xshell, 配置xshell下面的ZMODEM的上傳和下載目錄,就可使用rz命令向CentOS主機傳輸文件了。
我是在根目錄下建立了一個turnserver目錄。
mkdir turnserver
3,解壓
tar -xzvf confuse-2.7.tar.gz
tar -jxvf turnserver-0.7.3.tar.bz2
解壓後的目錄以下:
4,編譯安裝confuse-2.7
cd confuse-2.7 ./configure //這裏不要指定目錄,使用默認目錄進行安裝。默認是安裝在/usr/local目錄下面。 make sudo make install
沒有報錯,安裝成功。
5,編譯安裝turnserver-0.7.3
cd turnserver-0.7.3 ./configure //這裏不要指定目錄,使用默認目錄進行安裝。默認是安裝在/usr/local目錄下面。 make sudo make install
這兩個只因此沒有指定安裝目錄是由於設置了安裝目錄後,再安裝turnserver的時候,提示前面的confuse沒有安裝。
6,熟悉、創建、修改配置文件。
6.1 在turnserver源碼根目錄下的extra目錄下有配置模板能夠參考。
turnserver.fedora.initd #fedora平臺的啓動腳本
turnserver.spec #fedora平臺的啓動腳本
turnserver.debian.initd #debian平臺的啓動腳本
turnserver.conf.template#配置文件
turnusers.txt.template #用戶名、密碼配置文件
6.2 創建配置文件:
[hy@localhost-turnserver]$ cd extra/
[hy@localhost-extra]$ cp turnserver.conf.template /usr/local/etc/turnserver.conf
[hy@localhost-extra]$ cp turnusers.txt.template /usr/local/etc/turnusers.txt
[hy@localhost-extra]$ cd /usr/local/etc
6.3修改配置文件
cd /usr/local/etc
chmod 777 turnserver.conf
chmod 777 turnusers.txt
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"
的值相同.這個值用於密碼確認的.
7,啓動turnserver
[root@rlnf-76etc]# cd ../sbin
[root@rlnf-76sbin]# ./turnserver -c /usr/local/etc/turnserver.conf
8 啓動回顯服務:
在服務器上啓動回顯測試服務端程序:
[root@rlnf-76bin]# ./test_echo_server
UDP Echo server started on port 4588
9 測試服務器是否正常
在其它機器上(客戶機器)啓動測試程序:
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.
10 服務端打印的日誌:
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