基于janus源码 制作docker 镜像文件 (webrtc sfu服务器)

欢迎进janus群交流讨论  709487187

一 制作基于centos7系统的janus docker镜像

 创建dockerfile文件,文件名为Dockerfile,写入如下内容

FROM centos:7
 
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 && \
  yum provides '*/applydeltarpm'&& \  
  yum install deltarpm -y && \
  yum update -y && \
  yum install wget git -y &&  \
  cd etc/yum.repos.d  && \
  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo  && \
  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo  && \
  yum clean all  && \
  yum makecache  && \
  yum list | grep epel-release.noarch && \
  yum install epel-release.noarch  -y && \
  wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo    && \
  yum clean all  && \
  yum makecache  && \
  yum install -y  jansson-devel libwebsockets-devel.x86_64 \
       openssl-devel libsrtp-devel  glib2-devel libsrtp-devel.x86_64 \
        opus-devel libogg-devel libcurl-devel pkgconfig gengetopt  \
       libconfig-devel libtool autoconf automake cmake make meson librabbitmq-devel.x86_64 \
       gnutls-devel.x86_64 texinfo gtk-doc.x86_64 && \
  yum install epel-release -y && \
  yum update -y && \
  yum install -y https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm && \
  yum install -y ffmpeg-devel.x86_64 && \
  yum clean all && rm -rf /var/cache/yum/*  
WORKDIR /usr/local/src
#源码安装需要的库
RUN   wget https://github.com/cisco/libsrtp/archive/v2.0.0.tar.gz && \
   tar xfv v2.0.0.tar.gz && \
   cd libsrtp-2.0.0 && \
   ./configure --prefix=/usr --enable-openssl && \
   make shared_library && \
   make install && rm -rf /usr/local/src/*
RUN wget ftp://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.72.tar.gz && \
   tar xfv libmicrohttpd-0.9.72.tar.gz && \
   cd libmicrohttpd-0.9.72 && \
   ./configure && \
   make && \
   make install &&  rm -rf /usr/local/src/*
RUN git clone --branch 0.1.18  https://github.com/libnice/libnice.git && \
   cd libnice && \
   meson --prefix=/usr build && \
   ninja -C build && \
   ninja -C build install  && rm -rf /usr/local/src/*
RUN git clone --branch 0.9.5.0 https://github.com/sctplab/usrsctp.git  && \
   cd usrsctp && \
   ./bootstrap && \
   ./configure --prefix=/usr && \
   make && \
   make install 
RUN git clone https://github.com/freeswitch/sofia-sip.git  && \
  cd sofia-sip  && \
  ./bootstrap.sh  && \
  ./configure  && \
  make && make install && rm -rf /usr/local/src/* && \
  ldconfig && \
  cd /usr/local/src && \
  rm -rf ./* && \
  yum clean all && \
  rm -rf /var/cache/yum/*  && rm -rf /usr/local/src/*
RUN git clone --branch v0.11.2 https://github.com/meetecho/janus-gateway.git && \
   cd janus-gateway && \
    ./autogen.sh && \
    export  PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/lib/pkgconfig:$PKG_CONFIG_PATH && \
  ./configure --prefix=/usr/local/janus   --enable-json-logger  --enable-libsrtp2   --enable-post-processing   --enable-rest  --enable-websockets   && \
   make  && \
   make install  && \
   make configs && \
   make clean && rm -rf /usr/local/src/*



二 执行docker build -t  janus:0.11.2 .  因为有些代码需要到github上下载,可能会下载失败导致中断,如果失败就多执行几次。最后出现

 => => writing image sha256:b6770330374b943a93a83ee660c97e73af8b8a2c7a60a 表示images创建成功,通过docker images 即可看到创建的janus image

$ docker images

REPOSITORY   TAG            IMAGE ID       CREATED          SIZE

               b6770330374b   50 minutes ago   768MB

 如果使用 docker build . 没有指定镜像名称,生成的镜像需要用命令docker tag imagesid  Janus:0.1.2 打个tag

三 安装docker-copmpse并编写docker-composee配置文件

依次执行以下命令,确定docker-compose安装成功

pip3 install --upgrade pip

pip install docker-compose

创建docker-compose.yaml文件

写入以下内容


 

version: "3"

services:

  janus:

    image:  janus:0.11.2

    container_name: janus-gateway

    network_mode: "host"

    hostname: janus-gateway

    cap_add:

      - SYS_NICE

    working_dir:  /usr/local/janus/

    environment:

      - SET_CONTAINER_TIMEZONE=true

      - CONTAINER_TIMEZONE=Asia/Shanghai

      - TZ=Asia/Shanghai

    command:

    - /bin/sh

    - -c

    - |

      cd /usr/local/janus/bin

       nohup  ./janus >/dev/null  2>&1 &

      tail -f /dev/null

然后在当前目录下执行如下命令       docker-compose -f

docker-compose.yaml up -d 启动janus容器

宿主机上通过netstat -an|grep 8089/8088,看是否启动成功

janus服务器需要开放20000-40000udp端口

同时需要修改janus的配置文件,/usr/local/janus/etc/jianus目录下的janus.jcfg 文件,将 rtp_port_range = "20000-40000"的注释去掉

docker-compose -f docker-compose.yaml down --remove-orphans 命令为关闭janus容器

最后部署nginx demos环境

安装nginx,并修改nginx配置文件,配置好demos位置以及证书和key的路径,通过域名访问需要支持https,否则会有chrome无法调用摄像头的问题。如果没有证书使用ip地址测试也是可以的

server{

   listen 80;

   listen 8080;

   listen *:443 ssl;

   server_name localhost;

   location / {

    root /usr/local/demos;

    index index.html index.htm index.php;

   }



   location /jauns {

   proxy_set_header Host $host:$server_port;

   proxy_set_header X-Real-IP $remote_addr;

   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

    proxy_pass http://192.168.0.170:8088/janus;    #janus服务器ip地址

}



  ssl_certificate /usr/local/certs/cert.pem;

  ssl_certificate_key /usr/local/certs/cert.key;


   

然后重启nginx

然后就可以打开demos页面进行测试了

基于janus源码 制作docker 镜像文件 (webrtc sfu服务器)_第1张图片

基于janus源码 制作docker 镜像文件 (webrtc sfu服务器)_第2张图片

基于janus源码 制作docker 镜像文件 (webrtc sfu服务器)_第3张图片

你可能感兴趣的:(janus,docker,centos,webrtc,docker-compose,linux)