经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Django » 查看文章
CentOS+Django+uWSGI+Celery+Supervisor配置
来源:cnblogs  作者:ThankCAT  时间:2024/4/17 15:46:55  对本文有异议

背景

使用 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

安装

  1. pip install supervisor

配置Supervisor

1.生成配置文件

查看配置文件模板

  1. echo_supervisord_conf

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

  1. ; Sample supervisor config file.
  2. ;
  3. ; For more information on the config file, please see:
  4. ; http://supervisord.org/configuration.html
  5. ;
  6. ; Notes:
  7. ; - Shell expansion ("~" or "$HOME") is not supported. Environment
  8. ; variables can be expanded using this syntax: "%(ENV_HOME)s".
  9. ; - Quotes around values are not supported, except in the case of
  10. ; the environment= options as shown below.
  11. ; - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
  12. ; - Command will be truncated if it looks like a config file comment, e.g.
  13. ; "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ".
  14. ;
  15. ; Warning:
  16. ; Paths throughout this example file use /tmp because it is available on most
  17. ; systems. You will likely need to change these to locations more appropriate
  18. ; for your system. Some systems periodically delete older files in /tmp.
  19. ; Notably, if the socket file defined in the [unix_http_server] section below
  20. ; is deleted, supervisorctl will be unable to connect to supervisord.
  21. [unix_http_server]
  22. file=/tmp/supervisor.sock ; the path to the socket file
  23. ;chmod=0700 ; socket file mode (default 0700)
  24. ;chown=nobody:nogroup ; socket file uid:gid owner
  25. ;username=user ; default is no username (open server)
  26. ;password=123 ; default is no password (open server)
  27. ; Security Warning:
  28. ; The inet HTTP server is not enabled by default. The inet HTTP server is
  29. ; enabled by uncommenting the [inet_http_server] section below. The inet
  30. ; HTTP server is intended for use within a trusted environment only. It
  31. ; should only be bound to localhost or only accessible from within an
  32. ; isolated, trusted network. The inet HTTP server does not support any
  33. ; form of encryption. The inet HTTP server does not use authentication
  34. ; by default (see the username= and password= options to add authentication).
  35. ; Never expose the inet HTTP server to the public internet.
  36. ;[inet_http_server] ; inet (TCP) server disabled by default
  37. ;port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface
  38. ;username=user ; default is no username (open server)
  39. ;password=123 ; default is no password (open server)
  40. [supervisord]
  41. logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log
  42. logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB
  43. logfile_backups=10 ; # of main logfile backups; 0 means none, default 10
  44. loglevel=info ; log level; default info; others: debug,warn,trace
  45. pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
  46. nodaemon=false ; start in foreground if true; default false
  47. silent=false ; no logs to stdout if true; default false
  48. minfds=1024 ; min. avail startup file descriptors; default 1024
  49. minprocs=200 ; min. avail process descriptors;default 200
  50. ;umask=022 ; process file creation umask; default 022
  51. ;user=supervisord ; setuid to this UNIX account at startup; recommended if root
  52. ;identifier=supervisor ; supervisord identifier, default is 'supervisor'
  53. ;directory=/tmp ; default is not to cd during start
  54. ;nocleanup=true ; don't clean up tempfiles at start; default false
  55. ;childlogdir=/tmp ; 'AUTO' child log dir, default $TEMP
  56. ;environment=KEY="value" ; key value pairs to add to environment
  57. ;strip_ansi=false ; strip ansi escape codes in logs; def. false
  58. ; The rpcinterface:supervisor section must remain in the config file for
  59. ; RPC (supervisorctl/web interface) to work. Additional interfaces may be
  60. ; added by defining them in separate [rpcinterface:x] sections.
  61. [rpcinterface:supervisor]
  62. supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
  63. ; The supervisorctl section configures how supervisorctl will connect to
  64. ; supervisord. configure it match the settings in either the unix_http_server
  65. ; or inet_http_server section.
  66. [supervisorctl]
  67. serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
  68. ;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
  69. ;username=chris ; should be same as in [*_http_server] if set
  70. ;password=123 ; should be same as in [*_http_server] if set
  71. ;prompt=mysupervisor ; cmd line prompt (default "supervisor")
  72. ;history_file=~/.sc_history ; use readline history if available
  73. ; The sample program section below shows all possible program subsection values.
  74. ; Create one or more 'real' program: sections to be able to control them under
  75. ; supervisor.
  76. ;[program:theprogramname]
  77. ;command=/bin/cat ; the program (relative uses PATH, can take args)
  78. ;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
  79. ;numprocs=1 ; number of processes copies to start (def 1)
  80. ;directory=/tmp ; directory to cwd to before exec (def no cwd)
  81. ;umask=022 ; umask for process (default None)
  82. ;priority=999 ; the relative start priority (default 999)
  83. ;autostart=true ; start at supervisord start (default: true)
  84. ;startsecs=1 ; # of secs prog must stay up to be running (def. 1)
  85. ;startretries=3 ; max # of serial start failures when starting (default 3)
  86. ;autorestart=unexpected ; when to restart if exited after running (def: unexpected)
  87. ;exitcodes=0 ; 'expected' exit codes used with autorestart (default 0)
  88. ;stopsignal=QUIT ; signal used to kill process (default TERM)
  89. ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
  90. ;stopasgroup=false ; send stop signal to the UNIX process group (default false)
  91. ;killasgroup=false ; SIGKILL the UNIX process group (def false)
  92. ;user=chrism ; setuid to this UNIX account to run the program
  93. ;redirect_stderr=true ; redirect proc stderr to stdout (default false)
  94. ;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
  95. ;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
  96. ;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10)
  97. ;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
  98. ;stdout_events_enabled=false ; emit events on stdout writes (default false)
  99. ;stdout_syslog=false ; send stdout to syslog with process name (default false)
  100. ;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
  101. ;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
  102. ;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10)
  103. ;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
  104. ;stderr_events_enabled=false ; emit events on stderr writes (default false)
  105. ;stderr_syslog=false ; send stderr to syslog with process name (default false)
  106. ;environment=A="1",B="2" ; process environment additions (def no adds)
  107. ;serverurl=AUTO ; override serverurl computation (childutils)
  108. ; The sample eventlistener section below shows all possible eventlistener
  109. ; subsection values. Create one or more 'real' eventlistener: sections to be
  110. ; able to handle event notifications sent by supervisord.
  111. ;[eventlistener:theeventlistenername]
  112. ;command=/bin/eventlistener ; the program (relative uses PATH, can take args)
  113. ;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
  114. ;numprocs=1 ; number of processes copies to start (def 1)
  115. ;events=EVENT ; event notif. types to subscribe to (req'd)
  116. ;buffer_size=10 ; event buffer queue size (default 10)
  117. ;directory=/tmp ; directory to cwd to before exec (def no cwd)
  118. ;umask=022 ; umask for process (default None)
  119. ;priority=-1 ; the relative start priority (default -1)
  120. ;autostart=true ; start at supervisord start (default: true)
  121. ;startsecs=1 ; # of secs prog must stay up to be running (def. 1)
  122. ;startretries=3 ; max # of serial start failures when starting (default 3)
  123. ;autorestart=unexpected ; autorestart if exited after running (def: unexpected)
  124. ;exitcodes=0 ; 'expected' exit codes used with autorestart (default 0)
  125. ;stopsignal=QUIT ; signal used to kill process (default TERM)
  126. ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
  127. ;stopasgroup=false ; send stop signal to the UNIX process group (default false)
  128. ;killasgroup=false ; SIGKILL the UNIX process group (def false)
  129. ;user=chrism ; setuid to this UNIX account to run the program
  130. ;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners
  131. ;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
  132. ;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
  133. ;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10)
  134. ;stdout_events_enabled=false ; emit events on stdout writes (default false)
  135. ;stdout_syslog=false ; send stdout to syslog with process name (default false)
  136. ;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
  137. ;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
  138. ;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10)
  139. ;stderr_events_enabled=false ; emit events on stderr writes (default false)
  140. ;stderr_syslog=false ; send stderr to syslog with process name (default false)
  141. ;environment=A="1",B="2" ; process environment additions
  142. ;serverurl=AUTO ; override serverurl computation (childutils)
  143. ; The sample group section below shows all possible group values. Create one
  144. ; or more 'real' group: sections to create "heterogeneous" process groups.
  145. ;[group:thegroupname]
  146. ;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions
  147. ;priority=999 ; the relative start priority (default 999)
  148. ; The [include] section can just contain the "files" setting. This
  149. ; setting can list multiple files (separated by whitespace or
  150. ; newlines). It can also contain wildcards. The filenames are
  151. ; interpreted as relative to this file. Included files *cannot*
  152. ; include files themselves.
  153. ;[include]
  154. ;files = relative/directory/*.ini

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

  1. cho_supervisord_conf > /etc/supervisord.conf

2. 修改配置文件

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

  1. vim /etc/supervisord.conf

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

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

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

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

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

  1. cd /etc
  2. mkdir supervisor

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

3. 创建进程文件

创建 uwsgi.conf 进程文件

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

  1. vim /etc/supervisor/uwsgi.conf

将下面内容复制到文件中

  1. [program:uwsgi]
  2. command=/opt/anaconda3/envs/GrowthVision/bin/uwsgi --ini /www/GrowthVision/Backend/server/uwsgi.ini
  3. user=root
  4. autorestart=true
  5. autostart=true
  6. startretries=3
  7. redirect_stderr=true
  8. startsecs=5
  9. stdout_logfile=/var/log/django/uwsgi/uwsgi_stdout.log
  10. stderr_logfile=/var/log/django/uwsgi/uwsgi_stderr.log
  11. stopasgroup=true
  12. killasgroup=true
  13. priority=999

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

  1. # 进程的名字
  2. [program:uwsgi]
  3. # 需要托管给supervisor执行的命令,这里是uwsgi的启动命令,这里需要按自己的情况更改
  4. # /opt/anaconda3/envs/GrowthVision/bin/uwsgi anaconda3的 python 环境中的uwsgi命令
  5. # --ini uwsgi命令参数
  6. # /www/GrowthVision/Backend/server/uwsgi.ini 项目中 uwsgi 的初始化文件
  7. command=/opt/anaconda3/envs/GrowthVision/bin/uwsgi --ini /www/GrowthVision/Backend/server/uwsgi.ini
  8. # 执行命令的用户,这里填root,你可以填其他的,只要有权限即可
  9. user=root
  10. # uwsgi关闭后是否自动重启
  11. autorestart=true
  12. # 是否随supervisor启动而启动
  13. autostart=true
  14. # 启动失败自动重试次数,默认是 3
  15. startretries=3
  16. # 把 stderr 重定向到 stdout,默认 false
  17. redirect_stderr=true
  18. # 启动 5 秒后没有异常退出,就当作已经正常启动了
  19. startsecs=5
  20. # 当前进程正常运行日志文件存放目录
  21. stdout_logfile=/var/log/django/uwsgi/uwsgi_stdout.log
  22. # 当前进程运行异常日志文件存放目录
  23. stderr_logfile=/var/log/django/uwsgi/uwsgi_stderr.log
  24. # 是否干掉程序的所有进程(包括子进程)
  25. stopasgroup=true
  26. # 作用同上
  27. killasgroup=true
  28. # 程序启动优先级,若有多个进程管理时使用,默认-1
  29. priority=999

创建celery进程文件

  1. vim /etc/supervisor/celery.conf
  1. [program:celery-worker]
  2. command=/opt/anaconda3/envs/GrowthVision/bin/celery -A server worker -l info
  3. directory=/www/GrowthVision/Backend/
  4. user=root
  5. autorestart=true
  6. autostart=true
  7. startretries=3
  8. redirect_stderr=true
  9. startsecs=5
  10. stdout_logfile=/var/log/django/celery/worker_stdout.log
  11. stderr_logfile=/var/log/django/celery/worker_stderr.log
  12. stopasgroup=true
  13. killasgroup=true
  14. priority=998
  15. [program:celery-beat]
  16. command=/opt/anaconda3/envs/GrowthVision/bin/celery -A server beat -l info
  17. directory=/www/GrowthVision/Backend/
  18. user=root
  19. autorestart=true
  20. autostart=true
  21. startretries=3
  22. redirect_stderr=true
  23. startsecs=5
  24. stdout_logfile=/var/log/django/celery/beat_stdout.log
  25. stderr_logfile=/var/log/django/celery/beat_stderr.log
  26. stopasgroup=true
  27. killasgroup=true
  28. priority=997
  29. [program:celery-flower]
  30. command=/opt/anaconda3/envs/GrowthVision/bin/celery -A server flower -l info --basic_auth=chenhao:951215
  31. directory=/www/GrowthVision/Backend/
  32. user=root
  33. autorestart=true
  34. autostart=true
  35. startretries=3
  36. redirect_stderr=true
  37. startsecs=5
  38. stdout_logfile=/var/log/django/celery/flower_stdout.log
  39. stderr_logfile=/var/log/django/celery/flower_stderr.log
  40. stopasgroup=true
  41. killasgroup=true
  42. priority=996

一些需要注意的键值说明

  1. # celery worker beat flower 一共三个进程,用不到的可以删掉
  2. [program:celery-worker]
  3. [program:celery-beat]
  4. [program:celery-flower]
  5. # 三个进城的区别在command,这里使用worker举例
  6. # 需要托管给supervisor执行的命令,这里是uwsgi的启动命令,这里需要按自己的情况更改
  7. # /opt/anaconda3/envs/GrowthVision/bin/celery anaconda3的 python 环境中的celery命令
  8. # -A server worker -l info celery命令参数
  9. command=/opt/anaconda3/envs/GrowthVision/bin/celery -A server worker -l info
  10. # Django项目所在的目录
  11. # 我的项目地址 /www/GrowthVision/Backend/server/celery.py
  12. directory=/www/GrowthVision/Backend/

启动supervisor

启动之前需要在uwsgi.ini中修改uwsgi配置,并且干掉正在运行的uwsgi进程

  1. 修改 uwsgi配置
  1. daemonize=%(chdir)/server/uwsgi.log
  2. <<---注释掉uwsgi配置文件中自己的日志输出--->>
  3. # daemonize=%(chdir)/server/uwsgi.log
  1. 干掉uwsgi进程
  1. # 如果没启动就不运行这个
  2. ps -aux | grep uwsgi |awk '{print $2}'|xargs kill -9

启动supervisor

  1. supervisord -c /etc/supervisord.conf

查看所有进程的状态

  1. supervisorctl status

正常结果

  1. celery-beat RUNNING pid 106329, uptime 1:08:53
  2. celery-flower RUNNING pid 13742, uptime 0:53:15
  3. celery-worker RUNNING pid 106613, uptime 1:08:44
  4. uwsgi RUNNING pid 106614, uptime 1:08:44

错误结果

  1. uwsgi FATAL Exited too quickly (process log may have details)

如果有启动失败的去进程配置文件中的日志路径中去查看日志,看看哪里出了问题,大多数情况都是配置参数的问题,自己多调试几遍也就好了

常用命令

  1. ps -aux | grep supervisord # 查看所有进程ID
  2. supervisorctl status # 查看所有进程的状态
  3. supervisord -c /etc/supervisord.conf # 开启supervisord
  4. supervisord # 启动supervisord
  5. supervisorctl start all # 启动supervisord管理的所有进程
  6. supervisorctl stop all # 停止supervisord管理的所有进程
  7. supervisorctl restart all # 重启所有进程
  8. supervisorctl stop zedis # 停止zedis, name为[program:xx]中的xx
  9. supervisorctl start zedis # 启动zedis
  10. supervisorctl restart zedis # 重启zedis
  11. supervisorctl update # 配置文件修改后使用该命令加载新的配置
  12. supervisorctl reload # 重新加载配置文件并启动
  13. supervisorctl shutdown # 停止supervisord

配置文件详解

  1. [unix_http_server]
  2. file=/tmp/supervisor.sock ; socket文件的路径,supervisorctlXML_RPCsupervisord通信就是通过它进行
  3. 的。如果不设置的话,supervisorctl也就不能用了
  4. 不设置的话,默认为none 非必须设置
  5. ;chmod=0700 ; 这个简单,就是修改上面的那个socket文件的权限为0700
  6. 不设置的话,默认为0700 非必须设置
  7. ;chown=nobody:nogroup ; 这个一样,修改上面的那个socket文件的属组为user.group
  8. 不设置的话,默认为启动supervisord进程的用户及属组。非必须设置
  9. ;username=user ; 使用supervisorctl连接的时候,认证的用户
  10. 不设置的话,默认为不需要用户。 非必须设置
  11. ;password=123 ; 和上面的用户名对应的密码,可以直接使用明码,也可以使用SHA加密
  12. 如:{SHA}82ab876d1387bfafe46cc1c8a2ef074eae50cb1d
  13. 默认不设置。。。非必须设置
  14. ;[inet_http_server] ; 侦听在TCP上的socketWeb Server和远程的supervisorctl都要用到他
  15. 不设置的话,默认为不开启。非必须设置
  16. ;port=127.0.0.1:9001 ; 这个是侦听的IP和端口,侦听所有IP :9001或*:9001
  17. 这个必须设置,只要上面的[inet_http_server]开启了,就必须设置它
  18. ;username=user ; 这个和上面的uinx_http_server一个样。非必须设置
  19. ;password=123 ; 这个也一个样。非必须设置
  20. [supervisord] ;这个主要是定义supervisord这个服务端进程的一些参数的
  21. 这个必须设置,不设置,supervisor就不用干活了
  22. logfile=/tmp/supervisord.log ; 这个是supervisord这个主进程的日志路径,注意和子进程的日志不搭嘎。
  23. 默认路径$CWD/supervisord.log$CWD是当前目录。。非必须设置
  24. logfile_maxbytes=50MB ; 这个是上面那个日志文件的最大的大小,当超过50M的时候,会生成一个新的日
  25. 志文件。当设置为0时,表示不限制文件大小
  26. 默认值是50M,非必须设置。
  27. logfile_backups=10 ; 日志文件保持的数量,上面的日志文件大于50M时,就会生成一个新文件。文件
  28. 数量大于10时,最初的老文件被新文件覆盖,文件数量将保持为10
  29. 当设置为0时,表示不限制文件的数量。
  30. 默认情况下为10。。。非必须设置
  31. loglevel=info ; 日志级别,有critical, error, warn, info, debug, trace, or blather
  32. 默认为info。。。非必须设置项
  33. pidfile=/tmp/supervisord.pid ; supervisordpid文件路径。
  34. 默认为$CWD/supervisord.pid。。。非必须设置
  35. nodaemon=false ; 如果是truesupervisord进程将在前台运行
  36. 默认为false,也就是后台以守护进程运行。。。非必须设置
  37. minfds=1024 ; 这个是最少系统空闲的文件描述符,低于这个值supervisor将不会启动。
  38. 系统的文件描述符在这里设置cat /proc/sys/fs/file-max
  39. 默认情况下为1024。。。非必须设置
  40. minprocs=200 ; 最小可用的进程描述符,低于这个值supervisor也将不会正常启动。
  41. ulimit -u这个命令,可以查看linux下面用户的最大进程数
  42. 默认为200。。。非必须设置
  43. ;umask=022 ; 进程创建文件的掩码
  44. 默认为022。。非必须设置项
  45. ;user=chrism ; 这个参数可以设置一个非root用户,当我们以root用户启动supervisord之后。
  46. 我这里面设置的这个用户,也可以对supervisord进行管理
  47. 默认情况是不设置。。。非必须设置项
  48. ;identifier=supervisor ; 这个参数是supervisord的标识符,主要是给XML_RPC用的。当你有多个
  49. supervisor的时候,而且想调用XML_RPC统一管理,就需要为每个
  50. supervisor设置不同的标识符了
  51. 默认是supervisord。。。非必需设置
  52. ;directory=/tmp ; 这个参数是当supervisord作为守护进程运行的时候,设置这个参数的话,启动
  53. supervisord进程之前,会先切换到这个目录
  54. 默认不设置。。。非必须设置
  55. ;nocleanup=true ; 这个参数当为false的时候,会在supervisord进程启动的时候,把以前子进程
  56. 产生的日志文件(路径为AUTO的情况下)清除掉。有时候咱们想要看历史日志,当
  57. 然不想日志被清除了。所以可以设置为true
  58. 默认是false,有调试需求的同学可以设置为true。。。非必须设置
  59. ;childlogdir=/tmp ; 当子进程日志路径为AUTO的时候,子进程日志文件的存放路径。
  60. 默认路径是这个东西,执行下面的这个命令看看就OK了,处理的东西就默认路径
  61. python -c "import tempfile;print tempfile.gettempdir()"
  62. 非必须设置
  63. ;environment=KEY="value" ; 这个是用来设置环境变量的,supervisordlinux中启动默认继承了linux
  64. 环境变量,在这里可以设置supervisord进程特有的其他环境变量。
  65. supervisord启动子进程时,子进程会拷贝父进程的内存空间内容。 所以设置的
  66. 这些环境变量也会被子进程继承。
  67. 小例子:environment=name="haha",age="hehe"
  68. 默认为不设置。。。非必须设置
  69. ;strip_ansi=false ; 这个选项如果设置为true,会清除子进程日志中的所有ANSI 序列。什么是ANSI
  70. 序列呢?就是我们的\n,\t这些东西。
  71. 默认为false。。。非必须设置
  72. ; the below section must remain in the config file for RPC
  73. ; (supervisorctl/web interface) to work, additional interfaces may be
  74. ; added by defining them in separate rpcinterface: sections
  75. [rpcinterface:supervisor] ;这个选项是给XML_RPC用的,当然你如果想使用supervisord或者web server
  76. 个选项必须要开启的
  77. supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
  78. [supervisorctl] ;这个主要是针对supervisorctl的一些配置
  79. serverurl=unix:///tmp/supervisor.sock ; 这个是supervisorctl本地连接supervisord的时候,本地UNIX socket
  80. 路径,注意这个是和前面的[unix_http_server]对应的
  81. 默认值就是unix:///tmp/supervisor.sock。。非必须设置
  82. ;serverurl=http://127.0.0.1:9001 ; 这个是supervisorctl远程连接supervisord的时候,用到的TCP socket路径
  83. 注意这个和前面的[inet_http_server]对应
  84. 默认就是http://127.0.0.1:9001。。。非必须项
  85. ;username=chris ; 用户名
  86. 默认空。。非必须设置
  87. ;password=123 ; 密码
  88. 默认空。。非必须设置
  89. ;prompt=mysupervisor ; 输入用户名密码时候的提示符
  90. 默认supervisor。。非必须设置
  91. ;history_file=~/.sc_history ; 这个参数和shell中的history类似,我们可以用上下键来查找前面执行过的命令
  92. 默认是no file的。。所以我们想要有这种功能,必须指定一个文件。。。非
  93. 必须设置
  94. ; The below sample program section shows all possible program subsection values,
  95. ; create one or more 'real' program: sections to be able to control them under
  96. ; supervisor.
  97. ;[program:theprogramname] ;这个就是咱们要管理的子进程了,":"后面的是名字,最好别乱写和实际进程
  98. 有点关联最好。这样的program我们可以设置一个或多个,一个program就是
  99. 要被管理的一个进程
  100. ;command=/bin/cat ; 这个就是我们的要启动进程的命令路径了,可以带参数
  101. 例子:/home/test.py -a 'hehe'
  102. 有一点需要注意的是,我们的command只能是那种在终端运行的进程,不能是
  103. 守护进程。这个想想也知道了,比如说command=service httpd start
  104. httpd这个进程被linuxservice管理了,我们的supervisor再去启动这个命令
  105. 这已经不是严格意义的子进程了。
  106. 这个是个必须设置的项
  107. ;process_name=%(program_name)s ; 这个是进程名,如果我们下面的numprocs参数为1的话,就不用管这个参数
  108. 了,它默认值%(program_name)s也就是上面的那个program冒号后面的名字,
  109. 但是如果numprocs为多个的话,那就不能这么干了。想想也知道,不可能每个
  110. 进程都用同一个进程名吧。
  111. ;numprocs=1 ; 启动进程的数目。当不为1时,就是进程池的概念,注意process_name的设置
  112. 默认为1 。。非必须设置
  113. ;directory=/tmp ; 进程运行前,会前切换到这个目录
  114. 默认不设置。。。非必须设置
  115. ;umask=022 ; 进程掩码,默认none,非必须
  116. ;priority=999 ; 子进程启动关闭优先级,优先级低的,最先启动,关闭的时候最后关闭
  117. 默认值为999 。。非必须设置
  118. ;autostart=true ; 如果是true的话,子进程将在supervisord启动后被自动启动
  119. 默认就是true 。。非必须设置
  120. ;autorestart=unexpected ; 这个是设置子进程挂掉后自动重启的情况,有三个选项,false,unexpected
  121. true。如果为false的时候,无论什么情况下,都不会被重新启动,
  122. 如果为unexpected,只有当进程的退出码不在下面的exitcodes里面定义的退
  123. 出码的时候,才会被自动重启。当为true的时候,只要子进程挂掉,将会被无
  124. 条件的重启
  125. ;startsecs=1 ; 这个选项是子进程启动多少秒之后,此时状态如果是running,则我们认为启
  126. 动成功了
  127. 默认值为1 。。非必须设置
  128. ;startretries=3 ; 当进程启动失败后,最大尝试启动的次数。。当超过3次后,supervisor将把
  129. 此进程的状态置为FAIL
  130. 默认值为3 。。非必须设置
  131. ;exitcodes=0,2 ; 注意和上面的的autorestart=unexpected对应。。exitcodes里面的定义的
  132. 退出码是expected的。
  133. ;stopsignal=QUIT ; 进程停止信号,可以为TERM, HUP, INT, QUIT, KILL, USR1, or USR2等信号
  134. 默认为TERM 。。当用设定的信号去干掉进程,退出码会被认为是expected
  135. 非必须设置
  136. ;stopwaitsecs=10 ; 这个是当我们向子进程发送stopsignal信号后,到系统返回信息
  137. supervisord,所等待的最大时间。 超过这个时间,supervisord会向该
  138. 子进程发送一个强制kill的信号。
  139. 默认为10秒。。非必须设置
  140. ;stopasgroup=false ; 这个东西主要用于,supervisord管理的子进程,这个子进程本身还有
  141. 子进程。那么我们如果仅仅干掉supervisord的子进程的话,子进程的子进程
  142. 有可能会变成孤儿进程。所以咱们可以设置可个选项,把整个该子进程的
  143. 整个进程组都干掉。 设置为true的话,一般killasgroup也会被设置为true
  144. 需要注意的是,该选项发送的是stop信号
  145. 默认为false。。非必须设置。。
  146. ;killasgroup=false ; 这个和上面的stopasgroup类似,不过发送的是kill信号
  147. ;user=chrism ; 如果supervisordroot启动,我们在这里设置这个非root用户,可以用来
  148. 管理该program
  149. 默认不设置。。。非必须设置项
  150. ;redirect_stderr=true ; 如果为true,则stderr的日志会被写入stdout日志文件中
  151. 默认为false,非必须设置
  152. ;stdout_logfile=/a/path ; 子进程的stdout的日志路径,可以指定路径,AUTOnone等三个选项。
  153. 设置为none的话,将没有日志产生。设置为AUTO的话,将随机找一个地方
  154. 生成日志文件,而且当supervisord重新启动的时候,以前的日志文件会被
  155. 清空。当 redirect_stderr=true的时候,sterr也会写进这个日志文件
  156. ;stdout_logfile_maxbytes=1MB ; 日志文件最大大小,和[supervisord]中定义的一样。默认为50
  157. ;stdout_logfile_backups=10 ; 和[supervisord]定义的一样。默认10
  158. ;stdout_capture_maxbytes=1MB ; 这个东西是设定capture管道的大小,当值不为0的时候,子进程可以从stdout
  159. 发送信息,而supervisor可以根据信息,发送相应的event
  160. 默认为0,为0的时候表达关闭管道。。。非必须项
  161. ;stdout_events_enabled=false ; 当设置为ture的时候,当子进程由stdout向文件描述符中写日志的时候,将
  162. 触发supervisord发送PROCESS_LOG_STDOUT类型的event
  163. 默认为false。。。非必须设置
  164. ;stderr_logfile=/a/path ; 这个东西是设置stderr写的日志路径,当redirect_stderr=true。这个就不用
  165. 设置了,设置了也是白搭。因为它会被写入stdout_logfile的同一个文件中
  166. 默认为AUTO,也就是随便找个地存,supervisord重启被清空。。非必须设置
  167. ;stderr_logfile_maxbytes=1MB ; 这个出现好几次了,就不重复了
  168. ;stderr_logfile_backups=10 ; 这个也是
  169. ;stderr_capture_maxbytes=1MB ; 这个一样,和stdout_capture一样。 默认为0,关闭状态
  170. ;stderr_events_enabled=false ; 这个也是一样,默认为false
  171. ;environment=A="1",B="2" ; 这个是该子进程的环境变量,和别的子进程是不共享的
  172. ;serverurl=AUTO ;
  173. ; The below sample eventlistener section shows all possible
  174. ; eventlistener subsection values, create one or more 'real'
  175. ; eventlistener: sections to be able to handle event notifications
  176. ; sent by supervisor.
  177. ;[eventlistener:theeventlistenername] ;这个东西其实和program的地位是一样的,也是suopervisor启动的子进
  178. 程,不过它干的活是订阅supervisord发送的event。他的名字就叫
  179. listener了。我们可以在listener里面做一系列处理,比如报警等等
  180. 楼主这两天干的活,就是弄的这玩意
  181. ;command=/bin/eventlistener ; 这个和上面的program一样,表示listener的可执行文件的路径
  182. ;process_name=%(program_name)s ; 这个也一样,进程名,当下面的numprocs为多个的时候,才需要。否则默认就
  183. OK
  184. ;numprocs=1 ; 相同的listener启动的个数
  185. ;events=EVENT ; event事件的类型,也就是说,只有写在这个地方的事件类型。才会被发送
  186. ;buffer_size=10 ; 这个是event队列缓存大小,单位不太清楚,楼主猜测应该是个吧。当buffer
  187. 超过10的时候,最旧的event将会被清除,并把新的event放进去。
  188. 默认值为10。。非必须选项
  189. ;directory=/tmp ; 进程执行前,会切换到这个目录下执行
  190. 默认为不切换。。。非必须
  191. ;umask=022 ; 淹没,默认为none,不说了
  192. ;priority=-1 ; 启动优先级,默认-1,也不扯了
  193. ;autostart=true ; 是否随supervisord启动一起启动,默认true
  194. ;autorestart=unexpected ; 是否自动重启,和program一个样,分true,false,unexpected等,注意
  195. unexpectedexitcodes的关系
  196. ;startsecs=1 ; 也是一样,进程启动后跑了几秒钟,才被认定为成功启动,默认1
  197. ;startretries=3 ; 失败最大尝试次数,默认3
  198. ;exitcodes=0,2 ; 期望或者说预料中的进程退出码,
  199. ;stopsignal=QUIT ; 干掉进程的信号,默认为TERM,比如设置为QUIT,那么如果QUIT来干这个进程
  200. 那么会被认为是正常维护,退出码也被认为是expected中的
  201. ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
  202. ;stopasgroup=false ; send stop signal to the UNIX process group (default false)
  203. ;killasgroup=false ; SIGKILL the UNIX process group (def false)
  204. ;user=chrism ;设置普通用户,可以用来管理该listener进程。
  205. 默认为空。。非必须设置
  206. ;redirect_stderr=true ; true的话,stderrlog会并入stdoutlog里面
  207. 默认为false。。。非必须设置
  208. ;stdout_logfile=/a/path ; 这个不说了,好几遍了
  209. ;stdout_logfile_maxbytes=1MB ; 这个也是
  210. ;stdout_logfile_backups=10 ; 这个也是
  211. ;stdout_events_enabled=false ; 这个其实是错的,listener是不能发送event
  212. ;stderr_logfile=/a/path ; 这个也是
  213. ;stderr_logfile_maxbytes=1MB ; 这个也是
  214. ;stderr_logfile_backups ; 这个不说了
  215. ;stderr_events_enabled=false ; 这个也是错的,listener不能发送event
  216. ;environment=A="1",B="2" ; 这个是该子进程的环境变量
  217. 默认为空。。。非必须设置
  218. ;serverurl=AUTO ; override serverurl computation (childutils)
  219. ; The below sample group section shows all possible group values,
  220. ; create one or more 'real' group: sections to create "heterogeneous"
  221. ; process groups.
  222. ;[group:thegroupname] ;这个东西就是给programs分组,划分到组里面的program。我们就不用一个一个去操作了
  223. 我们可以对组名进行统一的操作。 注意:program被划分到组里面之后,就相当于原来
  224. 的配置从supervisor的配置文件里消失了。。。supervisor只会对组进行管理,而不再
  225. 会对组里面的单个program进行管理了
  226. ;programs=progname1,progname2 ; 组成员,用逗号分开
  227. 这个是个必须的设置项
  228. ;priority=999 ; 优先级,相对于组和组之间说的
  229. 默认999。。非必须选项
  230. ; The [include] section can just contain the "files" setting. This
  231. ; setting can list multiple files (separated by whitespace or
  232. ; newlines). It can also contain wildcards. The filenames are
  233. ; interpreted as relative to this file. Included files *cannot*
  234. ; include files themselves.
  235. ;[include] ;这个东西挺有用的,当我们要管理的进程很多的时候,写在一个文件里面
  236. 就有点大了。我们可以把配置信息写到多个文件中,然后include过来
  237. ;files = relative/directory/*.ini

原文链接:https://www.cnblogs.com/thankcat/p/18140922

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号