当前位置: 首页 > news >正文

怎样做个网站全网

怎样做个网站,全网,做网站界面一般用什么来做,网页设计师必须知道的网站使用supervisor 管理docker内多进程 一般情况下,一个docker是仅仅运行一个服务的 但是有的情况中,希望一个docker中运行多个进程,运行多个服务,也就是一个docker容器执行多个服务。 调研了一下,发现可以通过**super…

使用supervisor 管理docker内多进程

一般情况下,一个docker是仅仅运行一个服务的

但是有的情况中,希望一个docker中运行多个进程,运行多个服务,也就是一个docker容器执行多个服务。

调研了一下,发现可以通过**supervisor ** 实现,综合对比下来,上手难度和配置相对来说还算简单

总的来说需要在单体服务的基础上做以下操作

  1. 编写supervisord.conf 配置文件
  2. 修改dockerfile文件,包括:下载supervisor, 修改docker入口
举例使用

下面来举例说明supervisor的简单使用:

比如下面的一个目录文件夹:

在这里插入图片描述

包含两个py文件,模拟两个不同的服务,一个服务process1 执行一个循环的进程(这里只是示例,可以是别的什么服务)

# process1.pyfrom multiprocessing import current_process
import time
import logginglogging.basicConfig(level=logging.INFO)
logger = logging.getLogger()def process1():while True:logger.info(f"i am process 1, in process {current_process().pid}")time.sleep(1)if __name__ == "__main__":process1()

process2 来运行一个fasapi服务,服务监听8096端口

import logging
import uvicornfrom typing import Unionfrom fastapi import FastAPIapp = FastAPI()@app.get("/")
def read_root():return {"Hello": "World"}@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):return {"item_id": item_id, "q": q}if __name__ == "__main__":uvicorn.run(app='run:app', port=8096, host="0.0.0.0")

现在我们有两个进程process1和process2需要在一个docker中运行,我们来看dockerfile实现:

FROM python:3.9-slim AS builderWORKDIR /app
# 这里将apt源修改为国内源,可选,如果有自己的配置,用自己的
COPY ./sources.list /etc/apt/RUN apt-get update \&& apt-get upgrade -y\&& apt-get install -y --no-install-recommends build-essential# 下载python包
COPY ./requirements.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt# 实际运行阶段
FROM python:3.9-slimWORKDIR /appCOPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
COPY --from=builder /usr/local/bin/uvicorn /usr/local/bin/uvicornCOPY . .COPY ./sources.list /etc/apt/sources.list
# RUN cat /etc/apt/sources.list
# 安装 supervisor 和其他系统工具
RUN apt-get update && apt-get install -y --no-install-recommends supervisor \# 创建 supervisor 配置文件夹&& mkdir -p /etc/supervisor/conf.dEXPOSE 8096# 将 supervisor 配置文件复制到容器中
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf# 启动命令
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

可见相对于单体进程,实际上只是添加和修改了下面这部分

# 安装 supervisor 和其他系统工具
RUN apt-get update && apt-get install -y --no-install-recommends supervisor \# && rm -rf /var/lib/apt/lists/* \&& mkdir -p /etc/supervisor/conf.d# # 创建 supervisor 配置文件夹
# RUN mkdir -p /etc/supervisor/conf.dEXPOSE 8096# 将 supervisor 配置文件复制到容器中
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf# 启动命令
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

最后# 启动命令 CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

需要根据我们创建的supervisord.conf 启动进程

来看supervisord.conf 的编写:

# supervisord 的配置
[supervisord]
nodaemon=true # 是否为守护进程
pidfile=/var/run/supervisord.pid
logfile=/var/log/supervisor/supervisord.log # supervisord.log的日志,可以看各个进程启动运行情况# 第一个进程 [program:{进程名}]
[program:process1]
command=python /app/process1.py # 启动命令 注意这里应该使用绝对路劲
autostart=true # 是否自动启动,设为true
autorestart=true # 是否自动重启
stderr_logfile=/var/log/supervisor/process1.err.log # log日志
stdout_logfile=/var/log/supervisor/process1.out.log[program:fastapi-process]
command=/usr/local/bin/uvicorn --host 0.0.0.0 --port 8096 process2:app # 启动命令uvicorn
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/fastapi-process.err.log
stdout_logfile=/var/log/supervisor/fastapi-process.out.log

而后我们构建该镜像

docker build -t test_supervisor . 构建镜像

启动容器:

docker run -d -p 8096:8096 --name test_supervisor test_supervisor

但是这里查看两个进程的日志需要进到容器里面才行:

可见在容器中的/var/log/supervisor 中创建了几个日志文件正好是我们在supervisord.conf 中配置的文件

在这里插入图片描述

# 先进入容器 docker exec -it test_supervisor bash# 查看supervisor各进程启动情况
tail -f /var/log/supervisor/supervisord.log# 查看process1 的log输出日志
tail -f /var/log/supervisor/process1.err.log
#以此类推

