基于docker的OZO流媒体服务器的使用和搭建方法

这是我写的当前基于docker的流媒体服务器的使用和搭建方法,当然细节上还有很多优化和改进的空间,包括可以通过dockerfile的方式更加快速方便地构建镜像。整体上来看通过docker将流媒体服务器整合进Live服务器后不仅设备数量上有所减少同时系统稳定性也有所加强。

在新机器上配置流媒体服务器

我已经将制作好的流媒体服务器的docker镜像上传到我的docker hub中(shixiaohan/maxinginx:7)。所以只需要两条指令就可以在一台新机器上(无论是linux还是windows都可以,docker是跨平台的,不限制)构建一个新的流媒体服务器。

 

在ubuntu平台上,windows上也可以,docker是跨平台的。

(apt-get update)

apt-get install docker     (Ubuntu上安装docker)

(apt install docker.io) (为可能要进行的步骤,如果前面一步失败)

docker pull shixiaohan/maxinginx:7    (下载流媒体服务器镜像,仅几十M)

docker run shixiaohan/maxinginx:7 /home/nginx5.sh    (运行启动流媒体服务器)     

 

容器停止命令:docker stop  ******(容器的对应的数字,由于没有进入容器终端所以在宿主机新打开一个终端通过docker ps查看,查看的前提是root登录,sudo su)

当然也不用刻意去停止,直接关机也可以,但我不建议这么做。

 

直播系统中其他元件的改动

针对原直播系统,修改如下:

路由器地址改为真正的网关地址:10.68.240.65

在路由器上添加一条静态路由   172.17.0.0   255.255.0.0  10.68.240.67

Live的推流地址和手机的访问地址改为rtmp://172.17.0.2/dash/ozo002

 

修改后的直播图

基于docker的OZO流媒体服务器的使用和搭建方法

流媒体docker镜像制作上传教程

1,安装docker

apt-get update

apt-get install docker

apt install docker.io

2,docker pull ubuntu

3,docker  run  –v (宿主机挂载文件夹):(docker挂载文件夹) –it  ubuntu  /bin/bash(在ubuntu的镜像上进一步构建,-it可以进入里面的这个终端界面进行命令行控制)例如:docker run -v /home/maxi/1:/data –it ubuntu

4,根据之前教程走一遍(不需要修改IP地址),这里面有两点不同,1是挂载,可以将文件传送到容器里面。这在一开始启动容器的时候就需要 docker run –v  ,然后把一些文件(nginx.conf)复制移到容器里面,2是同时还要自己新建一个nginx的启动脚本

vi nginx5.sh(这就等同于新建了)

然后进去后输入如下内容

#!/bin/bash

service nginx start  (启动nginx)

tail -f /dev/null (在shell脚本最后加上一条永远完成不了的命令,让容器一直运行不会退出)

 

上面一小段是说明,下面是进入容器终端后的具体步骤:

# sudo -i (as root)

apt-get install build-essential libpcre3 libpcre3-dev libssl-dev unzip

cd  /opt

wget  http://nginx.org/download/nginx-1.10.3.tar.gz

wget  https://github.com/arut/nginx-rtmp-module/archive/master.zip

tar  -zxvf  nginx-1.10.3.tar.gz

unzip  master.zip

cd  nginx-1.10.3

./configure --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx-rtmp-module-master

make

make  install

wget  https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx

chmod  +x  /etc/init.d/nginx

update-rc.d  nginx  defaults

service  nginx  start

#Open a web browser on a computer in the same network, enter the IP address of NUC server, you should see Nginx Homepage

service nginx stop

# nginx is installed at /usr/local/nginx

# create directories

mkdir  -p  /var/www/hls

mkdir  -p  /var/www/dash

chmod  -R  777 /var/www

# backup and replace Nginx conf file

cd  /usr/local/nginx/conf

mv  nginx.conf nginx.conf.bak

# upload attached nginx.conf to /usr/local/nginx/conf

#通过容器挂载的方式将nginx.conf这个文件从本地复制到容器的文件夹,再移动到/usr/local/nginx/conf这个文件夹中

service nginx start

# open the web browser, make sure you can access [NUC IP]/dash or [NUC IP]/hls

# configure OZO Live RTMP output to be RTMP://[UNC IP]/dash/test_TB

# check on web browser, make sure there are .mpd file and other files generated under [NUC IP]/dash

# prepare a .playlist file on Gear VR+S7 for latest OZO Player, the content is RTMP://[UNC IP]/dash/test_TB.mpd

#Play it and enjoy!!!

# Make sure to put some gain on OZO Live audio

# you can also try hls, the same, change OZO Live RTMP output to be RTMP://[UNC IP]/hls/test_TB, prepare a .playlist file on Gear VR+S7 for latest OZO Player, the content is http://[UNC IP]/hls/test_TB.m3u8

#需要在容器的/home文件夹下新建一个nginx启动脚本

vi nginx5.sh(这就等同于新建了)

然后进去后输入如下内容

#!/bin/bash

service nginx start

tail -f /dev/null

然后保存退出(wq)即可

弄完之后输入exit退出容器。

5,docker  commit  **********  shixiaohan/maxinginx:7(**********是容器号码,容器终端显示例如[email protected],就是@后面那一串数字,用docker ps查看也是一样的) 

6,docker push shixiaohan/maxinginx:7   (这个得保证自己已经登录过了,先docker login,同时自己账号是什么就写自己账号地址而不是shixiaohan)至此流媒体服务器镜像构建完成并成功上传到docker hub上可以供任何人下载使用。

 

 

 

Docker镜像一运行,本地是可以直接ping通docker内部的地址的(一般默认为172.17.0.2),docker 内部也是可以直接ping通本机的IP的,根本不需要额外设置。这个需要注意,开始在这上面折腾很长时间最后发现根本没有必要。