当前位置:网站首页>Supervisor 安装与使用
Supervisor 安装与使用
2022-07-27 08:29:00 【公博义】
1. 简介
Supervisor 的服务器端称为 supervisord,主要负责在启动自身时启动管理的子进程,响应客户端的命令,重启崩溃或退出的子进程,记录子进程 stdout 和 stderr 输出,生成和处理子进程生命周期中的事件。可以在一个配置文件中配置相关参数,包括 Supervisord 自身的状态,其管理的各个子进程的相关属性。配置文件一般位于 /etc/supervisord.conf。
Supervisor 的客户端称为 supervisorctl,它提供了一个类 shell 的接口(即命令行)来使用 supervisord 服务端提供的功能。通过 supervisorctl,用户可以连接到 supervisord 服务器进程,获得服务器进程控制的子进程的状态,启动和停止子进程,获得正在运行的进程列表。客户端通过 Unix 域套接字或者 TCP 套接字与服务端进行通信,服务器端具有身份凭证认证机制,可以有效提升安全性。当客户端和服务器位于同一台机器上时,客户端与服务器共用同一个配置文件 /etc/supervisord.conf,通过不同标签来区分两者的配置。
安装要求
- Supervisor 可以运行在大多数 Unix 系统上,但不支持在 Windows 系统上运行。
- Supervisor 需要 Python2.4 及以上版本,但任何 Python3 版本都不支持。
- 建议安装 Supervisor3.0 及以上版本。
2. 离线安装
cd /usr/local/src
wget https://pypi.python.org/packages/7b/17/88adf8cb25f80e2bc0d18e094fcd7ab300632ea00b601cbbbb84c2419eae/supervisor-3.3.2.tar.gz
# wget http://49.232.8.65/supervisor/supervisor-3.3.2.tar.gz
tar -zxvf supervisor-3.3.2.tar.gz
cd supervisor-3.3.2
python setup.py install #本地python版本为python2.7
# python2.7 setup.py install #本地python版本为python3以上
3. 在线安装
yum install epel-release -y && yum clean all && yum makecache
yum install -y supervisor
启动 supervisor
[[email protected] ~]#/usr/bin/python2 /usr/bin/supervisord -c /etc/supervisord.conf
[[email protected] ~]#supervisorctl
supervisor>
......
注册系统服务
cat > /usr/lib/systemd/system/supervisord.service << EOF [Unit] Description=Process Monitoring and Control Daemon After=rc-local.service nss-user-lookup.target [Service] Type=forking ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf [Install] WantedBy=multi-user.target EOF
# -------------------------------
ps aux|grep supervisord | head -n 1 | awk '{print $2}' | xargs kill -9
systemctl daemon-reload && systemctl restart supervisord && systemctl enable supervisord
systemctl status supervisord
4. supervisor 配置文件
supervisor 配置文件:/etc/supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock #UNIX socket 文件,supervisorctl 会使用
chmod=0700 #socket文件的mode,默认是0700
chown=nobody:nogroup #socket文件的owner,格式:uid:gid
[inet_http_server] #HTTP服务器,提供web管理界面
port=127.0.0.1:9001 #Web管理后台运行的IP和端口,如果开放到公网,需要注意安全性
username=user #登录管理后台的用户名
password=123 #登录管理后台的密码
[supervisord]
logfile=/tmp/supervisord.log #日志文件,默认是 $CWD/supervisord.log
logfile_maxbytes=50MB #日志文件大小,超出会rotate,默认 50MB,如果设成0,表示不限制大小
logfile_backups=10 #日志文件保留备份数量默认10,设为0表示不备份
loglevel=info #日志级别,默认info,其它: debug,warn,trace
pidfile=/tmp/supervisord.pid #pid 文件
nodaemon=false #是否在前台启动,默认是false,即以 daemon 的方式启动
minfds=1024 #可以打开的文件描述符的最小值,默认 1024
minprocs=200 #可以打开的进程数的最小值,默认 200
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock #通过UNIX socket连接supervisord,路径与unix_http_server部分的file一致
serverurl=http://127.0.0.1:9001 #通过HTTP的方式连接supervisord
#包含其它配置文件
[include]
files = relative/directory/*.ini #可以指定一个或多个以.ini结束的配置文件
5. 子进程配置文件
路径:/etc/supervisord.d/
给需要管理的子进程(程序)编写一个配置文件,放在 /etc/supervisor.d/ 目录下,以 .ini 作为扩展名(每个进程的配置文件都可以单独分拆也可以把相关的脚本放一起)
[include]
files = supervisord.d/*.ini /zcm/supervisor/*.ini
[email protected][/zcm/supervisor]#ls
nms-node-exporter.ini zcm-config.ini.bak zcm-env-base.profile zcm-env-cluster.profile zcm-env.profile zcm-file-manager.ini.bak zcm-node-proxy.ini
[email protected][/zcm/supervisor]#cat zcm-node-proxy.ini
[program:zcm-node-proxy]
command=/bin/bash -c \
'. /zcm/supervisor/zcm-env.profile; \ [ `docker ps -a -f "name=zcm-node-proxy"| wc -l` -gt 1 ] && \ exec docker start -a zcm-node-proxy || \ docker run --name zcm-node-proxy \ -v /zcm/node-proxy/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf \ -v /run/containerd:/run/containerd \ --restart=on-failure:5 \ --memory=512M \ --net=host \ -e CLOUD_APP_NAME=paas_zcm-node-proxy \ -v /etc/localtime:/etc/localtime:ro \ -v /etc/timezone:/etc/timezone:ro \ -v /tmp/zlogs:/tmp/zlogs \ -v /tmp/zcore:/tmp/zcore \ -d \ ${ZCM_HARBOR}/zcm9/zcm-openresty:${ZCM_NODE_PROXY_TAG}; \ exec docker start -a zcm-node-proxy'
process_name= zcm-node-proxy
numprocs=1
autostart=true
autorestart=true
startretries = 6
user=root
stdout_logfile=/var/log/zcm/zcm-node-proxy.log
stdout_logfile_maxbytes=10MB
stderr_logfile=/var/log/zcm/zcm-node-proxy.log
stderr_logfile_maxbytes=10MB
stopwaitsecs=20
[email protected][/root]#supervisorctl status
nms-node-exporter RUNNING pid 13581, uptime 63 days, 9:15:53
zcm-node-proxy RUNNING pid 13868, uptime 63 days, 9:15:52
6. supervisor 命令说明
supervisord //启动supervisord
supervisorctl shutdown //停止supervisord
supervisorctl status //查看所有进程的状态
supervisorctl stop es //停止es
supervisorctl start es //启动es
supervisorctl restart es //重启es
supervisorctl update //配置文件修改后使用该命令加载新的配置
supervisorctl reload //重新启动配置中的所有程序
supervisorctl start all //启动supervisord管理的所有进程
supervisorctl stop all //停止supervisord管理的所有进程
supervisorctl restart all //重启所有进程
直接输入 supervisorctl 进入 supervisorctl 的 shell 交互界面,此时上面的命令不带 supervisorctl 可直接使用。
示例
supervisorctl status
supervisorctl stop nginx-gateway
supervisorctl remove nginx-gateway
supervisorctl update nginx-gateway
supervisorctl status
docker logs -f nginx-gateway --tail=200
边栏推荐
- Local Oracle reported ora-12514: tns: the listener cannot recognize the requested service at present
- Dormitory access control system made by imitating the boss (III)
- One book 1201 Fibonacci sequence
- Realization of backstage brand management function
- Login to homepage function implementation
- How to uninstall -- Qianxin secure terminal management system
- Notes in "PHP Basics" PHP
- [BJDCTF2020]EasySearch 1
- QPushButton 按钮的创建与简单应用
- 百人参与,openGauss开源社区这群人都在讨论什么?
猜你喜欢

ERP生产作业控制 华夏

"Intermediate and advanced test questions": what is the implementation principle of mvcc?

海量数据肖枫:共建共治openGauss根社区,共享欣欣向荣新生态

Massive data Xiao Feng: jointly build and govern opengauss root community and share a thriving new ecosystem

Element display mode: block level, inline, inline block, nesting specification, display mode conversion

File name wildcard rules for kettle

Login to homepage function implementation
![[ciscn2019 southeast China division]web11 1](/img/94/61ad4f6cbbd46ff66f361462983d7a.png)
[ciscn2019 southeast China division]web11 1

Leetcode54. Spiral matrix

众昂矿业:新能源行业快速发展,氟化工产品势头强劲
随机推荐
PHP realizes data interaction with MySQL
阿里云国际版回执消息简介与配置流程
Opengauss stopped from the library and found that the main library could not write data
You may need an additional loader to handle the result of these loaders.
[pytorch] resnet18, resnet20, resnet34, resnet50 network structure and Implementation
Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
Fluent rendering mechanism - GPU thread rendering
Explain cache consistency and memory barrier
ERP生产作业控制 华夏
JS rotation chart
Prevent cookies from modifying ID to cheat login
Node installation and debugging
众昂矿业:新能源行业快速发展,氟化工产品势头强劲
One book 1201 Fibonacci sequence
虚拟机克隆
openGauss之TryMe初体验
开怀一笑
Vcenter7.0 managing esxi7.0 hosts
[geek challenge 2019] finalsql 1
First experience of tryme in opengauss