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