gunicorn命令、uvicorn的生产版本

gunicorn命令、uvicorn的生产版本 文章目录命令启动脚本systemd方式kill -9 杀不掉其他命令手册开发测试用uvicorn生产用gunicorn。命令-w # worker 指定有几个进程-k # 指定异步worker如-k uvicorn.workers.UvicornWorker–bind # 绑定端口–daemon # 让服务在后台运行–access-logfile # 指定access日志路径启动脚本#!/bin/bash# 1. 激活虚拟环境source.venv/bin/activate# 2. 使用 Gunicorn Uvicorn Worker 启动# -w 4: 启动4个工作进程建议设为 CPU核心数 * 2 1# -k uvicorn.workers.UvicornWorker: 指定异步 worker# --bind: 绑定地址和端口# --daemon: 让服务在后台运行# --access-logfile / --error-logfile: 指定访问日志和错误日志路径gunicorn main:app-w4-k uvicorn.workers.UvicornWorker--bind0.0.0.0:8000--daemon--access-logfile access.log--error-logfile error.log echoFastAPI 生产环境服务已后台启动systemd方式稍微麻烦些至少要求掌握到gunicorn。kill -9 杀不掉解决方案kill-15主进程id实测成功了牛。其他命令手册gunicorn--help输出结果 usage: gunicorn[OPTIONS][APP_MODULE]options: -h,--helpshow thishelpmessage andexit-v,--versionshow programs version number and exit -c CONFIG, --config CONFIG :ref:The Gunicorn config fileconfiguration_file. [./gunicorn.conf.py] -b ADDRESS, --bind ADDRESS The socket to bind. [[127.0.0.1:8000]] --backlog INT The maximum number of pending connections. [2048] -w INT, --workers INT The number of worker processes for handling requests. [1] -k STRING, --worker-class STRING The type of workers to use. [sync] --threads INT The number of worker threads for handling requests. [1] --worker-connections INT The maximum number of simultaneous clients. [1000] --max-requests INT The maximum number of requests a worker will process before restarting. [0] --max-requests-jitter INT The maximum jitter to add to the *max_requests* setting. [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 in seconds. [30] --keep-alive INT The number of seconds to wait for requests on a Keep-Alive connection. [2] --limit-request-line INT The maximum size of HTTP request line in bytes. [4094] --limit-request-fields INT Limit the number of HTTP headers fields in a request. [100] --limit-request-field_size INT Limit the allowed size of an HTTP request header field. [8190] --reload Restart workers when code changes. [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. [/data/langgraph-demo] -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. [0] -g GROUP, --group GROUP Switch worker process to run as this group. [0] -m INT, --umask INT A bit mask for the file mode on files written by Gunicorn. [0] --initgroups If true, set the worker processs group access list with all of the[False]--forwarded-allow-ips STRING Front-ends IP addresses or networks from which allowed to handle [127.0.0.1,::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-config-json FILE The log config to read config from a JSON file [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 The address 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, [] --enable-backlog-metric Enable socket backlog metric (only supported on Linux). [False] -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 [MODE] Enable PROXY protocol support. [off] --proxy-allow-from PROXY_ALLOW_IPS Front-ends IP addresses or networks fromwhichallowed accept[127.0.0.1,::1]--protocolSTRING The protocolforincoming connections.[http]--uwsgi-allow-from UWSGI_ALLOW_IPS IPs allowed to send uWSGI protocol requests(comma separated).[127.0.0.1,::1]--keyfileFILE SSL keyfile[None]--certfileFILE SSL certificatefile[None]--ssl-version SSL_VERSION SSL version to use(see stdlib ssl modules). [2] --cert-reqs CERT_REQS Whether client certificate is required (see stdlib ssl modules)[0]--ca-certs FILE CA certificatesfile[None]--suppress-ragged-eofs Suppress ragged EOFs(see stdlib ssl modules) [True] --do-handshake-on-connect Whether to perform SSL handshake on socket connect (see stdlib ssl modules)[False]--ciphersCIPHERS SSL Cipher suite to use,intheformatof an OpenSSL cipher list.[None]--http-protocols STRING HTTP protocol versions to support(comma-separated, orderpreference).[h1]--http2-max-concurrent-streams INT Maximum number of concurrent HTTP/2 streams per connection.[100]--http2-initial-window-size INT Initial HTTP/2 flow control window sizeinbytes.[65535]--http2-max-frame-size INT Maximum HTTP/2 frame payload sizeinbytes.[16384]--http2-max-header-list-size INT Maximum size of HTTP/2 header listinbytes(HPACK protection).[65536]--paste-global CONF Set a PasteDeploy global config variableinkeyvalueform.[[]]--permit-obsolete-folding Permit requests employing obsolete HTTP line folding mechanism[False]--strip-header-spaces Strip spaces present between the header name and the the:.[False]--permit-unconventional-http-method Permit HTTP methods not matching conventions, such as IANA registration guidelines[False]--permit-unconventional-http-version Permit HTTP version not matching conventions of2023[False]--casefold-http-method Transform received HTTP methods to uppercase[False]--forwarder-headers FORWARDER_HEADERS A list containing upper-case header field names that the front-end proxy[SCRIPT_NAME,PATH_INFO]--header-map HEADER_MAP Configure how header field names are mapped into environ[drop]--asgi-loop STRING Event loop implementationforASGI workers.[auto]--asgi-lifespan STRING Control ASGI lifespan protocol handling.[auto]--asgi-disconnect-grace-period INT Grace period(seconds)forASGI apps to handle client disconnects.[3]--http-parser STRING HTTP parser implementationforASGI workers.[auto]--root-path STRING The root pathforASGI applications.[]--dirty-app STRING Dirty applications to loadinthe dirty worker pool.[[]]--dirty-workers INT The number of dirty worker processes.[0]--dirty-timeout INT Timeoutfordirty task executioninseconds.[300]--dirty-threads INT The number of threads per dirty worker.[1]--dirty-graceful-timeout INT Timeoutforgraceful dirty workershutdowninseconds.[30]--control-socketPATHUnix socket pathforcontrol interface.[/run/user/0/gunicorn.ctl]--control-socket-mode INT Permission modeforcontrol socket.[384]--no-control-socket Disable control socket.[False]