首页 > 系统相关 >CentOS+Django+uWSGI+Celery+Supervisor配置

CentOS+Django+uWSGI+Celery+Supervisor配置

时间:2024-04-17 15:56:57浏览次数:31  
标签:false supervisord CentOS default Django stderr 进程 Supervisor true

目录

背景

使用 Django 开发的项目需要部署到 CentOS 中,项目中使用了 Celery 和 uWSGI,所以需要一个进程管理软件一键启动项目和 celery

参考:

目录

  • python环境: /opt/anaconda3/envs/GrowthVision/bin/python
  • Django项目: /www/GrowthVision/Backend
  • uwsgi.ini : /www/GrowthVision/Backend/server/uwsgi.ini
  • supervisor配置文件: /etc/supervisord.conf
  • uwsgi进程配置文件: /etc/supervisor/uwsgi.conf
  • uwsgi日志: /var/log/django/uwsgi/uwsgi_stdout.log
  • celery进程配置文件: /etc/supervisor/celery.conf
  • celery日志: /var/log/django/celery/worker|beat|flower_stdout.log

安装

pip install supervisor

配置Supervisor

1.生成配置文件

查看配置文件模板

echo_supervisord_conf

在模版中;是注释,
将关注重点放在输出的最后两行

; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Quotes around values are not supported, except in the case of
;    the environment= options as shown below.
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
;  - Command will be truncated if it looks like a config file comment, e.g.
;    "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ".
;
; Warning:
;  Paths throughout this example file use /tmp because it is available on most
;  systems.  You will likely need to change these to locations more appropriate
;  for your system.  Some systems periodically delete older files in /tmp.
;  Notably, if the socket file defined in the [unix_http_server] section below
;  is deleted, supervisorctl will be unable to connect to supervisord.

[unix_http_server]
file=/tmp/supervisor.sock   ; the path to the socket file
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

; Security Warning:
;  The inet HTTP server is not enabled by default.  The inet HTTP server is
;  enabled by uncommenting the [inet_http_server] section below.  The inet
;  HTTP server is intended for use within a trusted environment only.  It
;  should only be bound to localhost or only accessible from within an
;  isolated, trusted network.  The inet HTTP server does not support any
;  form of encryption.  The inet HTTP server does not use authentication
;  by default (see the username= and password= options to add authentication).
;  Never expose the inet HTTP server to the public internet.

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; ip_address:port specifier, *:port for all iface
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

[supervisord]
logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
loglevel=info                ; log level; default info; others: debug,warn,trace
pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false               ; start in foreground if true; default false
silent=false                 ; no logs to stdout if true; default false
minfds=1024                  ; min. avail startup file descriptors; default 1024
minprocs=200                 ; min. avail process descriptors;default 200
;umask=022                   ; process file creation umask; default 022
;user=supervisord            ; setuid to this UNIX account at startup; recommended if root
;identifier=supervisor       ; supervisord identifier, default is 'supervisor'
;directory=/tmp              ; default is not to cd during start
;nocleanup=true              ; don't clean up tempfiles at start; default false
;childlogdir=/tmp            ; 'AUTO' child log dir, default $TEMP
;environment=KEY="value"     ; key value pairs to add to environment
;strip_ansi=false            ; strip ansi escape codes in logs; def. false

; The rpcinterface:supervisor section must remain in the config file for
; RPC (supervisorctl/web interface) to work.  Additional interfaces may be
; added by defining them in separate [rpcinterface:x] sections.

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

; The supervisorctl section configures how supervisorctl will connect to
; supervisord.  configure it match the settings in either the unix_http_server
; or inet_http_server section.

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as in [*_http_server] if set
;password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available

; The sample program section below shows all possible program subsection values.
; Create one or more 'real' program: sections to be able to control them under
; supervisor.

;[program:theprogramname]
;command=/bin/cat              ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=999                  ; the relative start priority (default 999)
;autostart=true                ; start at supervisord start (default: true)
;startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
;startretries=3                ; max # of serial start failures when starting (default 3)
;autorestart=unexpected        ; when to restart if exited after running (def: unexpected)
;exitcodes=0                   ; 'expected' exit codes used with autorestart (default 0)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false             ; send stop signal to the UNIX process group (default false)
;killasgroup=false             ; SIGKILL the UNIX process group (def false)
;user=chrism                   ; setuid to this UNIX account to run the program
;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)
;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stdout_syslog=false           ; send stdout to syslog with process name (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10     ; # of stderr logfile backups (0 means none, default 10)
;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;stderr_syslog=false           ; send stderr to syslog with process name (default false)
;environment=A="1",B="2"       ; process environment additions (def no adds)
;serverurl=AUTO                ; override serverurl computation (childutils)

; The sample eventlistener section below shows all possible eventlistener
; subsection values.  Create one or more 'real' eventlistener: sections to be
; able to handle event notifications sent by supervisord.

;[eventlistener:theeventlistenername]
;command=/bin/eventlistener    ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;events=EVENT                  ; event notif. types to subscribe to (req'd)
;buffer_size=10                ; event buffer queue size (default 10)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=-1                   ; the relative start priority (default -1)
;autostart=true                ; start at supervisord start (default: true)
;startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
;startretries=3                ; max # of serial start failures when starting (default 3)
;autorestart=unexpected        ; autorestart if exited after running (def: unexpected)
;exitcodes=0                   ; 'expected' exit codes used with autorestart (default 0)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false             ; send stop signal to the UNIX process group (default false)
;killasgroup=false             ; SIGKILL the UNIX process group (def false)
;user=chrism                   ; setuid to this UNIX account to run the program
;redirect_stderr=false         ; redirect_stderr=true is not allowed for eventlisteners
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stdout_syslog=false           ; send stdout to syslog with process name (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10     ; # of stderr logfile backups (0 means none, default 10)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;stderr_syslog=false           ; send stderr to syslog with process name (default false)
;environment=A="1",B="2"       ; process environment additions
;serverurl=AUTO                ; override serverurl computation (childutils)

; The sample group section below shows all possible group values.  Create one
; or more 'real' group: sections to create "heterogeneous" process groups.

;[group:thegroupname]
;programs=progname1,progname2  ; each refers to 'x' in [program:x] definitions
;priority=999                  ; the relative start priority (default 999)

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

;[include]
;files = relative/directory/*.ini

然而上面命令输出的结果仅是一个模板,我们需要使用下面的命令在/etc目录下生成配置文件

cho_supervisord_conf > /etc/supervisord.conf

2. 修改配置文件

之后我们可以使用vim查看该文件的内容

vim /etc/supervisord.conf

我们可以看到,该配置文件内容一大堆,但是我们目前仅需要知道并改文件末尾的这个部分就可以了,这是默认写法

;[include]
;files = relative/directory/*.ini

我们首先把它去然后将files的值改为:

[include]
files = /etc/supervisor/*.conf

include可以理解为包含,它的意思是将/etc/supervisor/目录下的,所有以.conf结尾的文件包含进来,/etc/下的supervisor/文件夹默认是不存在的,我们需要手动创建:

cd /etc
mkdir supervisor

.conf结尾的文件文件也是默认不存的,也需要我们根据需求自己创建,一个conf文件代表的是一个程序,假如我需要supervisor管理uwsgi程序,那么就在/etc/supervisor/目录下创建一个uwsgi.conf文件,在里面写入配置信息,如果需要管理其他的xx程序,就重新创建一个xx.conf文件,比如 celery.conf

3. 创建进程文件

创建 uwsgi.conf 进程文件

好,现在我们就创建一个uwsgi.conf文件

vim /etc/supervisor/uwsgi.conf

将下面内容复制到文件中

[program:uwsgi]
command=/opt/anaconda3/envs/GrowthVision/bin/uwsgi --ini /www/GrowthVision/Backend/server/uwsgi.ini
user=root
autorestart=true
autostart=true
startretries=3
redirect_stderr=true
startsecs=5
stdout_logfile=/var/log/django/uwsgi/uwsgi_stdout.log
stderr_logfile=/var/log/django/uwsgi/uwsgi_stderr.log
stopasgroup=true
killasgroup=true
priority=999

键值说明
不要将下面的内容复制进去,要复制复制上面的

标签:false,supervisord,CentOS,default,Django,stderr,进程,Supervisor,true
From: https://www.cnblogs.com/thankcat/p/18140922

相关文章

  • django 不推荐使用 makemigrations migrate
    个人使用感触,希望大家交流讨论发现用django去管理数据库这些操作,以下两点可能感觉用着还可以,1.对于定义好表结构,字段的这些,并且开发中不修改,很少修改的用着还行,2.习惯用这种方式的,php的laravel也是,不过,试过之后,就很少用了;我说说我的理由:1.最简单的,这边该维护model维护mo......
  • 【CentOS7】ulimit 使用
    ulimit-a显示当前用户进程限制语法:ulimit[-aHS][-c<core文件上限>][-d<数据节区大小>][-f<文件大小>][-m<内存大小>][-n<文件数目>][-p<缓冲区大小>][-s<堆叠大小>][-t<CPU时间>][-u<程序数目>][-v<虚拟内存大小>]参数:  -a显示目前资源限制的设定。   -c......
  • Linux centos安装tesseract-ocr教程
    安装依赖依赖的包:autoconfautomakelibtoollibjpeg-devellibpng-devellibtiff-develzlib-develleptonica(1.67以上)(一下环境依赖,有则更新,无则安装)yuminstallautoconfautomakelibtoolyuminstalllibjpeg-devellibpng-devellibtiff-develzlib-develLeptonica库......
  • centos防火墙怎么关闭
    centos防火墙怎么关闭在CentOS系统中,可以使用firewalld服务来管理防火墙。如果你想要关闭防火墙,可以执行以下命令:停止firewalld服务:sudosystemctlstopfirewalld  禁用firewalld服务,使其不在系统启动时自动运行:sudosystemctldisablefirew......
  • docker使用centos镜像创建的容器内使用systemctl重启sshd服务报错或者无法使用
    问题是这样的:如果镜像是ubuntu系统的,创建容器后使用systemctl启动sshd没有什么问题,但是如果镜像是centos,那就会报错failedtoconnecttobusnosuch原因:centos系统的的安全性较高,相比ubuntu一些底层无法映射到容器中,即使在创建容器时加上--security-optseccomp:unconfined --......
  • CentOS安装
    VMware虚拟机指通过软件模拟的具有完整硬件系统功能的、运行在一个完全隔离环境中的完整计算机系统,在实体计算机中能够完成的工作在虚拟机中都能够实现。介绍VMWare虚拟机软件是一个“虚拟PC”软件,它使你可以在一台机器上同时运行多个系统。VMware是一款功能强大的桌面虚拟......
  • CentOS 7配置Nginx反向代理的步骤
    安装Nginx:如果你的服务器还没有安装Nginx,你可以使用以下命令来安装:sudoyuminstallepel-releasesudoyuminstallnginx创建或修改Nginx配置文件:默认的Nginx配置文件通常位于/etc/nginx/conf.d/目录下。你可以在这个目录下创建一个新的配置文件,例如yourdomain.conf:sudo......
  • CentOS 7.9 python 虚拟环境安装mysqlclient失败
    目录环境懵懂安装报错原因解决完结撒花......
  • CentOS 7.9编译安装Python-3.10.13
    目录查看CentOS版本、系统默认gcc版本、Python版本和pip版本部署Python-3.10.13测试将yum中的Python版本修改为系统原来的2.7.5版本查看CentOS版本、系统默认gcc版本、Python版本和pip版本cat/etc/redhat-releasegcc--versionpython-Vpip-V部署Python-3.10.13下载......
  • 5.CentOS-7-Minimal 安装KubernetesV1.23.17&DockerV20.10.23
    1.环境准备主节点IP:192.168.254.130node1IP:192.168.254.131node2IP:192.168.254.132OSversion:CentOS7miniCPUArchitecture:x86_64/amd64K8sversion:v1.23.17Dockerversion:20.10.232.安装前准备#安装依赖yuminstall-ycurlwgetsystemdbash-completi......