#WebRTC服務器——Licode 環境搭建html
##系統配置node
阿里雲服務器git
Ubuntu 14.04.5 LTSgithub
在一臺空的機器上搭建docker環境,先要安裝docker,執行下面的命令便可:web
apt-get update apt-get install docker.io
執行下面的shell腳本:docker
#!/bin/sh MIN_PORT=30000; MAX_PORT=30050; docker run --name licode -p 3000:3000 -p $MIN_PORT-$MAX_PORT:$MIN_PORT-$MAX_PORT/udp -p 3001:3001 -p 8080:8080 -e "MIN_PORT=$MIN_PORT" -e "MAX_PORT=$MAX_PORT" -e "PUBLIC_IP=your_ip_address" lynckia/licode
沒錯任何錯誤的話,licode服務會自動運行起來,查看port:shell
root@test:/git/docker# netstat -nltp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 865/sshd tcp6 0 0 :::8080 :::* LISTEN 4732/docker-proxy tcp6 0 0 :::3000 :::* LISTEN 4496/docker-proxy tcp6 0 0 :::3001 :::* LISTEN 4856/docker-proxy
有幾點注意瀏覽器
最後能夠在Chrome或者火狐瀏覽器中輸入地址:服務器
http://your_ip_address:3001
做者在一臺Mac和一臺andorid上測試的,看一下效果,就不露臉了~~ 網絡
先按照官方文檔的步驟操做:
git clone https://github.com/lynckia/licode.git cd licode
安裝Licode依賴的組件:
./scripts/installUbuntuDeps.sh
安裝LIcode的各個組件:
./scripts/installNuve.sh ./scripts/installErizo.sh
./scripts/installBasicExample.sh
由於是在阿里雲服務器上搭建環境,有些關於服務器地址的配置須要修改,在licode_config.js中把下面的字段改爲阿里雲服務器的外網IP或者域名:
config.erizoController.publicIP = 'your_ip_address'; config.erizoController.hostname = 'your_ip_address'; config.erizoAgent.publicIP = 'your_ip_address'; //default value: ''
改一下網卡的名字,通常都是eth0:
config.erizoAgent.networkinterface = 'eth0'; //default value: '':w
啓動Licode服務:
./scripts/initLicode.sh
啓動Licode實例:
./scripts/initBasicExample.sh
在瀏覽器裏面輸入下面的URL以後:
http://your_ip_address:3001
瀏覽器會報下面的錯誤:
ICE failed, add a TURN server and see about:webrtc for more details
看一下licode的配置文件licode_config.js,配置ICE server的地方:
config.erizoController.iceServers = [{'url': 'stun:stun.l.google.com:19302'}]; // default value: [{'url': 'stun:stun.l.google.com:19302'}]
只有一個STUN服務器連接,看來是須要本身添加一個TURN服務器,做者本身在本地搭建了一個coturn服務器,具體流程能夠參考此連接,做者採用的是編譯安裝。
在網絡上搜索了不少資料來配置coturn,不少都沒有成功,下面是做者本身機器上的配置:
#若是多網卡,記得此處設置爲和你所用監聽的IP相對應的eth listening-device=eth0 listening-ip=your_local_address external-ip=your_external_address listening-port=3478 relay-device=eth0 min-port=30000 max-port=30050 Verbose fingerprint #webrtc須要使用此選項 lt-cred-mech #use-auth-secret #static-auth-secret=123456 #以前turnadmin中-r參數的值,此處要對應 realm=demo stale-nonce #能夠添加用戶名和密碼 user=demo:123456 #測試期間可使用example/etc中的pem,本身計算的話須要用到openssl,方法爲: #sudo openssl req -x509 -newkey rsa:2048 -keyout /etc/ turn_server_pkey.pem -out /etc/turn_server_cert.pem -days 99999 -nodes #填寫pem目錄便可,如 #cert=/root/cert/_cert.pem cert=/root/cert/mycert.pem #pkey=/root/cert/_pkey.pem pkey=/root/cert/mycert.key no-loopback-peers no-multicast-peers mobility no-cli
關於如何添加用戶名和密碼,如何配置證書須要自行解決。
執行下面的命令:
turnserver -c path/turnserver.conf
碰到下面一堆log不要驚慌,這不是錯誤的log,只是在監聽事件:
1112: timer_event_handler: timeout 0xc449b0: timer_handler 1113: timer_event_handler: timeout 0xc461b0: rtcp_map_timeout_handler 1113: timer_event_handler: timeout 0x7f2acc001c90: timer_handler 1113: timer_event_handler: timeout 0x7f2acc002ea0: timer_timeout_handler 1113: timer_event_handler: timeout 0x7f2ac4001c90: timer_handler 1113: timer_event_handler: timeout 0x7f2ac4002ea0: timer_timeout_handler 1113: timer_event_handler: timeout 0x7f2ac8001d30: timer_handler
添加了turn 選項:
config.erizoController.iceServers = [{'url': 'stun:stun.l.google.com:19302'},{'url':'turn:your_external_address:3478','username':'demo','credential':'123456'}]; //
最後重啓licode服務和實例,在地址欄在此輸入地址,若是請求TURN穿透,coturn服務會有相似下面的log:
86: read_client_connection:4436:start 86: read_client_connection: data.buffer=0x7f26040033ec, data.len=100 86: session 000000000000000005: peer 10.0.42.1 lifetime updated: 300 86: session 000000000000000005: realm <demo> user <demo>: incoming packet CREATE_PERMISSION processed, success 86: write_client_connection:4220:start 86: write_client_connection: prepare to write to s 0x7f2604028170 86: write_client_connection:4243:end 86: read_client_connection:4542:end 86: udp_server_input_handler:666:end 86: udp_server_input_handler:628:start 86: read_client_connection:4436:start 86: read_client_connection: data.buffer=0x7f26040033ec, data.len=140 86: handle_turn_send:2916:start 86: handle_turn_send:3011:end 86: session 000000000000000005: realm <demo> user <demo>: incoming packet SEND processed, success 86: udp_server_input_handler:666:end 86: udp_server_input_handler:628:start 86: read_client_connection:4436:start 86: read_client_connection: data.buffer=0x7f260401816c, data.len=140
瀏覽器控制檯上有時會有下面的log:
ICE failed, your TURN server appears to be broken, see about:webrtc for more details
這是你的turnserver沒有配置好,若是鏈接成功,最終瀏覽器控制檯會有下面的連接成功的log:
DEBUG: Event: ice-state-change erizo.js:28:39 DEBUG: Event: icestatechanged erizo.js:28:39 INFO: 341271403301651300 - iceConnectionState: connected erizo.js:28:39 DEBUG: Event: onAddStream erizo.js:28:39 DEBUG: Event: stream-added erizo.js:28:39 DEBUG: Event: signaling_message_erizo
最後放一個搭建好的licode環境連接: webrtc實驗田
原文出處:https://www.cnblogs.com/harlanc/p/10226614.html