系统:CentOS7.2(阿里云ESC)

1。python版本,使用的是默认的python2.7(或者先安装python3)

2。安装nginx,yum install -y nginx

3。安装virtualenv,yum install -y python-virtualenv

4。创建虚拟环境,virtualenv venv (venv为虚拟环境名称,可自行加上目录)

5。激活虚拟环境,source venv /bin/activate

6。在虚拟环境中安装gunicorn和flask,(venv) $ pipinstall gunicorn (venv) $ pip install flask

7。在目录/var/www中创建文件flask.py

from flask import Flask

def create_app():
app = Flask(__name__)
return app app = create_app() if __name__ == '__main__':
app.run() @app.route('/')
def index():
return '<html>Hello world!</html>' 8。配置nginx,vim /etc/nginx/nginx.conf
头部:user root(ubuntu)
记得设置权限chmod 777
添加配置 server{
listen 80;
server_name 域名;
root         /root/www/xxxx; location / {
proxy_pass http://域名:801;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}
} service nginx restart
9。启动gunicorn(在py目录)
gunicorn -w 4 -b 0.0.0.0:801 flask:app

3.安装supervisor 
这里退出py3的虚拟环境,直接使用自带的py2.75的来安装

pip install supervisor
echo_supervisord_conf > /etc/supervisord.conf #重定向配置文件到制定目录

(chmod+x 是给以执行权限 绿色 -x未去除权限 灰色)
chmod +x /etc/supervisord.conf
改一下最后的配置文件导入

[include]
files = /etc/supervisor/*.conf
在/etc/supervisor创建flask.conf

[program:wsgi]
directory = /usr/local/flask_cmdb ;命令执行目录
command = /usr/local/ENV_CMDB/bin/python3 /usr/local/ENV_CMDB/bin/gunicorn -w 4 -b 127.0.0.1:5000 manager:app
autostart = true ;默认随supervisord自动启动,默认true
startsecs = 5 ; 启动 5 秒后没有异常退出,就当作已经正常启动了
autorestart = true ;程序异常退出后自动重启
startretries = 3 ; 启动失败自动重试次数,默认是 3
redirect_stderr = true ;重定向错误
stdout_logfile = /var/log/flask_supervisor.log ;这里日志需要手动创建否则无法启动

这里重点的地方是command,运行gunicorn 是在virtualenv的虚拟目录下执行
---------------------

查看gunicorn 进程
pstree -ap|grep gunicorn
结束主进程
kill -9 pid 如果需要gevent可以安装gevent携程

  

Pycharm生成requirement.txt

生成requirement文件:pip freeze > requirements.txt

根据requirement文件安装依赖库:pip install -r requirement.txt

Supervisor重新加载配置启动新的进程

一、添加好配置文件后

二、更新新的配置到supervisord

supervisorctl update

三、重新启动配置中的所有程序

supervisorctl reload

四、启动某个进程(program_name=你配置中写的程序名称)

supervisorctl start program_name

五、查看正在守候的进程

supervisorctl

六、停止某一进程 (program_name=你配置中写的程序名称)

pervisorctl stop program_name

七、重启某一进程 (program_name=你配置中写的程序名称)

supervisorctl restart program_name

八、停止全部进程

supervisorctl stop all

注意:显示用stop停止掉的进程,用reload或者update都不会自动重启。

https://www.jianshu.com/p/f8735b039c67?from=groupmessage

https://www.jianshu.com/p/40caabd91827

https://blog.csdn.net/qq850482461/article/details/78893710

最新文章

  1. jquery高级函数
  2. jmeter 如何将上一个请求的结果作为下一个请求的参数——使用正则提取器
  3. Effective C++ 之 Item 1: 视C++为一个语言联邦
  4. 阿里云maven加速和docker加速
  5. Error in Android Studio - &quot;Default Activity Not Found&quot;
  6. 12 高性能I/O框架库Libevent
  7. [转]Struts标签库详解
  8. HDU 3974 Assign the task 暴力/线段树
  9. php Mysql 和Mysqli数据库函数整合
  10. [原创]浅谈NT下Ring3无驱进入Ring0的方法
  11. mysql如何开启远程连接
  12. tomcat 重启进程
  13. mui开发app之自定义事件以更新其他页内容
  14. Mysql update in报错 [Err] 1093 - You can&#39;t specify target table &#39;company_info&#39; for update in FROM clause
  15. 基于Ubuntu的LNMP环境搭建
  16. js操作中要去注意的一些问题
  17. Python的优势及应用领域
  18. numpy学习总结(重点讲解索引方式)
  19. centos/RHEL 7.6 使用yum安装php7.3(方便wordpress的php7.3需求,并解决了libphp7.so缺失问题)
  20. E - Emptying the Baltic Kattis - emptyingbaltic (dijkstra堆优化)

热门文章

  1. JavaScript Patterns 2.7 Avoiding Implied Typecasting
  2. .net连接MySQL数据库的方案与实例演示
  3. golang函数——可以为类型(包括内置数据类型)定义函数,类似类方法,同时支持多返回值
  4. [模板]平衡树splay
  5. linux 条件测试 ******
  6. 56. EditorGridPanel和渲染器renderer的使用
  7. Java命名规范(新手宝典)
  8. 什么是mycat?
  9. jQuery自适应倒计时插件
  10. sublime text3配置插件