Ubuntu16.04 中 搭建Janus Server

Ubuntu16.04 局域网中搭建Janus Server

文章目录

  • Ubuntu16.04 局域网中搭建Janus Server
    • janus简介
    • 系统环境
    • 安装准备
      • 安装 aptitu
      • 安装依赖
    • 安装源码
      • 安装 WebSocket
      • 安装 libsrtp
      • 安装libusrsctp
      • 安装libmicrohttpd
      • 安装 Janus
      • 安装和配置nginx
        • 签名证书
        • 安装nginx
        • 配置nginx
        • 验证nginx配置是否成功
    • janus 官方demo运行
      • 配置janus
      • 修改demo增加wss支持
      • 验证 Janus demo

janus简介

​ Janus是WebRTC 服务器端的开源项目,官方对其定义是一个WebRTC服务器端,支持的功能比较丰富,通过core模块来支持不同的插件的方式,支持SFU模式,客户端集成相对比较简。开发语言(C语言),代码架构比较清晰,支持了SIP 接口。

官方网址:https://janus.conf.meetecho.com/index.html

系统环境

uname -ar
Linux ubuntu16 4.4.0-186-generic #216-Ubuntu SMP Wed Jul 1 05:34:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

安装准备

安装 aptitu

sudo apt-get install aptitude

安装依赖

sudo aptitude install libmicrohttpd-dev libjansson-dev libnice-dev \
    libssl1.0.1-dev libsrtp-dev libsofia-sip-ua-dev libglib2.3.4-dev \
    libopus-dev libogg-dev libcurl4-openssl-dev pkg-config gengetopt \
    libtool automake
    
sudo apt install cmake
sudo aptitude install libconfig-dev
sudo aptitude install libssl-dev
sudo aptitude install doxygen graphviz
sudo aptitude install libavcodec-dev libavformat-dev libswscale-dev libavutil-dev

安装源码

janus支持插件式功能安装,根据需求选择安装,这里将安装:WebSocket(支持 WebSocket),bsrtp和libusrsctp(音视频流传输控制和数据协议支持),libmicrohttpd(支持http/https),Janus(咱们的主角),nginx(提供web服务)

Ubuntu16.04 中 搭建Janus Server_第1张图片

安装 WebSocket

git clone https://github.com/warmcat/libwebsockets.git
cd libwebsockets
git checkout v3.2-stable 
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" ..
make && sudo make install

janus会通过 --enable-websockets 使能 WebSocket 开关, --disable-websockets 关闭 WebSocket 开关

安装 libsrtp

wget https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gz
tar xfv v2.2.0.tar.gz
cd libsrtp-2.2.0
./configure --prefix=/usr --enable-openssl
make shared_library && sudo make install

安装libusrsctp

git clone https://github.com/Kurento/libusrsctp.git
cd libusrsctp
./bootstrap
./configure
make
sudo make install

janus会通过–enable-data-channels支持libusrsctp

安装libmicrohttpd

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

janus会通过–enable-rest支持

安装 Janus

git clone https://github.com/meetecho/janus-gateway.git
git  checkout v0.10.4
sh autogen.sh
./configure --prefix=/opt/janus --enable-websockets --enable-post-processing --enable-docs --enable-rest --enable-data-channels
make
sudo make install

执行后,

Compiler:                  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):     yes
    WebSockets:            yes
    RabbitMQ:              no
    MQTT:                  no
    Unix Sockets:          yes
    Nanomsg:               no
Plugins:
    Echo Test:             yes
    Streaming:             yes
    Video Call:            yes
    SIP Gateway:           yes
    NoSIP (RTP Bridge):    yes
    Audio Bridge:          yes
    Video Room:            yes
    Voice Mail:            yes
    Record&Play:           yes
    Text Room:             yes
    Lua Interpreter:       no
    Duktape Interpreter:   no
Event handlers:
    Sample event handler:  yes
    WebSocket ev. handler: yes
    RabbitMQ event handler:no
    MQTT event handler:    no
    Nanomsg event handler: no
    GELF event handler:    yes
External loggers:
    JSON file logger:      no
JavaScript modules:        no

安装和配置nginx

签名证书

使用https/wss,需要证书,使用如下命令生成:

mkdir -p ~/cert
cd ~/cert
# CA私钥
openssl genrsa -out key.pem 2048
# 自签名证书
openssl req -new -x509 -key key.pem -out cert.pem -days 1095
安装nginx
wget http://nginx.org/download/nginx-1.15.8.tar.gz
tar xvzf nginx-1.15.8.tar.gz
cd nginx-1.15.8/
./configure --with-http_ssl_module 
make
sudo make install
配置nginx
vim /usr/local/nginx/conf/nginx.conf

修改大概98行位置,如下:

98     server {
99         listen       443 ssl;
100         server_name  localhost;
101
102         ssl_certificate      自己的证书路径/cert.pem;   #自己的证书
103         ssl_certificate_key  自己的证书路径/key.pem;
104
105         ssl_session_cache    shared:SSL:1m;
106         ssl_session_timeout  5m;
107
108         ssl_ciphers  HIGH:!aNULL:!MD5;
109         ssl_prefer_server_ciphers  on;
110
111         location / { 
112             root   /opt/janus/share/janus/demos;  #web网页打开时,定位到这里
113             index  index.html index.htm;
114         }
115     }

