流媒体服务器 Janus 的编译过程

----------------------------------------------------------------------------------------------------------------------

一分钟快速搭建 rtmpd 服务器: https://blog.csdn.net/freeabc/article/details/102880984

软件下载地址: http://www.qiyicc.com/download/rtmpd.zip

github 地址:https://github.com/superconvert/smart_rtmpd

----------------------------------------------------------------------------------------------------------------------

操作系统 Ubuntu 18.04 64 位, Janus 和 Mediasoup 都是性能非常不错的 webrtc 服务器,相对比较简易,下面是我亲自验证并能成功编译运行的流程,分享给大家

1. 安装 libnice

git clone https://gitlab.freedesktop.org/libnice/libnice

问题解决
  https://blog.csdn.net/ewerwerwerer/article/details/107936762
  这个错误是meson版本不匹配导致的,ubuntun18.04中的meson版本为0.45.1, libnice中用了更新的meson版本,所以就想着在ubuntu18.04中更新meson的版本。
  但是apt中meson的最新版本号就是0.45.1 通过 pip3 install --user meson 安装最新的 meson , 继续搜索发现pip3会将软件安装到/home/user/.local/bin 
  而系统默认是使用/usr/bin/meson 所以通过修改path路径使得pip安装的meson优先于系统meson被搜索到 export PATH=~/.local/bin:$PATH
安装 gnutls
aptitude install libgnutls28-dev

安装 gstreamer
aptitude install libgstreamer1.0-dev

安装 meson
apt install meson

安装 pip
apt install python3-pip

更新 meson 为最新版本

pip3 install --user meson
export PATH=~/.local/bin:$PATH

meson -v 查看版本,是否是最新版本,否则无法编译 libice

开始编译 libice

cd libnice
meson build
ninja -C build
ninja -C build test
ninja -C build install

2. 安装 libwebsocket

git clone https://github.com/warmcat/libwebsockets.git
aptitude install libssl-dev
mkdir build
cd build/
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" ..
make
sudo make install

3. 安装 nodejs 

wget https://nodejs.org/dist/v14.8.0/node-v14.8.0-linux-x64.tar.xz
tar -xJf node-v14.8.0-linux-x64.tar.xz -C /opt
sudo ln -s /opt/node-v14.8.0-linux-x64/bin/npm /usr/local/bin/npm
sudo ln -s /opt/node-v14.8.0-linux-x64/bin/node /usr/local/bin/node
node -v
sudo npm -g install http-server

4. 安装 libsrtp/archive/v2

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

5. 编译 janus

git clone https://github.com/meetecho/janus-gateway.git
aptitude install libconfig-dev
aptitude install libjansson-dev
aptitude install gengetopt 
aptitude install libmicrohttpd-dev
cd janus-gateway/
./autogen.sh 
./configure --prefix=/opt/janus --enable-websockets --enable-http
make
sudo make install
make configs
/opt/janus/bin/janus --debug-level=7 --log-file=$HOME/janus-log

6. 制作测试证书

编制脚本 make_cert.sh 制作私有证书

  !/bin/sh
  openssl genrsa -out privkey.pem 1024
  openssl req -new -x509 -key privkey.pem -out server.pem -days 365

7. 安装 nginx

apt install nginx

拷贝 janus 演示页面到 /opt/html 下

mkdir /opt/html
cp /root/work/janus-gateway/html/* /opt/html/ -r

编辑 vi /etc/nginx/nginx.conf 

http {
    server {
        listen 0.0.0.0:443 ssl;
        listen [::]:443 ssl;
        # tls configuration that is not covered in this guide
        # we recommend the use of https://certbot.eff.org/
        server_name doman.com;
        # janus 的演示页面        
        root /opt/html;
        index index.html;
        location ~ ^/([a-zA-Z0-9=\?]+)$ {
            rewrite ^/(.*)$ / break;
        }
        location / {
            ssi on;
        }

        # 证书的路径
        ssl_certificate /root/work/cert/server.pem; 
        ssl_certificate_key /root/work/cert/privkey.pem; 
    }
}

8. 配置 janus

vi /opt/janus/etc/janus/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)
        http = false                                    # 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 = "/root/work/cert/server.pem"
        cert_key = "/root/work/cert/privkey.pem"
        #cert_pwd = "secretpassphrase"
        #ciphers = "PFS:-VERS-TLS1.0:-VERS-TLS1.1:-3DES-CBC:-ARCFOUR-128"
}

9. 运行

运行 nginx

service nginx restart

运行 janus

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

10. 测试

http://ip:port/index.html

这样就可以体验 janus 了, good luck!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章