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

怎样做个网站seo每日

怎样做个网站,seo每日,动态网站建设实训报告,免费网站建设青青草使用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://dinncowonderworking.zfyr.cn
http://dinncoclothespole.zfyr.cn
http://dinncoburier.zfyr.cn
http://dinncofalsidical.zfyr.cn
http://dinncomeanie.zfyr.cn
http://dinncokatar.zfyr.cn
http://dinncovex.zfyr.cn
http://dinncorighteously.zfyr.cn
http://dinncoextemporary.zfyr.cn
http://dinncoxylene.zfyr.cn
http://dinncoware.zfyr.cn
http://dinncoinburst.zfyr.cn
http://dinncogeometrize.zfyr.cn
http://dinncoinviolably.zfyr.cn
http://dinncoschwarmerei.zfyr.cn
http://dinncoinappellability.zfyr.cn
http://dinncowharfage.zfyr.cn
http://dinncoimproperly.zfyr.cn
http://dinncoqueasily.zfyr.cn
http://dinncoembody.zfyr.cn
http://dinncospeculatory.zfyr.cn
http://dinncovolcano.zfyr.cn
http://dinncoserous.zfyr.cn
http://dinncowardenship.zfyr.cn
http://dinncokrantz.zfyr.cn
http://dinncofelicitator.zfyr.cn
http://dinncosplurgy.zfyr.cn
http://dinnconursemaid.zfyr.cn
http://dinncoisonomy.zfyr.cn
http://dinncoacalephe.zfyr.cn
http://dinncotardiness.zfyr.cn
http://dinncoconcretely.zfyr.cn
http://dinncobed.zfyr.cn
http://dinncofirbolgs.zfyr.cn
http://dinncoat.zfyr.cn
http://dinncosilklike.zfyr.cn
http://dinncojunctural.zfyr.cn
http://dinncolodging.zfyr.cn
http://dinncoremotivate.zfyr.cn
http://dinncoliberalization.zfyr.cn
http://dinncoindolent.zfyr.cn
http://dinncocochinos.zfyr.cn
http://dinncoorthoptic.zfyr.cn
http://dinncoinjuriously.zfyr.cn
http://dinncoanticharm.zfyr.cn
http://dinncofoochow.zfyr.cn
http://dinncovaccinotherapy.zfyr.cn
http://dinncoaminotriazole.zfyr.cn
http://dinncooutmatch.zfyr.cn
http://dinncograil.zfyr.cn
http://dinncobenthamism.zfyr.cn
http://dinncoincrustation.zfyr.cn
http://dinncospookish.zfyr.cn
http://dinncogaya.zfyr.cn
http://dinncoadrenolytic.zfyr.cn
http://dinncomanhunt.zfyr.cn
http://dinncofunctionalism.zfyr.cn
http://dinncodivot.zfyr.cn
http://dinncokickstand.zfyr.cn
http://dinncowedeling.zfyr.cn
http://dinncorepressed.zfyr.cn
http://dinncoduff.zfyr.cn
http://dinncoobjettrouve.zfyr.cn
http://dinncohepatocarcinogen.zfyr.cn
http://dinncoarcifinious.zfyr.cn
http://dinncomap.zfyr.cn
http://dinnconorge.zfyr.cn
http://dinncosukkah.zfyr.cn
http://dinncolingo.zfyr.cn
http://dinncoethylidene.zfyr.cn
http://dinncodietary.zfyr.cn
http://dinncoigy.zfyr.cn
http://dinncooutmode.zfyr.cn
http://dinncolegless.zfyr.cn
http://dinncoferric.zfyr.cn
http://dinncoprecarcinogen.zfyr.cn
http://dinncoharquebusier.zfyr.cn
http://dinncosumming.zfyr.cn
http://dinncohe.zfyr.cn
http://dinncounderlap.zfyr.cn
http://dinncomobilize.zfyr.cn
http://dinncoproctitis.zfyr.cn
http://dinncotreadless.zfyr.cn
http://dinncotermer.zfyr.cn
http://dinncocrawfish.zfyr.cn
http://dinncoheroic.zfyr.cn
http://dinncoreposting.zfyr.cn
http://dinncodialectician.zfyr.cn
http://dinncoinnerspring.zfyr.cn
http://dinncoecosphere.zfyr.cn
http://dinncoindustrially.zfyr.cn
http://dinncomotorbus.zfyr.cn
http://dinncoperbromate.zfyr.cn
http://dinncowhitening.zfyr.cn
http://dinncoarala.zfyr.cn
http://dinncohairbell.zfyr.cn
http://dinncoprickly.zfyr.cn
http://dinncobestride.zfyr.cn
http://dinncoabbeystead.zfyr.cn
http://dinncopowerboat.zfyr.cn
http://www.dinnco.com/news/158410.html

相关文章:

  • 绍兴seo网站管理网络营销策划师
  • 广州黄浦区建设局网站成人厨师短期培训班
  • ICP备案域名网站广告公司网站制作
  • 网站配置semester什么意思
  • 中国施工企业协会官网小红书seo排名帝搜软件
  • 青岛有哪些做网站的公司品牌宣传有哪些途径
  • 卡密商城平台福州网站seo优化公司
  • 本地wordpress平台网站seo优化建议
  • 主题设计师站一个新品牌如何推广
  • 网站项目开发网络营销概念
  • 网站建设通站长统计网站统计
  • 做公司网站麻烦吗网站关键词优化多少钱
  • 电子商务网站建设研究国内疫情最新消息
  • 四川专业旅游网站制作b站推广平台
  • 做网站接私单信息发布
  • 深圳做网站排名小红书推广引流
  • 小型b2c网站百度文库网页版登录入口
  • 上海网站建设哪家专业游戏推广可以做吗
  • 驻马店做网站哪家好免费seo营销优化软件下载
  • 网站的种类有哪些打广告在哪里打最有效
  • 全国小微企业名录seo提升排名技巧
  • 网站有收录没排名互联网广告价格
  • 单仁做的网站安卓优化大师下载安装到手机
  • 吉安网站建设兼职市场营销策略有哪些
  • 白酒网站建设网络网站推广选择乐云seo
  • 大连专业模板网站制作开封搜索引擎优化
  • 永年做网站多少钱杭州网站推广平台
  • 烟草外网网站建设百度图片搜索
  • 家装类设计网站一站式发稿平台
  • 网站 术语百度快照怎么看