日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Ubuntu >内容正文

Ubuntu

Ubuntu下搭建Janus Server

發(fā)布時間:2024/4/11 Ubuntu 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Ubuntu下搭建Janus Server 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Ubuntu下搭建Janus Server


目錄

  • Janus簡介
  • 下載和編譯 Janus
  • 配置和運行janus
  • 視頻通話聯(lián)調測試

  • 1. Janus簡介

  • Janus 是一個開源的,通過 C 語言實現(xiàn)了對 WebRTC 支持的 Gateway。
  • Janus 自身實現(xiàn)得很簡單,提供插件機制來支持不同的業(yè)務邏輯,配合官方自帶插件就可以用來實現(xiàn)高效的 Media Server 服務。
  • 本博客在 Ubuntu下搭建 Janus 服務器,實現(xiàn) janus 官方 Demo 瀏覽器與 Android APP Demo(janus-gateway-android)之間的音視頻通話。注意:瀏覽器打開音視頻采集的話需要 HTTPS 加密訪問。
  • 2. 下載和編譯 Janus

  • 編譯運行 Janus Server 需要依賴較多的一些第三方庫,而這些依賴庫在 Ubuntu 下主要通過 aptitude 進行安裝,首先通過安裝 aptitude:
  • sudo apt-get install aptitude sudo apt-get update
  • 執(zhí)行以下命令更新鏡像源
  • sudo apt-get update && sudo apt-get upgrade

    1. 命令安裝依賴

  • Ubuntu 下通過 aptitude 批量安裝依賴工具包
  • 批量安裝命令:
  • sudo apt install build-essentialsudo aptitude install libmicrohttpd-dev libjansson-dev libnice-dev libsofia-sip-ua-dev \libopus-dev libogg-dev libcurl4-openssl-dev pkg-config gengetopt \libtool automakesudo aptitude install libglib2.3.4-dev sudo apt install cmake sudo aptitude install libconfig-dev sudo aptitude install libssl-dev sudo aptitude install doxygen graphviz# ffmpeg庫 支持--enable-post-processing sudo aptitude install libavcodec-dev libavformat-dev libswscale-dev libavutil-dev
  • 附錄:卸載命令
  • apt-get remove 會刪除軟件包而保留軟件的配置文件 apt-get purge 會同時清除軟件包和軟件的配置文件
  • 查找包命令
  • 查找軟件包 apt-cache search 軟件包名 顯示軟件包的詳細信息 apt-cache show 軟件包名

    2. 源碼安裝依賴

    1. 安裝 WebSocket

  • janus 支持 WebSocket 是可選項,如果不安裝,編譯 janus 時,默認不支持 WebSocket 的鏈接請求,而 Android APP Demo 是通過 WebSocket 與 janus 進行通信的,因此如果需要 Android APP Demo 能與瀏覽器(HTTP)進行視頻通話,所以就必須要在編譯 janus 時支持 WebSocket。
  • 依次執(zhí)行以下命令,分別進行下載,編譯,安裝:
  • git clone https://gitee.com/embedded-lib/libwebsockets.git 或 git clone https://github.com/warmcat/libwebsockets.git cd libwebsockets git branch -a 查看選擇最新的穩(wěn)定版本, git checkout v4.3.0 切換到較新穩(wěn)定版本 mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" .. make && sudo make install
  • 安裝成功后,在編譯 janus 時,janus 默認會增加對 WebSocket 的集成,或者通過增加編譯參數(shù) --enable-websockets 打開 WebSocket 開關
  • 2. 安裝 libsrtp

  • Janus 需要至少 version 1.5 以上的 libsrtp,如果系統(tǒng)中已經(jīng)安裝了 libsrtp,則首先卸載后,手動安裝新版本,這里我們安裝 libsrtp 2.2,2. 依次執(zhí)行以下命令:
  • git clone https://gitee.com/MediaNext/libsrtp.git cd libsrtp git checkout v2.3.0 ./configure --prefix=/usr --enable-openssl make shared_library && sudo make install

    3. 安裝libmicrohttpd

  • libmicrohttpd支持–enable-rest
  • wget https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.71.tar.gz tar zxf libmicrohttpd-0.9.71.tar.gz cd libmicrohttpd-0.9.71/ ./configure make sudo make install

    3. 編譯 Janus

  • 通過 Git 下載 Janus 源碼,并編譯安裝:
  • git clone https://gitee.com/easyhao/janus-gateway.git 或git clone https://github.com/meetecho/janus-gateway.git cd janus-gateway git tag 查看當前的 tag,選擇最新穩(wěn)定的版本v0.10.4 git checkout v0.10.4 sh autogen.sh ./configure --prefix=/opt/janus --enable-websockets --enable-post-processing --enable-docs --enable-rest make sudo make install
  • make install的時候,將janus安裝到 /opt/janus路徑,插件的so庫在/opt/janus/lib/janus/plugins

  • configure 執(zhí)行成功后,會輸出 janus 所支持的 協(xié)議及插件,如下:

  • ompiler: gcc libsrtp version: 2.x SSL/crypto library: OpenSSL DTLS set-timeout: not available Mutex implementation: GMutex (native futex on Linux) DataChannels support: yes Recordings post-processor: yes TURN REST API client: yes Doxygen documentation: yes Transports:REST (HTTP/HTTPS): yesWebSockets: yesRabbitMQ: noMQTT: noUnix Sockets: yesNanomsg: no Plugins:Echo Test: yesStreaming: yesVideo Call: yesSIP Gateway: yesNoSIP (RTP Bridge): yesAudio Bridge: yesVideo Room: yesVoice Mail: yesRecord&Play: yesText Room: yesLua Interpreter: noDuktape Interpreter: no Event handlers:Sample event handler: yesWebSocket ev. handler: yesRabbitMQ event handler:noMQTT event handler: noNanomsg event handler: noGELF event handler: yes External loggers:JSON file logger: no JavaScript modules: no

    3. 配置和運行janus

    1. 配置nginx

  • 安裝nginx,主要用來提供web訪問。
  • 1. 生成證書

    mkdir -p ~/cert cd ~/cert # CA私鑰 openssl genrsa -out key.pem 2048自簽名證書 openssl req -new -x509 -key key.pem -out cert.pem -days 1095

    2. 安裝nginx

    #下載nginx 1.15.8版本 wget http://nginx.org/download/nginx-1.15.8.tar.gz tar xvzf nginx-1.15.8.tar.gz cd nginx-1.15.8/# 配置,一定要支持https ./configure --with-http_ssl_module # 編譯 make#安裝 sudo make install

    3. 修改nginx配置文件

  • Nginx配置文件默認在 /usr/local/nginx/conf/nginx.conf
  • 指向janus所在目錄/opt/janus/share/janus/demos
  • # HTTPS server#server {listen 443 ssl;server_name localhost;# 配置相應的keyssl_certificate /root/cert/cert.pem;ssl_certificate_key /root/cert/key.pem;ssl_session_cache shared:SSL:1m;ssl_session_timeout 5m;ssl_ciphers HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers on;# 指向janus demo所在目錄location / {root /opt/janus/share/janus/demos;index index.html index.htm;}}

    4. 啟動nginx

    sudo /usr/local/nginx/sbin/nginx
  • 然后通過 https://服務器公網(wǎng)地址(比如:https://8.141.75.xxx/)就可以訪問到界面,但此時還不能正常通話。
  • 注意如果訪問不通,需要設置安全組,添加80和443端口
  • 如果提示在Chrome中打開網(wǎng)頁時出現(xiàn)以下問題:您的連接不是私密連接 攻擊者可能會試圖從 x.x.x.x 竊取您的信息(例如:密碼、通訊內容或信用卡信息),直接在頁面輸入:thisisunsafe ,回車,頁面即會自動刷新進入網(wǎng)頁。
  • 2. 安裝和啟動coturn

    sudo apt-get install libssl-dev sudo apt-get install libevent-dev ? #git clone https://github.com/coturn/coturn #cd coturn # 提供另一種安裝方式turnserver是coturn的升級版本 wget http://coturn.net/turnserver/v4.5.0.7/turnserver-4.5.0.7.tar.gz tar xfz turnserver-4.5.0.7.tar.gz cd turnserver-4.5.0.7./configure make && sudo make install
  • 啟動
  • sudo nohup turnserver -L 0.0.0.0 --min-port 50000 --max-port 60000 -a -u xxx:123456 -v -f -r nort.gov &
  • 需要在安全組開放端口: TCP/UDP 3478 和 UDP 50000-60000
  • 3. 配置janus的jcfg文件

  • janus安裝目錄在/opt/janus
  • ./bin./etc./include./lib./share
    可執(zhí)行文件janus配置文件janus頭文件janus庫存放腳本或者文檔,web demo也在這里

    1. 配置Video room

  • 先配置video room,需要配置的文件為(目錄/opt/janus/etc/janus),并開通8088,8089,8188,8989端口
  • 要先把.sample后綴的文件拷貝成jcfg后綴
  • # 進到對應的目錄 cd /opt/janus/etc/janus # 拷貝文件 sudo cp janus.jcfg.sample janus.jcfg sudo cp janus.transport.http.jcfg.sample janus.transport.http.jcfg sudo cp janus.transport.websockets.jcfg.sample janus.transport.websockets.jcfg sudo cp janus.plugin.videoroom.jcfg.sample janus.plugin.videoroom.jcfg sudo cp janus.transport.pfunix.jcfg.sample janus.transport.pfunix.jcfg sudo cp janus.plugin.streaming.jcfg.sample janus.plugin.streaming.jcfg sudo cp janus.plugin.recordplay.jcfg.sample janus.plugin.recordplay.jcfg sudo cp janus.plugin.voicemail.jcfg.sample janus.plugin.voicemail.jcfg sudo cp janus.plugin.sip.jcfg.sample janus.plugin.sip.jcfg sudo cp janus.plugin.nosip.jcfg.sample janus.plugin.nosip.jcfg sudo cp janus.plugin.textroom.jcfg.sample janus.plugin.textroom.jcfg sudo cp janus.plugin.echotest.jcfg.sample janus.plugin.echotest.jcfg

    2. 配置janus.jcfg

    # 大概237行 stun_server = "8.141.75.xxx"stun_port = 3478nice_debug = false # 大概267行 填寫云服務器外網(wǎng)ip地址 nat_1_1_mapping = "8.141.75.xxx" ? #大概274# credentials to authenticate...turn_server = "8.141.75.xxx"turn_port = 3478turn_type = "udp"turn_user = "ljw"turn_pwd = "123456"
  • ?大約202行左右,設置udp端口范圍。
  • 3. 配置janus.transport.http.jcfg

    general: {#events = true # Whether to notify event handlers about transport events (default=true)json = "indented" # Whether the JSON messages should be indented (default),# plain (no indentation) or compact (no indentation and no spaces)base_path = "/janus" # Base path to bind to in the web server (plain HTTP only)threads = "unlimited" # unlimited=thread per connection, number=thread poolhttp = true # Whether to enable the plain HTTP interfaceport = 8088 # Web server HTTP port#interface = "eth0" # Whether we should bind this server to a specific interface only#ip = "192.168.0.1" # Whether we should bind this server to a specific IP address (v4 or v6) onlyhttps = true # Whether to enable HTTPS (default=false)secure_port = 8089 # Web server HTTPS port, if enabled#secure_interface = "eth0" # Whether we should bind this server to a specific interface only#secure_ip = "192.168.0.1" # Whether we should bind this server to a specific IP address (v4 or v6) only#acl = "127.,192.168.0." # Only allow requests coming from this comma separated list of addresses } ? certificates: {cert_pem = "/home/ubuntu/cert/cert.pem" # 跟前面配置的cert.pem一樣路徑cert_key = "/home/ubuntu/cert/key.pem"#cert_pwd = "secretpassphrase"#ciphers = "PFS:-VERS-TLS1.0:-VERS-TLS1.1:-3DES-CBC:-ARCFOUR-128" }

    4. 配置janus.transport.websockets.jcfg

    general: {#events = true # Whether to notify event handlers about transport events (default=true)json = "indented" # Whether the JSON messages should be indented (default),# plain (no indentation) or compact (no indentation and no spaces)#pingpong_trigger = 30 # After how many seconds of idle, a PING should be sent#pingpong_timeout = 10 # After how many seconds of not getting a PONG, a timeout should be detected ?ws = true # Whether to enable the WebSockets APIws_port = 8188 # WebSockets server port#ws_interface = "eth0" # Whether we should bind this server to a specific interface only#ws_ip = "192.168.0.1" # Whether we should bind this server to a specific IP address onlywss = true # Whether to enable secure WebSocketswss_port = 8989 # WebSockets server secure port, if enabled#wss_interface = "eth0" # Whether we should bind this server to a specific interface only#wss_ip = "192.168.0.1" # Whether we should bind this server to a specific IP address only#ws_logging = "err,warn" # libwebsockets debugging level as a comma separated list of things# to debug, supported values: err, warn, notice, info, debug, parser,# header, ext, client, latency, user, count (plus 'none' and 'all')#ws_acl = "127.,192.168.0." # Only allow requests coming from this comma separated list of addresses } ? certificates: {cert_pem = "/home/ubuntu/cert/cert.pem"cert_key = "/home/ubuntu/cert/key.pem"#cert_pwd = "secretpassphrase" }

    4. 修改網(wǎng)頁默認支持的wss協(xié)議

  • 修改 /opt/janus/share/janus/demos/videoroomtest.js文件,原來為(在45行處)
  • var server = null; if(window.location.protocol === 'http:')server = "http://" + window.location.hostname + ":8088/janus"; elseserver = "https://" + window.location.hostname + ":8089/janus"; 將默認的https協(xié)議改為wss var server = "wss://" + window.location.hostname + ":8989";

    5. 配置coturn地址-這里不是必須的

  • 這里不是必須的
  • 修改 /opt/janus/share/janus/demos/videoroomtest.js 文件,配置自己搭建的coturn地址,以下ip、用戶名,密碼根據(jù)實際修改。在約83行添加。
  • iceServers :[{urls: ["turn:8.141.75.xxx:3478?transport=udp","turn:8.141.75.xxx:3478?transport=tcp" ],username: "ljw",credential: "123456" }, {urls: ["stun:8.141.75.xxx:3478"] }],

    6. 云服務器端口開放

  • 需要用到的端口有:TCP的8088,8089,8188,8989,3478,UDP的3478,50000~60000端口
  • 7. 運行 Janus

  • WebSocket 的ws端口號為 8188 和 8989,記住這個端口號,在 Android APP Demo 中會使用到
  • 啟動 Janus:
  • /opt/janus/bin/janus --debug-level=5 --log-file=$HOME/janus-log
  • 根據(jù)需要可以選擇是否加上后面兩個啟動參數(shù)。
  • 8. 測試web和web的通話

  • 打開 https://8.141.75.xxx/videoroomtest.html
  • 開兩個同樣的網(wǎng)頁,然后點擊start,輸入名字則開始進行音視頻通話測試。
  • 4. 視頻通話聯(lián)調測試

  • 我們使用 PC 下的 瀏覽器 與 Android APP Demo 進行聯(lián)調,有空補上。
  • ?

    總結

    以上是生活随笔為你收集整理的Ubuntu下搭建Janus Server的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。