验证nginx配置是否成功
  1. 查看ngnix是否启动:
    ps -ef | grep nginx
    root 2046 1 0 10:55 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
    nobody 2047 2046 0 10:55 ? 00:00:00 nginx: worker process
    hbwang 2051 1858 0 10:55 pts/0 00:00:00 grep --color=auto nginx

  2. 如果没有启动,请执行如下cmd启动:
    sudo /usr/local/nginx/sbin/nginx

  3. 使用谷歌浏览器(qq浏览器也可以,但火狐我测试不能打开),进行验证 https://自己的本地ip
    Ubuntu16.04 中 搭建Janus Server_第2张图片

janus 官方demo运行

配置janus

将sample配置cp一份,作为我们janus基本配置,然后在此基础上更改

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

这里需要配置janus.transport.http.jcfg,janus.transport.websockets.jcfg

janus.transport.http.jcfg主要开启https和增加证书

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 pool
        http = true                                             # Whether to enable the plain HTTP interface
        port = 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) only
        https = 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 = "自己的证书路径/cert.pem"
        cert_key = "自己的证书路径/key.pem"
        #cert_pwd = "secretpassphrase"
        #ciphers = "PFS:-VERS-TLS1.0:-VERS-TLS1.1:-3DES-CBC:-ARCFOUR-128"
}

janus.transport.websockets.jcfg主要开启wss和增加证书

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 API
        ws_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 only
        wss = true                                              # Whether to enable secure WebSockets
        wss_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 = "自己的证书路径/cert.pem"
        cert_key = "自己的证书路径/key.pem"
        #cert_pwd = "secretpassphrase"
}

修改demo增加wss支持

vim /opt/janus/share/janus/demos/videoroomtest.js

var server = null;
if(window.location.protocol === 'http:')
        server = "http://" + window.location.hostname + ":8088/janus";
else
        #server = "https://" + window.location.hostname + ":8089/janus";
        server = "wss://" + window.location.hostname + ":8989";

验证 Janus demo

/opt/janus/bin/janus --debug-level=5 --log-file=$HOME/janus-log

启动log如下:

Janus commit: b68b209f91d0250f0739feee28555fe71255450b
Compiled on:  Sat Jan 30 12:50:58 CST 2021

Logger plugins folder: /opt/janus/lib/janus/loggers
---------------------------------------------------
  Starting Meetecho Janus (WebRTC Server) v0.10.4
---------------------------------------------------

Checking command line arguments...
Debug/log level is 3
Debug/log timestamps are disabled
Debug/log colors are enabled
[WARN] Token based authentication disabled
[WARN] Janus is deployed on a private address (192.168.1.4) but you didn't specify any STUN server! Expect trouble if this is supposed to work over the internet and not just in a LAN...
[WARN] The libsrtp installation does not support AES-GCM profiles
[WARN] No cert/key specified, autogenerating some...
[WARN] Event handlers support disabled
[ERR] [config.c:janus_config_parse:191]   -- Error reading configuration file 'janus.plugin.videocall.jcfg'... error 2 (No such file or directory)
[WARN] Couldn't find .jcfg configuration file (janus.plugin.videocall), trying .cfg
[ERR] [config.c:janus_config_parse:191]   -- Error reading configuration file 'janus.plugin.videocall.cfg'... error 2 (No such file or directory)
[ERR] [config.c:janus_config_parse:191]   -- Error reading configuration file 'janus.plugin.audiobridge.jcfg'... error 2 (No such file or directory)
[WARN] Couldn't find .jcfg configuration file (janus.plugin.audiobridge), trying .cfg
[ERR] [config.c:janus_config_parse:191]   -- Error reading configuration file 'janus.plugin.audiobridge.cfg'... error 2 (No such file or directory)
[WARN] Admin/monitor HTTP webserver disabled
[WARN] Admin/monitor HTTPS webserver disabled
[WARN] Unix Sockets server disabled (Janus API)
[WARN] Unix Sockets server disabled (Admin API)
[WARN] No Unix Sockets server started, giving up...
[WARN] The 'janus.transport.pfunix' plugin could not be initialized
[WARN] libwebsockets has been built without IPv6 support, will bind to IPv4 only
[WARN] Admin WebSockets server disabled
[WARN] Secure Admin WebSockets server disabled
[WARN] libnice version outdated: 0.1.13 installed, at least 0.1.16 recommended. Notice the installed version was checked at build time: if you updated libnice in the meanwhile, re-configure and recompile to get rid of this warning

使用谷歌浏览器(qq浏览器也可以,但火狐我测试不能打开),进行验证 https://自己的本地ip

Ubuntu16.04 中 搭建Janus Server_第3张图片

Ubuntu16.04 中 搭建Janus Server_第4张图片

你可能感兴趣的:(janus,后端)