前言
打造 flask + gunicron + nginx + Mysql 环境
nginx + Mysql 使用docker 快速部署
使用 supervisor 对 gunicron 做监控
环境:centos7 ,python3.7
flask 篇
flask 项目就不多赘述了。这里贴一下项目的目录,便于解释下面的命令参数。
运行python app.py
脚本,即可 web 访问,但无法并发访问,如果需要多线程开启 web 服务,实现并发访问,则需要额外一个工具进行封装,如gunicorn
这里安装 gunicron
gunicron 是用来 解析HTTP请求的网关服务
安装命令
pip install gunicron
# start gunicorn server 命令:
# gunicorn 命令要在 flask 项目所在的文件夹下运行
gunicorn app:app -c gunicorn.py
# gunicorn.py 内容
# 并行进程数量
workers = 3
# 每个进程的线程数
thread = 5
# #gunicorn监控的接口
bind = '0.0.0.0:5000'
# 进程pid文件
pidfile = 'gunicorn.pid' #gunicorn进程id,kill掉该文件的id,gunicorn就停止
logfile = './debug.log' #debug日志
errorlog = './error.log' #错误信息日志
loglevel = 'debug'
logfile = './debug.log' #debug日志
errorlog = './error.log' #错误信息日志
timeout = 90
#https://github.com/benoitc/gunicorn/issues/1194
keepalive = 75 # needs to be longer than the ELB idle timeout
worker_class = 'gevent'
docker 篇
docker 安装 mysql