使用supervisor管理tomcat,nginx等进程详解 | 二丫讲梵


本站和网页 https://wiki.eryajf.net/pages/1903.html#_4-%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86-tomcat-%E8%BF%9B%E7%A8%8B%E3%80%82 的作者无关,不对其内容负责。快照谨为网络故障时之索引,不代表被搜索网站的即时页面。

使用supervisor管理tomcat,nginx等进程详解 | 二丫讲梵
二丫讲梵 首页运维 运维 最佳实践 迎刃而解 Nginx Php Zabbix Prometheus Grafana CentOS Systemd Docker Rancker Ansible Ldap Gitlab GitHub Etcd Consul RabbitMQ Kafka MySql MongoDB OpenVPN KVM VMware Other专题 专题 ELK K8S Nexus Jenkins生活 生活 随写编年 家人物语 追忆青春 父亲的朋友圈 电影音乐 效率工具 博客相关编程 编程 Shell 前端实践 Vue学习笔记 Golang学习笔记 Golang编程技巧周刊 周刊 学习周刊 Obsidian插件周刊关于友链推广页面 页面 本站索引 分类标签归档本站页面 导航打赏我的工具
备忘录清单
(opens new window)
网站状态
(opens new window)
json2go
(opens new window)
微信MD编辑
(opens new window)
国内镜像
(opens new window)
出口IP查询
(opens new window)
代码高亮工具
(opens new window)外站页面
开往
(opens new window)
ldapdoc
(opens new window)
HowToStartOpenSource
(opens new window)
vdoing-template
(opens new window)
GitHub
(opens new window) 二丫讲梵 行者常至,为者常成 首页运维 运维 最佳实践 迎刃而解 Nginx Php Zabbix Prometheus Grafana CentOS Systemd Docker Rancker Ansible Ldap Gitlab GitHub Etcd Consul RabbitMQ Kafka MySql MongoDB OpenVPN KVM VMware Other专题 专题 ELK K8S Nexus Jenkins生活 生活 随写编年 家人物语 追忆青春 父亲的朋友圈 电影音乐 效率工具 博客相关编程 编程 Shell 前端实践 Vue学习笔记 Golang学习笔记 Golang编程技巧周刊 周刊 学习周刊 Obsidian插件周刊关于友链推广页面 页面 本站索引 分类标签归档本站页面 导航打赏我的工具
备忘录清单
(opens new window)
网站状态
(opens new window)
json2go
(opens new window)
微信MD编辑
(opens new window)
国内镜像
(opens new window)
出口IP查询
(opens new window)
代码高亮工具
(opens new window)外站页面
开往
(opens new window)
ldapdoc
(opens new window)
HowToStartOpenSource
(opens new window)
vdoing-template
(opens new window)
GitHub
(opens new window) 最佳实践 迎刃而解 Nginx Php Zabbix Prometheus Grafana CentOS Supervisord 使用supervisor管理tomcat,nginx等进程详解1,介绍。2,安装。3,创建主配置。4,配置管理 tomcat 进程。5,启动 supervisor。1,创建 supervisor 服务管理文件。2,加入开机自启。6,开启 web 管理。7,配置文件详解。8,参考文章。Systemd Docker Docker-Compose Rancher Ansible OpenLdap GitLab GitHub Etcd Consul RabbitMQ Kafka Mysql MongoDB OpenVPN Kvm VMware 配置文件详解 Other 运维观止Supervisord 二丫讲梵 2018-10-22 目录 使用supervisor管理tomcat,nginx等进程详解
这篇文章的发布时间较早,其中的内容可能已经过时,阅读时请注意甄别。
# 1,介绍。 官网:http://supervisord.org (opens new window) Supervisor 是用 Python 开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台 daemon,并监控进程状态,异常退出时能自动重启。 它是通过 fork/exec 的方式把这些被管理的进程当作 supervisor 的子进程来启动,这样只要在 supervisor 的配置文件中,把要管理的进程的可执行文件的路径写进去即可。也实现当子进程挂掉的时候,父进程可以准确获取子进程挂掉的信息的,可以选择是否自己启动和报警。supervisor 还提供了一个功能,可以为 supervisord 或者每个子进程,设置一个非 root 的 user,这个 user 就可以管理它对应的进程。 # 2,安装。 这里我推荐使用easy_install的方式安装,因为这种方式安装的自定义性比较强,安装也比较方便,虽然网上有不少地方也介绍 yum 方式的安装,但是据我个人的体验来看,不如这种安装方式来的好。 而且这种方式安装以及使用,是适用于 CentOS-6 以及 CenOS-7 两个大系统版本的。 yum install -y python-setuptools.noarch
easy_install supervisor
12如果两条命令都执行没有问题,就安装成功了。 也可以通过如下指令测试安装是否成功: [root@moban ~]$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 ".
[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=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
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=chrism ; default is current user, required 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,2 ; 'expected' exit codes used with autorestart (default 0,2)
;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)
;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)
;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,2 ; 'expected' exit codes used with autorestart (default 0,2)
;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)
;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)
;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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149# 3,创建主配置。 1,创建 supervisor 配置文件目录 。 mkdir -m 755 -p /etc/supervisor
12,创建主配置文件。 echo_supervisord_conf >/etc/supervisor/supervisord.conf
13,创建项目配置文件目录。 mkdir -m 755 /etc/supervisor/conf.d
1配置文件的详细解析放在最后。 # 4,配置管理 tomcat 进程。 主机上安装的 tomcat 进程,无论怎么操作都无法开机自启动,那么现在有了这个进程管理工具,就可以实现对 tomcat 进程的管理了。 进程管理配置参数,不建议全都写在supervisord.conf文件中,应该每个进程写一个配置文件放在 include 指定的目录下包含进 supervisord.conf 文件中。 所以此时应该先修改一下这个参数: vim /etc/supervisor/supervisord.conf
直接跳到文本最后,删掉前边的注释(分号)。然后更改如下:
[include]
files = /etc/supervisor/conf.d/*.ini
123456然后创建 tomcat 的配置文件。 需要注意的地方 ====》所有要管理的进程都不能开启后台模式,只能使用前台模式进行配置;使用后台模式会出现一直重新开启新进程的情况。 [root@fbtest conf.d]$cat tomcat.ini
[program:tomcat]
command=/usr/local/tomcat/bin/catalina.sh run
stdout_logfile=/usr/local/tomcat/logs/catalina.out
stderr_logfile=/usr/local/tomcat/logs/catalina.out
environment=JAVA_HOME="/usr/local/jdk1.8.0_144",JAVA_BIN="/usr/local/jdk1.8.0_144/bin"
autorestart=false
startsecs=60
priority=1
stopasgroup=true
killasgroup=true
1234567891011注意:我当时写 tomcat 启动命令的时候,使用了 / usr/local/tomcat_adminB/bin/startup.sh 这个命令,结果发现,不知道什么原因,竟然会一次启动四个 tomcat 进程,也是挺诡异的。
还有,因为使用catalina.sh run的方式启动是一种前台的启动方式,因此日志并不会输出到对应的 tomcat 日志里,当中有两句定义日志的指令,其中生效的是stderr_logfile,也就是说,是这条指令,使得尽管我们在前台启动的 tomcat 应用,依然会将日志输出到catalina.out里边。 还可以创建一个管理 nginx 的配置文件(也是要关闭后台模式,在执行的命令后面添加 - g “daemon off;”)。 [root@fbtest conf.d]$cat nginx.ini
[program:nginx]
command=/usr/local/nginx/sbin/nginx -g 'daemon off;'
priority=1000
autostart=true
startretries=3
autorestart=true
user=root
12345678还可以创建更多的管理服务的文件,这些配置依据文末的讲解,都可以非常容易的配置出来,不过有一些属性则需要自己去进行调试,然后来适应实际的工作需求,比如我在配置 tomcat 的配置时,就把自动重启的功能给关闭了,因为在测试环境需要经常发布,发布就免不了重启服务,如果这个地方开启自动重启,那么很容易会在发布的时候出现各种意想不到的情况。 # 5,启动 supervisor。 通过启动命令加载配置文件。 supervisord -c /etc/supervisor/supervisord.conf
[root@moban ~]$supervisorctl
tomcat FATAL Exited too quickly (process log may have details)
supervisor>
1234如果此时报错,那么 google 一下报的错误,很容易解决。 以上两个命令说明: supervisord : supervisor 的服务器端部分,用于 supervisor 启动。 supervisorctl:启动 supervisor 的命令行窗口,在该命令行中可执行 start、stop、status、reload 等操作。 注意:每次修改配置文件后需进入 supervisorctl,执行 reload, 改动部分才能生效。 # 1,创建 supervisor 服务管理文件。 此时可以通过查看 tomcat 的日志,来判断,是否启动成功,也可以通过重启服务器,来检验,是否生效。 估计重启服务器还不行,因为还没有添加 supervisor 进程的开机自启。 这个地方因为 CentOS 版本升级之后对服务的管理方式不同,因此创建的方式也不一样,我这里分别列出来。 1,如果是 CentOS-7。 进入 / lib/systemd/system 目录,并创建 supervisord.service 文件。 [root@moban ~]$cat /lib/systemd/system/supervisord.service
[Unit]
Description=supervisord
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
12345678910111213141516172,如果是 CenOS6。 [root@moban ~]$cat /etc/rc.d/init.d/supervisord
#!/bin/bash
# supervisord This scripts turns supervisord on
# Author: Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
# chkconfig: - 95 04
# description: supervisor is a process control utility. It has a web based
# xmlrpc interface as well as a few other nifty features.
# processname: supervisord
# config: /etc/supervisord.conf
# pidfile: /var/run/supervisord.pid
# source function library
. /etc/rc.d/init.d/functions
RETVAL=0
start() {
echo -n $"Starting supervisord: "
daemon "supervisord -c /etc/supervisor/supervisord.conf"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/supervisord
stop() {
echo -n $"Stopping supervisord: "
killproc supervisord
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/supervisord
restart() {
stop
start
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload|reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/supervisord ] && restart
;;
status)
status supervisord
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
exit 1
esac
exit $RETVAL
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465# 2,加入开机自启。 1,如果是 CentOS-7。 chmod 766 /lib/systemd/system/supervisord.service
systemctl daemon-reload
systemctl enable supervisord.service
systemctl start supervisord
systemctl status supervisord
123452,如果是 CenOS6。 chkconfig supervisord on
1# 6,开启 web 管理。 一般情况都是使用 supervisorctl 在命令行进行管理,不过也可以玩一下开启 web 管理,然后再关掉就好了。 编辑配置文件: vim /etc/supervisor/supervisord.conf
;[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))
修改成:
[inet_http_server] ; inet (TCP) server disabled by default
port=192.168.157.182: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))
port:绑定访问IP和端口,这里是绑定的是本机IP和9001端口(写上你自己的服务器IP或是本地IP)
username:登录管理后台的用户名
password:登录管理后台的密码
1234567891011121314151617访问一下: # 7,配置文件详解。 [unix_http_server]
file=/tmp/supervisor.sock ; socket文件的路径,supervisorctl用XML_RPC和supervisord通信就是通过它进行
的。如果不设置的话,supervisorctl也就不能用了
不设置的话,默认为none。 非必须设置
;chmod=0700 ; 这个简单,就是修改上面的那个socket文件的权限为0700
不设置的话,默认为0700。 非必须设置
;chown=nobody:nogroup ; 这个一样,修改上面的那个socket文件的属组为user.group
不设置的话,默认为启动supervisord进程的用户及属组。非必须设置
;username=user ; 使用supervisorctl连接的时候,认证的用户
不设置的话,默认为不需要用户。 非必须设置
;password=123 ; 和上面的用户名对应的密码,可以直接使用明码,也可以使用SHA加密
如:{SHA}82ab876d1387bfafe46cc1c8a2ef074eae50cb1d
默认不设置。。。非必须设置
;[inet_http_server] ; 侦听在TCP上的socket,Web Server和远程的supervisorctl都要用到他
不设置的话,默认为不开启。非必须设置
;port=127.0.0.1:9001 ; 这个是侦听的IP和端口,侦听所有IP用 :9001或*:9001。
这个必须设置,只要上面的[inet_http_server]开启了,就必须设置它
;username=user ; 这个和上面的uinx_http_server一个样。非必须设置
;password=123 ; 这个也一个样。非必须设置
[supervisord] ;这个主要是定义supervisord这个服务端进程的一些参数的
这个必须设置,不设置,supervisor就不用干活了
logfile=/tmp/supervisord.log ; 这个是supervisord这个主进程的日志路径,注意和子进程的日志不搭嘎。
默认路径$CWD/supervisord.log,$CWD是当前目录。。非必须设置
logfile_maxbytes=50MB ; 这个是上面那个日志文件的最大的大小,当超过50M的时候,会生成一个新的日
志文件。当设置为0时,表示不限制文件大小
默认值是50M,非必须设置。
logfile_backups=10 ; 日志文件保持的数量,上面的日志文件大于50M时,就会生成一个新文件。文件
数量大于10时,最初的老文件被新文件覆盖,文件数量将保持为10
当设置为0时,表示不限制文件的数量。
默认情况下为10。。。非必须设置
loglevel=info ; 日志级别,有critical, error, warn, info, debug, trace, or blather等
默认为info。。。非必须设置项
pidfile=/tmp/supervisord.pid ; supervisord的pid文件路径。
默认为$CWD/supervisord.pid。。。非必须设置
nodaemon=false ; 如果是true,supervisord进程将在前台运行
默认为false,也就是后台以守护进程运行。。。非必须设置
minfds=1024 ; 这个是最少系统空闲的文件描述符,低于这个值supervisor将不会启动。
系统的文件描述符在这里设置cat /proc/sys/fs/file-max
默认情况下为1024。。。非必须设置
minprocs=200 ; 最小可用的进程描述符,低于这个值supervisor也将不会正常启动。
ulimit -u这个命令,可以查看linux下面用户的最大进程数
默认为200。。。非必须设置
;umask=022 ; 进程创建文件的掩码
默认为022。。非必须设置项
;user=chrism ; 这个参数可以设置一个非root用户,当我们以root用户启动supervisord之后。
我这里面设置的这个用户,也可以对supervisord进行管理
默认情况是不设置。。。非必须设置项
;identifier=supervisor ; 这个参数是supervisord的标识符,主要是给XML_RPC用的。当你有多个
supervisor的时候,而且想调用XML_RPC统一管理,就需要为每个
supervisor设置不同的标识符了
默认是supervisord。。。非必需设置
;directory=/tmp ; 这个参数是当supervisord作为守护进程运行的时候,设置这个参数的话,启动
supervisord进程之前,会先切换到这个目录
默认不设置。。。非必须设置
;nocleanup=true ; 这个参数当为false的时候,会在supervisord进程启动的时候,把以前子进程
产生的日志文件(路径为AUTO的情况下)清除掉。有时候咱们想要看历史日志,当
然不想日志被清除了。所以可以设置为true
默认是false,有调试需求的同学可以设置为true。。。非必须设置
;childlogdir=/tmp ; 当子进程日志路径为AUTO的时候,子进程日志文件的存放路径。
默认路径是这个东西,执行下面的这个命令看看就OK了,处理的东西就默认路径
python -c "import tempfile;print tempfile.gettempdir()"
非必须设置
;environment=KEY="value" ; 这个是用来设置环境变量的,supervisord在linux中启动默认继承了linux的
环境变量,在这里可以设置supervisord进程特有的其他环境变量。
supervisord启动子进程时,子进程会拷贝父进程的内存空间内容。 所以设置的
这些环境变量也会被子进程继承。
小例子:environment=name="haha",age="hehe"
默认为不设置。。。非必须设置
;strip_ansi=false ; 这个选项如果设置为true,会清除子进程日志中的所有ANSI 序列。什么是ANSI
序列呢?就是我们的\n,\t这些东西。
默认为false。。。非必须设置
; the below 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: sections
[rpcinterface:supervisor] ;这个选项是给XML_RPC用的,当然你如果想使用supervisord或者web server 这
个选项必须要开启的
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl] ;这个主要是针对supervisorctl的一些配置
serverurl=unix:///tmp/supervisor.sock ; 这个是supervisorctl本地连接supervisord的时候,本地UNIX socket
路径,注意这个是和前面的[unix_http_server]对应的
默认值就是unix:///tmp/supervisor.sock。。非必须设置
;serverurl=http://127.0.0.1:9001 ; 这个是supervisorctl远程连接supervisord的时候,用到的TCP socket路径
注意这个和前面的[inet_http_server]对应
默认就是http://127.0.0.1:9001。。。非必须项
;username=chris ; 用户名
默认空。。非必须设置
;password=123 ; 密码
默认空。。非必须设置
;prompt=mysupervisor ; 输入用户名密码时候的提示符
默认supervisor。。非必须设置
;history_file=~/.sc_history ; 这个参数和shell中的history类似,我们可以用上下键来查找前面执行过的命令
默认是no file的。。所以我们想要有这种功能,必须指定一个文件。。。非
必须设置
; The below sample program section shows all possible program subsection values,
; create one or more 'real' program: sections to be able to control them under
; supervisor.
;[program:theprogramname] ;这个就是咱们要管理的子进程了,":"后面的是名字,最好别乱写和实际进程
有点关联最好。这样的program我们可以设置一个或多个,一个program就是
要被管理的一个进程
;command=/bin/cat ; 这个就是我们的要启动进程的命令路径了,可以带参数
例子:/home/test.py -a 'hehe'
有一点需要注意的是,我们的command只能是那种在终端运行的进程,不能是
守护进程。这个想想也知道了,比如说command=service httpd start。
httpd这个进程被linux的service管理了,我们的supervisor再去启动这个命令
这已经不是严格意义的子进程了。
这个是个必须设置的项
;process_name=%(program_name)s ; 这个是进程名,如果我们下面的numprocs参数为1的话,就不用管这个参数
了,它默认值%(program_name)s也就是上面的那个program冒号后面的名字,
但是如果numprocs为多个的话,那就不能这么干了。想想也知道,不可能每个
进程都用同一个进程名吧。
;numprocs=1 ; 启动进程的数目。当不为1时,就是进程池的概念,注意process_name的设置
默认为1 。。非必须设置
;directory=/tmp ; 进程运行前,会前切换到这个目录
默认不设置。。。非必须设置
;umask=022 ; 进程掩码,默认none,非必须
;priority=999 ; 子进程启动关闭优先级,优先级低的,最先启动,关闭的时候最后关闭
默认值为999 。。非必须设置
;autostart=true ; 如果是true的话,子进程将在supervisord启动后被自动启动
默认就是true 。。非必须设置
;autorestart=unexpected ; 这个是设置子进程挂掉后自动重启的情况,有三个选项,false,unexpected
和true。如果为false的时候,无论什么情况下,都不会被重新启动,
如果为unexpected,只有当进程的退出码不在下面的exitcodes里面定义的退
出码的时候,才会被自动重启。当为true的时候,只要子进程挂掉,将会被无
条件的重启
;startsecs=1 ; 这个选项是子进程启动多少秒之后,此时状态如果是running,则我们认为启
动成功了
默认值为1 。。非必须设置
;startretries=3 ; 当进程启动失败后,最大尝试启动的次数。。当超过3次后,supervisor将把
此进程的状态置为FAIL
默认值为3 。。非必须设置
;exitcodes=0,2 ; 注意和上面的的autorestart=unexpected对应。。exitcodes里面的定义的
退出码是expected的。
;stopsignal=QUIT ; 进程停止信号,可以为TERM, HUP, INT, QUIT, KILL, USR1, or USR2等信号
默认为TERM 。。当用设定的信号去干掉进程,退出码会被认为是expected
非必须设置
;stopwaitsecs=10 ; 这个是当我们向子进程发送stopsignal信号后,到系统返回信息
给supervisord,所等待的最大时间。 超过这个时间,supervisord会向该
子进程发送一个强制kill的信号。
默认为10秒。。非必须设置
;stopasgroup=false ; 这个东西主要用于,supervisord管理的子进程,这个子进程本身还有
子进程。那么我们如果仅仅干掉supervisord的子进程的话,子进程的子进程
有可能会变成孤儿进程。所以咱们可以设置可个选项,把整个该子进程的
整个进程组都干掉。 设置为true的话,一般killasgroup也会被设置为true。
需要注意的是,该选项发送的是stop信号
默认为false。。非必须设置。。
;killasgroup=false ; 这个和上面的stopasgroup类似,不过发送的是kill信号
;user=chrism ; 如果supervisord是root启动,我们在这里设置这个非root用户,可以用来
管理该program
默认不设置。。。非必须设置项
;redirect_stderr=true ; 如果为true,则stderr的日志会被写入stdout日志文件中
默认为false,非必须设置
;stdout_logfile=/a/path ; 子进程的stdout的日志路径,可以指定路径,AUTO,none等三个选项。
设置为none的话,将没有日志产生。设置为AUTO的话,将随机找一个地方
生成日志文件,而且当supervisord重新启动的时候,以前的日志文件会被
清空。当 redirect_stderr=true的时候,sterr也会写进这个日志文件
;stdout_logfile_maxbytes=1MB ; 日志文件最大大小,和[supervisord]中定义的一样。默认为50
;stdout_logfile_backups=10 ; 和[supervisord]定义的一样。默认10
;stdout_capture_maxbytes=1MB ; 这个东西是设定capture管道的大小,当值不为0的时候,子进程可以从stdout
发送信息,而supervisor可以根据信息,发送相应的event。
默认为0,为0的时候表达关闭管道。。。非必须项
;stdout_events_enabled=false ; 当设置为ture的时候,当子进程由stdout向文件描述符中写日志的时候,将
触发supervisord发送PROCESS_LOG_STDOUT类型的event
默认为false。。。非必须设置
;stderr_logfile=/a/path ; 这个东西是设置stderr写的日志路径,当redirect_stderr=true。这个就不用
设置了,设置了也是白搭。因为它会被写入stdout_logfile的同一个文件中
默认为AUTO,也就是随便找个地存,supervisord重启被清空。。非必须设置
;stderr_logfile_maxbytes=1MB ; 这个出现好几次了,就不重复了
;stderr_logfile_backups=10 ; 这个也是
;stderr_capture_maxbytes=1MB ; 这个一样,和stdout_capture一样。 默认为0,关闭状态
;stderr_events_enabled=false ; 这个也是一样,默认为false
;environment=A="1",B="2" ; 这个是该子进程的环境变量,和别的子进程是不共享的
;serverurl=AUTO ;
; The below sample eventlistener section shows all possible
; eventlistener subsection values, create one or more 'real'
; eventlistener: sections to be able to handle event notifications
; sent by supervisor.
;[eventlistener:theeventlistenername] ;这个东西其实和program的地位是一样的,也是suopervisor启动的子进
程,不过它干的活是订阅supervisord发送的event。他的名字就叫
listener了。我们可以在listener里面做一系列处理,比如报警等等
楼主这两天干的活,就是弄的这玩意
;command=/bin/eventlistener ; 这个和上面的program一样,表示listener的可执行文件的路径
;process_name=%(program_name)s ; 这个也一样,进程名,当下面的numprocs为多个的时候,才需要。否则默认就
OK了
;numprocs=1 ; 相同的listener启动的个数
;events=EVENT ; event事件的类型,也就是说,只有写在这个地方的事件类型。才会被发送
;buffer_size=10 ; 这个是event队列缓存大小,单位不太清楚,楼主猜测应该是个吧。当buffer
超过10的时候,最旧的event将会被清除,并把新的event放进去。
默认值为10。。非必须选项
;directory=/tmp ; 进程执行前,会切换到这个目录下执行
默认为不切换。。。非必须
;umask=022 ; 淹没,默认为none,不说了
;priority=-1 ; 启动优先级,默认-1,也不扯了
;autostart=true ; 是否随supervisord启动一起启动,默认true
;autorestart=unexpected ; 是否自动重启,和program一个样,分true,false,unexpected等,注意
unexpected和exitcodes的关系
;startsecs=1 ; 也是一样,进程启动后跑了几秒钟,才被认定为成功启动,默认1
;startretries=3 ; 失败最大尝试次数,默认3
;exitcodes=0,2 ; 期望或者说预料中的进程退出码,
;stopsignal=QUIT ; 干掉进程的信号,默认为TERM,比如设置为QUIT,那么如果QUIT来干这个进程
那么会被认为是正常维护,退出码也被认为是expected中的
;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 ;设置普通用户,可以用来管理该listener进程。
默认为空。。非必须设置
;redirect_stderr=true ; 为true的话,stderr的log会并入stdout的log里面
默认为false。。。非必须设置
;stdout_logfile=/a/path ; 这个不说了,好几遍了
;stdout_logfile_maxbytes=1MB ; 这个也是
;stdout_logfile_backups=10 ; 这个也是
;stdout_events_enabled=false ; 这个其实是错的,listener是不能发送event
;stderr_logfile=/a/path ; 这个也是
;stderr_logfile_maxbytes=1MB ; 这个也是
;stderr_logfile_backups ; 这个不说了
;stderr_events_enabled=false ; 这个也是错的,listener不能发送event
;environment=A="1",B="2" ; 这个是该子进程的环境变量
默认为空。。。非必须设置
;serverurl=AUTO ; override serverurl computation (childutils)
; The below sample group section shows all possible group values,
; create one or more 'real' group: sections to create "heterogeneous"
; process groups.
;[group:thegroupname] ;这个东西就是给programs分组,划分到组里面的program。我们就不用一个一个去操作了
我们可以对组名进行统一的操作。 注意:program被划分到组里面之后,就相当于原来
的配置从supervisor的配置文件里消失了。。。supervisor只会对组进行管理,而不再
会对组里面的单个program进行管理了
;programs=progname1,progname2 ; 组成员,用逗号分开
这个是个必须的设置项
;priority=999 ; 优先级,相对于组和组之间说的
默认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] ;这个东西挺有用的,当我们要管理的进程很多的时候,写在一个文件里面
就有点大了。我们可以把配置信息写到多个文件中,然后include过来
;files = relative/directory/*.ini
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481# 8,参考文章。 网上文章千千万万,任何教了自己的,都是一种缘分。 https://blog.csdn.net/StriverFeng/article/details/80057304 https://blog.csdn.net/xieliaowa9231/article/details/79077873 https://www.jb51.net/article/118045.htm https://blog.csdn.net/donggege214/article/details/80264811
打赏
上次更新: 2022/08/19, 09:49:20
为什么不建议Linux用root登陆或启动服务 CentOS7主机使用systemd管理应用→
最近更新 01
openLDAP入门系列笔记第三篇--ldapsearch查询语法整理入门
02-2002
Vuepress项目编译时报routines的错误
02-1803
学习周刊-总第94期-2023年第07周
02-17 更多文章>
Theme by
Vdoing
| Copyright © 2017-2023
| | 浙ICP备18057030号
跟随系统
浅色模式
深色模式
阅读模式