1. 程式人生 > >Ubuntu下安裝TURN Server (rfc5766-turn-server)

Ubuntu下安裝TURN Server (rfc5766-turn-server)

在使用WebRTC進行即時通訊時,需要使瀏覽器進行P2P通訊,但是由於NAT環境的複雜性,並不是所有情況下都能進行P2P,這時需要TURN Server來幫助客戶端之間轉發資料。rfc5766-turn-server是一個高效能的開源TURN Server實現。

以下是在EC2上使用Ubuntu作業系統安裝rfc5766-turn-server:

1. 下載安裝包:

$ wget http://ftp.cn.debian.org/debian/pool/main/r/rfc5766-turn-server/rfc5766-turn-server_3.2.4.4-1_amd64.deb

2. 安裝:

$ sudo apt-get update
$ sudo apt-get install gdebi-core
$ sudo gdebi rfc5766-turn-server_3.2.4.4-1_amd64.deb

安裝完後,在/usr/share/doc/rfc5766-turn-server下有很多文件可參考。

3. 配置:

$ sudo vi /etc/turnserver.conf
---------------------------------------
// 配置IP,EC2下需要配置listening-ip和external-ip
listening-ip=172.31.4.37
external-ip=54.223.149.60
// 當TURN Server用於WebRTC時,必須使用long-term credential mechanism
lt-cred-mech
// 增加一個使用者
user=username1:password1
// 設定realm
realm=mycompany.org
---------------------------------------

. 4. 啟動:

sudo turnserver -c /etc/turnserver.conf --daemon

. 5. 服務啟動後,在上一個WebRTC示例中更改iceServers後測試:

"iceServers": [{
    "url": "stun:stun.l.google.com:19302"
}, {
    "url": "turn:54.223.149.60",
    "username": "username1",
    "credential": "password1"
}]

更多安裝資訊在:http://turnserver.open-sys.org/downloads/v3.2.4.4/INSTALL

rfc5766-turn-server當然也有STUN Server的能力,但是需要給它配置2個IP,以幫助探測客戶端所在NAT環境的行為,這裡沒有做。

微信訂閱號: