Gunicorn部署flask

1 安装gunicorn

最好在linux环境下安装和测试,我的机器是Ubantu 20.04

pip install gunicorn

2 gunicorn可选参数

(laogao) zjf@ubuntu:~/Desktop/laogao$ gunicorn -h
usage: gunicorn [OPTIONS] [APP_MODULE]

optional arguments:
  -h, --help            帮助
  -v, --version         版本
  -c CONFIG, --config CONFIG 	配置文件
  -b ADDRESS, --bind ADDRESS	绑定IP:Port [['127.0.0.1:8000']]
  --backlog INT         		挂起的最大链接数. [2048]
  -w INT, --workers INT			处理请求的进程数. [1]
  -k STRING, --worker-class STRING		处理方法. [sync]
  --threads INT         		处理请求的线程数. [1]
  --worker-connections INT		并发链接. [1000]
  --max-requests INT    		重启前最大请求数. [0]
  --max-requests-jitter INT		--max-requests抖动. [0]
  -t INT, --timeout INT			Workers silent for more than this many seconds are killed and restarted. [30]
  --graceful-timeout INT		Timeout for graceful workers restart. [30]
  --keep-alive INT      		长连接保持的秒数. [2]
  --limit-request-line INT		HTTP请求的最大字节. [4094]
  --limit-request-fields INT	限制请求中HTTP报头字段的数量. [100]
  --limit-request-field_size INT限制HTTP请求报头字段的最大字节. [8190]
  --reload              		代码更改重启服务. [False]
  --reload-engine STRING		The implementation that should be used to power :ref:`reload`. [auto]
  --reload-extra-file FILES
                        Extends :ref:`reload` option to also watch and reload on additional files [[]]
  --spew                Install a trace function that spews every line executed by the server. [False]
  --check-config        Check the configuration and exit. The exit status is 0 if the [False]
  --print-config        Print the configuration settings as fully resolved. Implies :ref:`check-config`. [False]
  --preload             Load application code before the worker processes are forked. [False]
  --no-sendfile         Disables the use of ``sendfile()``. [None]
  --reuse-port          Set the ``SO_REUSEPORT`` flag on the listening socket. [False]
  --chdir CHDIR         Change directory to specified directory before loading apps. [/home/zjf/Desktop/laogao]
  -D, --daemon          Daemonize the Gunicorn process. [False]
  -e ENV, --env ENV     Set environment variables in the execution environment. [[]]
  -p FILE, --pid FILE   A filename to use for the PID file. [None]
  --worker-tmp-dir DIR  A directory to use for the worker heartbeat temporary file. [None]
  -u USER, --user USER  Switch worker processes to run as this user. [1000]
  -g GROUP, --group GROUP
                        Switch worker process to run as this group. [1000]
  -m INT, --umask INT   A bit mask for the file mode on files written by Gunicorn. [0]
  --initgroups          If true, set the worker process's group access list with all of the [False]
  --forwarded-allow-ips STRING
                        Front-end's IPs from which allowed to handle set secure headers. [127.0.0.1]
  --access-logfile FILE
                        The Access log file to write to. [None]
  --disable-redirect-access-to-syslog
                        Disable redirect access logs to syslog. [False]
  --access-logformat STRING
                        The access log format. [%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"]
  --error-logfile FILE, --log-file FILE
                        The Error log file to write to. [-]
  --log-level LEVEL     The granularity of Error log outputs. [info]
  --capture-output      Redirect stdout/stderr to specified file in :ref:`errorlog`. [False]
  --logger-class STRING
                        The logger you want to use to log events in Gunicorn. [gunicorn.glogging.Logger]
  --log-config FILE     The log config file to use. [None]
  --log-syslog-to SYSLOG_ADDR
                        Address to send syslog messages. [udp://localhost:514]
  --log-syslog          Send *Gunicorn* logs to syslog. [False]
  --log-syslog-prefix SYSLOG_PREFIX
                        Makes Gunicorn use the parameter as program-name in the syslog entries. [None]
  --log-syslog-facility SYSLOG_FACILITY
                        Syslog facility name [user]
  -R, --enable-stdio-inheritance
                        Enable stdio inheritance. [False]
  --statsd-host STATSD_ADDR
                        ``host:port`` of the statsd server to log to. [None]
  --dogstatsd-tags DOGSTATSD_TAGS
                        A comma-delimited list of datadog statsd (dogstatsd) tags to append to []
  --statsd-prefix STATSD_PREFIX
                        Prefix to use when emitting statsd metrics (a trailing ``.`` is added, []
  -n STRING, --name STRING
                        A base to use with setproctitle for process naming. [None]
  --pythonpath STRING   A comma-separated list of directories to add to the Python path. [None]
  --paste STRING, --paster STRING
                        Load a PasteDeploy config file. The argument may contain a ``#`` [None]
  --proxy-protocol      Enable detect PROXY protocol (PROXY mode). [False]
  --proxy-allow-from PROXY_ALLOW_IPS
                        Front-end's IPs from which allowed accept proxy requests (comma separate). [127.0.0.1]
  --keyfile FILE        SSL key file [None]
  --certfile FILE       SSL certificate file [None]
  --ssl-version SSL_VERSION
                        SSL version to use. [_SSLMethod.PROTOCOL_TLS]
  --cert-reqs CERT_REQS
                        Whether client certificate is required (see stdlib ssl module's) [VerifyMode.CERT_NONE]
  --ca-certs FILE       CA certificates file [None]
  --suppress-ragged-eofs
                        Suppress ragged EOFs (see stdlib ssl module's) [True]
  --do-handshake-on-connect
                        Whether to perform SSL handshake on socket connect (see stdlib ssl module's) [False]
  --ciphers CIPHERS     SSL Cipher suite to use, in the format of an OpenSSL cipher list. [None]
  --paste-global CONF   Set a PasteDeploy global config variable in ``key=value`` form. [[]]
  --strip-header-spaces
                        Strip spaces present between the header name and the the ``:``. [False]

3 使用gunicorn运行flask

(python) [root@iZ2ze6xwud2wojjfe7252fZ python]#  gunicorn -w 2 -b 127.0.0.1:5000 -D app.manage:app
(python) [root@iZ2ze6xwud2wojjfe7252fZ python]# pstree -ap|grep gunicorn
  |-gunicorn,17987 /root/python/.venv/bin/gunicorn -w 2 -b 127.0.0.1:5000 -D app.manage:app
  |   |-gunicorn,17990 /root/python/.venv/bin/gunicorn -w 2 -b 127.0.0.1:5000 -D app.manage:app
  |   `-gunicorn,17991 /root/python/.venv/bin/gunicorn -w 2 -b 127.0.0.1:5000 -D app.manage:app
  |   |               |-grep,17995 --color=auto gunicorn
(python) [root@iZ2ze6xwud2wojjfe7252fZ python]# kill -9 17987

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kobe_OKOK_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值