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

Centos7 中Gunicorn的安装配置

环境:

系统:centos7.9

python:3.11

django:5.2

1、安装

pip install gunicorn==23.0.0

2、写配置文件

# 创建Gunicorn配置文件
vim /home/igo/projects/igo-ecommerce/gunicorn.conf.py
```

Gunicorn配置示例:
```python
# gunicorn.conf.py
import multiprocessing

# 服务器配置
bind = "127.0.0.1:8000"
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = "sync"
worker_connections = 1000
max_requests = 1000
max_requests_jitter = 100
timeout = 30
keepalive = 2

# 日志配置
accesslog = "/home/igo/logs/gunicorn_access.log"
errorlog = "/home/igo/logs/gunicorn_error.log"
loglevel = "info"
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'

# 进程配置
daemon = False
pidfile = "/home/igo/logs/gunicorn.pid"
user = "igo"
group = "igo"
tmp_upload_dir = None

# 安全配置
limit_request_line = 4094
limit_request_fields = 100
limit_request_field_size = 8190

2、创建systemd服务

# 创建Gunicorn服务文件
sudo vim /etc/systemd/system/igo-gunicorn.service

服务配置示例:
```ini
[Unit]
Description=Gunicorn instance to serve IGO E-commerce
After=network.target mysql.service redis.service

[Service]
User=igo
Group=igo
WorkingDirectory=/home/igo/projects/igo-ecommerce
Environment="PATH=/home/igo/projects/igo_env/bin"
Environment="DJANGO_SETTINGS_MODULE=config.settings.production"
ExecStart=/home/igo/projects/igo_env/bin/gunicorn --config gunicorn.conf.py config.wsgi:application
ExecReload=/bin/kill -s HUP $MAINPID
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
```

3、启动服务

# 重新加载systemd配置
sudo systemctl daemon-reload

# 启动Gunicorn服务
sudo systemctl start igo-gunicorn
sudo systemctl enable igo-gunicorn

# 检查服务状态
sudo systemctl status igo-gunicorn

http://www.xdnf.cn/news/10377.html

相关文章:

  • Docker 在云环境中的部署:AWS/ECS 与 Azure/AKS 的实践对比
  • 自动驾驶系统研发系列—激光雷达感知延迟:自动驾驶安全的隐形隐患?
  • opencv使用经典bug
  • OD 算法题 B卷【文件目录大小】
  • 基于ssm+mysql的大创项目申报管理系统(含LW+PPT+源码+系统演示视频+安装说明)
  • 历年中山大学计算机保研上机真题
  • java swing 晃动鼠标改变背景颜色
  • PySide6 GUI 学习笔记——常用类及控件使用方法(标签控件QLabel)
  • Git初识Git安装
  • Spring Boot,两种配置文件
  • LeetCode 39.组合总和:回溯法与剪枝优化的完美结合
  • CCPC dongbei 2025 F
  • 组件化:软件工程化的基础
  • 接口安全SOAPOpenAPIRESTful分类特征导入项目联动检测
  • 树莓派3B小练习
  • IT技术文章汇总
  • 美业+智能体,解锁行业转化新密码(2/6)
  • 大白话 Seata 分布式事务浅析,详解TCC模式
  • 腾讯位置商业授权行政区划开发指南
  • Codeforces Round 1028 (Div. 2) B. Gellyfish and Baby‘s Breath
  • Nginx反向代理
  • NodeJS全栈开发面试题讲解——P12高性能场景题
  • Chorme如何对于youtube视频进行画中画背景播放?
  • 多模态AI的企业应用场景:视觉+语言模型的商业价值挖掘
  • 8天Python从入门到精通【itheima】-62~63
  • 结合源码分析Redis的内存回收和内存淘汰机制,LRU和LFU是如何进行计算的?
  • 深度学习|pytorch基本运算-乘除法和幂运算
  • 初识PS(Photoshop)
  • 【Oracle】安装单实例
  • 【Go】2、Go语言实战