PingOS 在Ubuntu20.04 环境下使用docker 编译镜像并部署

1. PingOS简介

PingOS依赖NGINX构建,并且继承arutAlexWoo的nginx-rtmp-module模块。修复arut和AlexWoo版本存在的部分问题外,PingOS在编码和直播协议以及其他方面做了多项功能扩展。

GitHub地址:https://github.com/pingostack/pingos

用户指南:快速开始 - PingOS

2. 为什么写这篇博客

本人按照GitHub上给的docker镜像编译部署方式(https://github.com/pingostack/pingos/blob/master/docker/README.md)没有成功,主要存在路径错误问题、编译过程中下载依赖失败等问题。

摸索了一下,解决了镜像编译问题,写此篇博客以记录和分享。

3. 安装docker

已安装docker请跳过该步骤。

安装依赖:

sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

导入 GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

添加源:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

安装最新版docker:

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

安装完成后docker服务会自动启动,可采用如下方式查看:

sudo systemctl status docker

此时得到如下内容,说明docker服务已运行:

● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset>
     Active: active (running) since Wed 2022-03-23 18:21:57 PDT; 51s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 1121 (dockerd)
      Tasks: 16
     Memory: 115.2M
     CGroup: /system.slice/docker.service
             └─1121 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/cont>

...

4. 配置docker

已配置docker请跳过该步骤。

4.1 设置普通用户权限运行docker

默认情况下,需要sudo权限运行docker,普通用户权限运行docker会报权限错误。此时若想用普通用户权限运行docker,可进行如下操作设置普通用户权限运行docker。

添加当前用户到docker用户组:

sudo usermod -aG docker $USER

退出 shell 重新登录,即可不使用 sudo 来运行 docker 相关操作。

4.2 更改docker镜像源为国内源

配置国内源可提高镜像拉取速度。

修改 /etc/docker/daemon.json (如果该文件不存在,则创建):

sudo gedit /etc/docker/daemon.json

/etc/docker/daemon.json修改为如下内容(网易源,自签证书):

{
	"registry-mirrors": [
		"https://hub-mirror.c.163.com"
	]
}
{
	"insecure-registries": [
		"10.0.17.100"
	]
}

重启docker进程:

sudo systemctl restart docker

查看是否生效:

docker info | grep -E "Registry|http"

输出如下内容:

Registry: https://index.docker.io/v1/
 Registry Mirrors:
  https://hub-mirror.c.163.com/

helloworld测试一下:

docker run hello-world

输出如下信息则成功:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

5. 编译PingOS docker镜像

5.1 源码下载

从GitHub下载源码:

git clone https://github.com/pingostack/pingos.git

5.2 解决编译镜像时下载依赖失败的问题

 在pingos/docker目录下创建sources.list文件:

gedit pingos/docker/sources.list

 修改sources.list文件内容如下(阿里云的源):

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse

解决 Failed to fetch XXX 问题,为DNS配置有问题(参考链接),编译时报错如下所示:

E: Failed to fetch http://mirrors.aliyun.com/ubuntu/pool/main/n/npth/libnpth0_1.6-1_amd64.deb  Undetermined Error [IP: 110.188.27.187 80]
E: Aborting install.
ERROR: Service 'pingos' failed to build: The command '/bin/sh -c apt update && apt-get upgrade -y &&     apt-get install -y wget build-essential libtool libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev --fix-missing git gcc' returned a non-zero code: 100

 在pingos/docker目录下创建resolv.conf文件:

gedit docker/resolv.conf

 修改resolv.conf文件内容如下(添加阿里DNS):

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
nameserver 223.5.5.5  
nameserver 223.6.6.6
options edns0 trust-ad
search localdomain

修改pingos/docker目录下的Dockerfile

gedit pingos/docker/Dockerfile

修改后Dockerfile文件内容如下:

FROM ubuntu:20.04 AS build
USER root
WORKDIR /home/
ENV DEBIAN_FRONTEND=noninteractive

COPY . /home/

RUN cp /home/docker/sources.list /etc/apt
RUN cp /home/docker/resolv.conf /etc

RUN \
    apt update  && \
    apt-get install -y wget build-essential libtool libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev --fix-missing git gcc
    
RUN \
    cd /home && \
    chmod +x ./release.sh && \
    ./release.sh -ir

RUN cp -rf /home/docker/conf/ /usr/local/pingos/
RUN cp -r /home/docker/cert/ /cert/

FROM ubuntu:20.04 AS prod

ARG RUN_PATH=/usr/local/pingos
ARG BUILD_PATH=/home

WORKDIR ${RUN_PATH}

ENV DEBIAN_FRONTEND=noninteractive

COPY . /home/

RUN cp /home/docker/sources.list /etc/apt
RUN cp /home/docker/resolv.conf /etc

RUN apt update  && \
    apt-get install -y supervisor ffmpeg openssl libpcre3 libpcre3-dev zlib1g-dev libssl-dev
#RUN rm -f /etc/supervisor/supervisord.conf
ENV PATH=${PATH}:${RUN_PATH}/sbin
COPY --from=build ${RUN_PATH}/ ${RUN_PATH}/
COPY --from=build ${BUILD_PATH}/docker/cert/ /cert
COPY --from=build ${BUILD_PATH}/docker/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
COPY --from=build ${BUILD_PATH}/docker/supervisor/pingos.conf /etc/supervisor/conf.d/pingos.conf
COPY --from=build ${BUILD_PATH}/docker/pingos-entrypoint.sh /usr/local/bin/pingos-entrypoint.sh

RUN mkdir -p /data/record && mkdir -p /usr/local/pingos/conf/conf.d/location && mkdir -p /usr/local/pingos/conf/conf.d/server
RUN chmod 777 /usr/local/bin/pingos-entrypoint.sh

CMD [ "/usr/bin/supervisord" ]

根据需求决定是否修改 nginx.conf,更改方式参考用户手册。此本文处未修改。

5.3 解决编译镜像时路径错误的问题

拷贝pingos/docker目录下的内容到pingos目录

cp -r pingos/docker/. pingos/

5.4 编译镜像

切换到pingos目录

cd pingos/

 切换到root权限

sudo su

给run.sh脚本添加权限

chmod +x run.sh

编译镜像

./run.sh up -d

然后就是漫长的等待。。。
 

编译成功会得到如下内容:

...
Successfully built ba5631519759
Successfully tagged pingos:latest
WARNING: Image for service pingos was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating pingos_pingos_1 ... done

6. 运行PingOS

docker container run pingos

输出如下内容:

2022-03-24 04:04:50,836 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
2022-03-24 04:04:50,836 INFO Included extra file "/etc/supervisor/conf.d/pingos.conf" during parsing
2022-03-24 04:04:50,869 INFO RPC interface 'supervisor' initialized
2022-03-24 04:04:50,869 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2022-03-24 04:04:50,870 INFO supervisord started with pid 1
2022-03-24 04:04:51,878 INFO spawned: 'nginx' with pid 8
2022-03-24 04:04:52,187 INFO exited: nginx (exit status 0; not expected)
2022-03-24 04:04:53,364 INFO spawned: 'nginx' with pid 15
2022-03-24 04:04:54,573 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
...

7. 离线部署

# 在本机上导出镜像
$ docker save pingos:latest -o pingos.latest.tar
# 上传本文件夹到服务器上并导入镜像
$ docker load -i pingos.latest.tar
# 默认以同目录docker-compose.yml文件作为配置文件启动容器
# 使用docker/compose容器启动容器
$ ./run.sh up -d

至此编译部署完毕,尽情享受PingOS推流服务。

【参考链接】

1. PingOS GitHub: https://github.com/pingostack/pingos
2. PingOS README文档: https://github.com/pingostack/pingos#readme

3. PingOS docker README文档: https://github.com/pingostack/pingos/blob/master/docker/README.md

4. PingOS 用户手册:快速开始 - PingOS

5. Ubuntu docker 安装教程:Ubuntu 20.04 Docker 安装并配置 - YahuiAn - 博客园

6. Failed to fetch问题处理: Ubuntu出现E: Failed to fetch问题解决_狂小虎的博客-CSDN博客

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值