1 pip install gunicorn
1 [program:xxx-server] # 项目名称 2 command=/usr/local/python3/bin/gunicorn -c gun.py manage:app # 前面是gunicorn的绝对路径,后面的gun.py是gunicorn的配置文件, manage是你的flask项目启动文件名称 3 directory=/www/xxx-server # flask项目存放路径 4 autorestart=true 5 stdout_logfile=/www/server/log/mock-server.out.log # 日志 6 redirect_stderr=true 7 user=root 8 priority=999
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # @Time : 2019/11/19 14:24 4 # @Author : Weiqiang.long 5 # @Site : 6 # @File : gun.py 7 # @Software: PyCharm 8 # @Description: 9 # import requests 10 import os 11 import platform 12 import gevent.monkey 13 import multiprocessing 14 15 16 gevent.monkey.patch_all() 17 debug = True 18 loglevel = 'deubg' 19 # 服务地址(adderes:port) 20 bind = '0.0.0.0:8090' 21 22 23 if platform.system() == 'Windows': 24 # win机器路径 25 log_path = os.path.join(os.path.dirname(__file__), 'log') 26 else: 27 # 服务器路径 28 log_path = '/log' 29 30 31 # print(log_path) 32 pidfile = log_path + '/gunicorn.pid' 33 logfile = log_path + '/debug.log' 34 35 36 # 启动的进程数(获取服务器的cpu核心数*2+1) 37 workers = multiprocessing.cpu_count() * 2 +1 38 worker_class = 'gunicorn.workers.ggevent.GeventWorker' 39 40 41 threads = 20 42 preload_app = True 43 reload = True 44 45 46 x_forwarded_for_header = 'X-FORWARDED-FOR'
1 # 启动全部服务 2 sudo supervisorctl start all 3 4 5 # 启动单个服务 6 sudo supervisorctl start 服务名称 7 8 9 # 中止全部服务 10 sudo supervisorctl stop all 11 12 13 # 重启全部服务 14 sudo supervisorctl restart all
参考来源:html