gunicorn+supervisor
1.gunicorn
installation:
pip3 install gunicorn
Configuration:
In two ways: command and file, because more configuration items, so on the file, you can specify the configuration file at startup
command:
如:gunicorn –w 4 –b 0.0.0.0:5000 –c config.py manager:app
-b bind ip and port applications
Number -w work, the official said, may include: the number of cores * + 1
-c specified configuration file
program manager file entry, i.e. manager.py
app manager in the flask objects
Profile config.py:
import multiprocessing
import os# If no log directory, create a; gunicorn running in the current directory
IF not os.path.exists ( 'log'):
os.mkdir ( 'log')
Debug = True
the bind = '0.0.0.0:5000'
# Pid file as a text file, the contents of only one line, recording the ID of the process;
# Prevent multiple copies of the process started. Only with the process pid file (file name fixed fixed path) write permission (F_WRLCK) can start properly and put their PID is written to the file. Other redundant process is the same program automatically exit.
pidfile = 'log / gunicorn.pid'
loglevel = 'debug' # logging level, and accesslog relevant
logfile = 'log / gunicorn_debug.log' # debug log? Actually not generated
errorlog = 'log / gunicorn_error.log' # specific log information generated by the operation
accesslog = 'log / gunicorn_access.log' # request log only, one per request, the request including the time, size, path
access_log_format = '% (h) s% (l) s% (p) s% (u) s% (t) s% (r) s% (s) s% (b) s% (f) s% (a) s% (D) S '
reload = True# The process started several
workers = multiprocessing.cpu_count ()The manner in which the processing request #
# (同步:sync),(异步:gevent/eventlet),(asyncIO:gthread/ gaiohttp),(tornado:tornado)
worker_class = 'gunicorn.workers.ggevent.GeventWorker'
x_forwarded_for_header = 'X-FORWARDED-FOR'
Once configured by gunicorn -c config.py manager: app start
The flask log integrated into gunicorn
This eliminates the need to store separate flask logs would only need to see gunicorn log to record the flask
__name__ = IF '__main__':!
# if not directly run, logs are in the gunicorn# Reads gunicorn log configuration, such as storage directory, format
gunicorn_logger = logging.getLogger ( 'gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel (gunicorn_logger.level)