flask+gunicorn+gevent+supervisor部署网站

首先我们需要安装gunicorn,gevent,supervisor。在centos下使用pip install gunicorn,pip install gevent。yum install supervisor。然后建立gunicorn的配置文件gun.py,代码如下:


import gevent.monkey

import multiprocessing

gevent.monkey.patch_all()

bind = '0.0.0.0:9000'

# restart workers when code change, only use in development

#reload = True

preload_app = True

# debug when development and error when production

loglevel = 'error'

logfile = '/var/log/debug.log'

accesslog = '/var/log/access.log'

access_log_format = '%(h)s %(t)s %(U)s %(q)s'

errorlog = '/var/log/error.log'

# process name

proc_name = 'vservice'

pidfile = 'log/gunicorn.pid'

# set process daemon, not use in default

#daemon = True

# number of processes

workers = multiprocessing.cpu_count() * 2 + 1

# number of threads of per process

threads = multiprocessing.cpu_count() * 2

worker_class = 'gevent'

然后通过supervisor来启动我们的服务,配置文件如下:


[program:demo]

command=/home/venv/bin/gunicorn -c /home/myproject/gun.py demo:app

directory=/home/myproject

startsecs=0

stopwaitsecs=0

autostart=false

autorestart=false

stdout_logfile=/home/myproject/log/gunicorn.log

stderr_logfile=/home/myproject/log/gunicorn.err

其中demo指的就是你的网站的程序,而app指的是文件中的实例。

通过supervisor -c supervisor.conf来启动程序就可以了。
参考链接:http://www.cnblogs.com/luis-allan/archive/2016/11/04/6029820.html

你可能感兴趣的:(flask+gunicorn+gevent+supervisor部署网站)