美文网首页
Celery 部署和监控

Celery 部署和监控

作者: 爱修仙的道友 | 来源:发表于2019-04-26 09:11 被阅读0次

监控工具:flower

  • Install :pip install flower
  • Start : python manage.py celery flower --basic_auth=pyvip:qwe123
image.png image.png

进程管理工具:supervisor

  • Install : pip install supervisor
  • Start : supervisord -c /etc/supervisord.conf
  • Tool : supervisorctl

项目目录下

(Cel_proj) pyvip@vip:~/DjCe_proj$ mkdir conf
(Cel_proj) pyvip@vip:~/DjCe_proj$ echo_supervisord_conf > conf/supervisord.conf
  • 开启web服务


    image.png
    image.png
  • 本项目所有 .ini文件视为其配置文件


    image.png
  • 源文件

; 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 ".

[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)

[inet_http_server]         ; inet (TCP) server disabled by default
port=0.0.0.0: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
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 = *.ini



自定义配置

  • 目录结构


    image.png
  • supervisord_celery_worker.ini

[program:pyvip-celery-worker]
command=python manage.py celery worker -l INFO
directory=/home/pyvip/DjCe_proj
environment=PATH="/home/pyvip/.virtualenvs/Cel_proj/bin"
stdout_logfile=/home/pyvip/DjCe_proj/logs/celery_worker_info.log
stderr_logfile=/home/pyvip/DjCe_proj/logs/celery_worker_err.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=60
priority=998
  • supervisord_celery_beat.ini
[program:pyvip-celery-beat]
command=python manage.py celery beat -l INFO
directory=/home/pyvip/DjCe_proj
environment=PATH="/home/pyvip/.virtualenvs/Cel_proj/bin"
stdout_logfile=/home/pyvip/DjCe_proj/logs/celery_beat_info.log
stderr_logfile=/home/pyvip/DjCe_proj/logs/celery_beat_err.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=60
priority=998
  • supervisord_celery_flower.ini
[program:pyvip-celery-flower]
command=python manage.py celery flower
directory=/home/pyvip/DjCe_proj
environment=PATH="/home/pyvip/.virtualenvs/Cel_proj/bin"
stdout_logfile=/home/pyvip/DjCe_proj/logs/celery_flower_info.log
stderr_logfile=/home/pyvip/DjCe_proj/logs/celery_flower_err.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=60
priority=996

执行命令

(Cel_proj) pyvip@vip:~/DjCe_proj$ supervisord -c conf/supervisord.conf
Unlinking stale socket /tmp/supervisor.sock
(Cel_proj) pyvip@vip:~/DjCe_proj$ supervisorctl
Server requires authentication
Username:user
Password:
supervisor> status
pyvip-celery-beat                STARTING  
pyvip-celery-flower              STARTING  
pyvip-celery-worker              STARTING  
  • 展示


    image.png

相关文章

  • Celery 部署和监控

    监控工具:flower Install :pip install flower Start : python ma...

  • 忘记Django登陆账号和密码的处理方法

    公司部署了一套分布式网络监控系统,使用celery来做的分布式任务队列,针对celery的周期任务管理使用的是dj...

  • Celery 进阶学习

    Celery 进阶学习 参考链接: Celery 4.1.0 documentation 初始文件 安装部署cel...

  • k8s 搭建 gpu 监控

    部署架构 部署方式:kubernetesnode 监控和 gpu 监控 node-exporter + gpu-m...

  • Celery部署爬虫(二)

    书接上文 Celery部署爬虫(一) Celery架构的启动都要依靠配置参数来触发,Celery简单、灵活、可靠很...

  • Celery部署爬虫(三)

    今天就来点比较有意思的东西 面前两篇Celery部署爬虫(一) Celery部署爬虫(二) 充其量就是 Celer...

  • Celery 监控和管理向导

    1、介绍有几种工具可用来监视和检查 Celery 集群。本文将介绍其中的一些功能,以及与监视相关的特性,比如事件和...

  • 部署celery

    一、Celery介绍和基本使用 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松...

  • django+celery+psutil+channels+el

    django+celery+psutil+channels+elasticsearch实现监控实时告警功能--一次...

  • 2019-10-24 celery4.3.0的Inspect无效

    错误现象 worker-inspect监控功能, 如celery -A proj inspect stats始终报...

网友评论

      本文标题:Celery 部署和监控

      本文链接:https://www.haomeiwen.com/subject/atuzgqtx.html