python flask 生产环境部署,基于gunicorn(centos 6.5)

发布时间 2023-12-18 19:19:49作者: 峡谷风

1.安装gunicorn,部分生产服务器会存在多个pip版本,一般用pip和pip3区分,本文中用pip

pip install gunicorn

2.启动程序

cd /usr/app
gunicorn --workers 2 -b 0.0.0.0:5056 app:app

 因为我的项目文件名称为app.py所以为app:如果是其他的文件名称注意修改,验证项目正常后继续如下操作

3.配置gunicorn配置文件

查看centos版本

cat /etc/redhat-release
# centos 6.5 
cd /etc/init.d
vim autostart.sh

4.新建一个配置文件autostart.sh

#!/bin/bash
chdir /usr/app gunicorn --workers 2 -b 0.0.0.0:5056 app:app

5.命令:sh autostart.sh

看下是否可以正常运行程序

6.修改权限chmod 775 autostart.sh

vim /etc/rc.d/rc.local

7.编辑/etc/rc.d/rc.local文件,在末尾增加如下内容

/usr/app/autostart.sh