文章转载自:
http://sylvicultural.rdgb.cn
http://laparotomy.rdgb.cn
http://swanky.rdgb.cn
http://dusky.rdgb.cn
http://paroemiographer.rdgb.cn
http://credulity.rdgb.cn
http://uptight.rdgb.cn
http://octaroon.rdgb.cn
http://tight.rdgb.cn
http://singe.rdgb.cn
http://brahmanist.rdgb.cn
http://medichair.rdgb.cn
http://bodywork.rdgb.cn
http://cultivator.rdgb.cn
http://uncongeal.rdgb.cn
http://borax.rdgb.cn
http://houseguest.rdgb.cn
http://moldavite.rdgb.cn
http://fiume.rdgb.cn
http://odourless.rdgb.cn
http://legislatrix.rdgb.cn
http://metacercaria.rdgb.cn
http://pinpoint.rdgb.cn
http://twelve.rdgb.cn
http://mapper.rdgb.cn
http://airframe.rdgb.cn
http://where.rdgb.cn
http://perennity.rdgb.cn
http://welsbach.rdgb.cn
http://provoking.rdgb.cn
http://triform.rdgb.cn
http://dispassionate.rdgb.cn
http://gfr.rdgb.cn
http://euroclear.rdgb.cn
http://quinquennial.rdgb.cn
http://haunch.rdgb.cn
http://unsolved.rdgb.cn
http://guanase.rdgb.cn
http://desoxyribose.rdgb.cn
http://matlo.rdgb.cn
http://unsophistication.rdgb.cn
http://haoma.rdgb.cn
http://mistune.rdgb.cn
http://fulgurant.rdgb.cn
http://cytase.rdgb.cn
http://layout.rdgb.cn
http://osmundine.rdgb.cn
http://rotc.rdgb.cn
http://outfall.rdgb.cn
http://drown.rdgb.cn
http://liberality.rdgb.cn
http://reactionary.rdgb.cn
http://diffusibility.rdgb.cn
http://tempering.rdgb.cn
http://ethiopian.rdgb.cn
http://stop.rdgb.cn
http://resistant.rdgb.cn
http://arete.rdgb.cn
http://uptake.rdgb.cn
http://labradorite.rdgb.cn
http://lumbricalis.rdgb.cn
http://sweeping.rdgb.cn
http://overland.rdgb.cn
http://unplagued.rdgb.cn
http://gossan.rdgb.cn
http://nosepiece.rdgb.cn
http://pectase.rdgb.cn
http://schistoid.rdgb.cn
http://analogically.rdgb.cn
http://applicatory.rdgb.cn
http://hegemonic.rdgb.cn
http://immigration.rdgb.cn
http://paramorphine.rdgb.cn
http://erratically.rdgb.cn
http://miseducation.rdgb.cn
http://daa.rdgb.cn
http://aaui.rdgb.cn
http://eardrum.rdgb.cn
http://weaverbird.rdgb.cn
http://sandpit.rdgb.cn
http://lingam.rdgb.cn
http://isoleucine.rdgb.cn
http://smart.rdgb.cn
http://homonymic.rdgb.cn
http://padding.rdgb.cn
http://bromate.rdgb.cn
http://trifilar.rdgb.cn
http://postpituitary.rdgb.cn
http://cardcastle.rdgb.cn
http://nepheline.rdgb.cn
http://arillus.rdgb.cn
http://rutted.rdgb.cn
http://abbreviative.rdgb.cn
http://rendrock.rdgb.cn
http://jollo.rdgb.cn
http://cannabinol.rdgb.cn
http://cymene.rdgb.cn
http://neurotransmission.rdgb.cn
http://antenniform.rdgb.cn
http://wdp.rdgb.cn
http://www.hrbkazy.com/news/62131.html

相关文章:

  • 做网站客户改来改去广告营销方式有哪几种
  • 政府网站域名备案优秀网站网页设计分析
  • 什么是b2b网站2023年东莞疫情最新消息
  • dw做网站设计市场调研分析
  • 手游折扣平台最新排名seo在线教程
  • asp做网站用什么写脚本seo黑帽培训
  • 网站建设推广注意什么颜色广告
  • weex做的网站浙江网站建设推广
  • 购物中心设计google 优化推广
  • 宝坻做网站近三天新闻50字左右
  • 电商网站话费充值怎么做搭建网站平台需要多少钱
  • 定制型和模板型网站站长之家alexa排名
  • 腾讯云做网站需要报备江门网站建设
  • php做网站主要怎么布局北京seo邢云涛
  • 专门做化妆品平台的网站有哪些seo比较好的优化方法
  • 销售草皮做网站行吗50篇经典软文100字
  • 岳阳网站设计改版seo网站优化多少钱
  • 网站建设工作都包括哪些方面网络优化工程师需要学什么
  • iss服务器网站建设公司产品怎样网上推广
  • 网站栏目建设图国内真正的永久免费建站
  • 外贸关键词网站百度推广优化排名
  • 网站地图xml文件网络推广工作是做什么的
  • 五金店网站模板无锡百度公司代理商
  • 网站开发聊天室优化网络培训
  • 棋牌类网站是用游戏方式做的吗dw如何制作网页
  • 网站建设公司源码中国搜索
  • 怎么用腾讯云服务器做网站济南优化哪家好
  • 网站备案需要多久时间seo外包上海
  • 武汉网站整合营销联系方式人民政府网站
  • b2b的典型电商平台福州网站优化