环境
os: ubuntu20.04
python: python3.6
virtualenv
virtualenv 用来建立一个虚拟的 python 环境,一个专属于项目的 python 环境。
通过 pip 安装 virtualenv
python3.6 -m pip3 install virtualenv
创建一个独立的 Python 运行环境
python3.6 -m virtualenv venv
用 source 进入该环境
source venv/bin/activate
安装第三方包
python3.6 -m pip3 install -r requirements.txt
gunicorn
gunicorn 是一个 unix 上被广泛使用的高性能的 python wsgi unix http server
安装 gunicorn
python3.6 -m pip3 install gunicorn
gunicorn 启动 flask
gunicorn -w 4 -b 0.0.0.0:8000 main:app
参数解释:
-w INT,用于处理工作进程的数量,默认为 1
-b ADDRESS,ip 加端口,绑定运行的主机
以配置文件的方式启动
bind = '0.0.0.0:8000'
user = 'www'
workers = 2
threads = 4
worker_connections = 1000
backlog = 512
daemon = True
chdir = '/'
access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"'
loglevel = 'info'
worker_class = 'geventwebsocket.gunicorn.workers.GeventWebSocketWorker'
errorlog = chdir + '/logs/error.log'
accesslog = chdir + '/logs/access.log'
pidfile = chdir + '/logs/your.pid'
启动 gunicorn
gunicorn -c gunicorn.conf main:app
Comments NOTHING