qiangrx 2021-09-28 21:02 采纳率: 0%
浏览 117

Docker下使用gunicorn部署Django,gunicorn启动失败

error日志

[2021-09-28 20:41:48 +0800] [1766] [INFO] Worker exiting (pid: 1766)
[2021-09-28 12:41:48 +0000] [1791] [INFO] Booting worker with pid: 1791
[2021-09-28 20:41:48 +0800] [1765] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
    super().init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 142, in init_process
    self.run()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 195, in run
    self.notify()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 75, in notify
    self.tmp.notify()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/workertmp.py", line 46, in notify
    os.fchmod(self._tmp.fileno(), self.spinner)
FileNotFoundError: [Errno 2] No such file or directory

使用配置文件和直接命令行执行均出现此错误

gunicorn.config.py

# -*- coding: utf-8 -*-
import multiprocessing
from pathlib import Path

BASE_DIR = Path(__file__).resolve(strict=True).parent

debug = False

# ============================================================
# gunicorn要切换到的目的工作目录
# ============================================================

chdir = str(BASE_DIR)

# ============================================================
# server socket相关
# ============================================================

# 指定绑定的ip和端口
bind = "0.0.0.0:8080"

# 服务器中排队等待的最大连接数,建议值64-2048,超过2048时client连接会得到一个error
backlog = 2048

# ============================================================
# 调试相关
# ============================================================

# 当代码有修改时,自动重启workers,适用于开发环境
reload = False

# 以守护进程形式来运行Gunicorn进程,其实就是将这个服务放到后台去运行
daemon = False

# ============================================================
# worker进程相关
# ============================================================

# 用于处理工作的进程数
workers = multiprocessing.cpu_count() * 2 + 1

# worker进程的工作方式,有sync、eventlet、gevent、tornado、gthread, 默认是sync,
# django使用gevent容易造成阻塞, 使用gthread的方式好一些
worker_class = 'gthread'

# 指定每个工作进程开启的线程数
threads = multiprocessing.cpu_count() * 2

# 访问超时时间
timeout = 30

# 接收到restart信号后,worker可以在graceful_timeout时间内,继续处理完当前requests
graceful_timeout = 60

# server端保持连接时间
keepalive = 30

# ============================================================
# 日志相关
# ============================================================

"""日志文件格式,其每个选项的含义如下:
h          remote address
l          '-'
u          currently '-', may be user name in future releases
t          date of the request
r          status line (e.g. ``GET / HTTP/1.1``)
s          status
b          response length or '-'
f          referer
a          user agent
T          request time in seconds
D          request time in microseconds
L          request time in decimal seconds
p          process ID
"""
access_log_format = '%(t)s %(h)s "%(r)s" %(s)s %(b)s "%(f)s" "%(L)s"'

errorlog = '/tmp/gunicorn.error.log' #发生错误时log的路径

accesslog = '/tmp/gunicorn.access.log' #正常时的log路径

# 错误日志输出等级,访问日志的输出等级无法设置
loglevel = "info"

# ============================================================
# 进程名相关
# ============================================================

# 设置进程名称,默认是gunicorn
proc_name = 'gunicorn_room'


进入docker容器直接命令行执行还是同样错误

gunicorn drf_admin.wsgi -b 0.0.0.0:8080

环境

Django==2.2.20
gunicorn==20.1.0

  • 写回答

2条回答 默认 最新

  • CSDN专家-黄老师 2021-09-28 21:46
    关注

    No such file or directory是找不到文件,你看看docker的文件怎样挂载

    评论

报告相同问题?

问题事件

  • 创建了问题 9月28日

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入