监控进程状态 2022-08-22 09:42 • 阅读:次 ![](/uploadfiles/image/202208/3.png) ## Supervisor > 安装 ```bash yum install supervisor ``` > 设置开机启动 ```bash systemctl enable supervisord.service ``` > 查看是否在运行 ```bash ps -ef | grep supervisord ``` > 启动 ```bash supervisord -c /etc/supervisord.conf ``` > 开机启动 ```bash vi /etc/rc.d/init.d/supervisor -------------------------------------------------------------------------- #!/bin/bash # # supervisord This scripts turns supervisord on # # Author: Mike McGrath (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/supervisor/supervisord.conf # pidfile: /var/run/supervisord.pid # # source function library #. /etc/rc.d/init.d/functions RETVAL=0 start() { echo -n $"Starting supervisord: " daemon "/usr/bin/supervisorctl reload" 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 -------------------------------------------------------------------------- chmod 755 /etc/rc.d/init.d/supervisor chkconfig supervisor on systemctl list-unit-files systemctl is-enabled supervisord chkconfig --list | grep supervisord chkconfig --del supervisord ``` > 设置访问 ```bash [inet_http_server] // 把分好去掉 port=127.0.0.1:9001 // 设置访问的地址 username=user // 设置用户名 password=123 // 设置密码 ``` > 配置监控项目 ```bash /etc/supervisord.d/ [program:name] // name 进程名字 user=root command= // 执行命令 process_name=%(program_name)s autostart=true autorestart=true stderr_logfile=/_stderr.log stdout_logfile=/_stdout.log ``` > 服务管理 ```bash supervisorctl reload # 从新启动 supervisorctl status supervisorctl start(restart|stop|start) XXX # XXX 某个进程 ``` > 报错 ```bash 1. Error: Cannot open an HTTP server: socket.error reported errno.ENOENT (2) 解决: 查看 /etc/supervisord.conf 下的【unix_http_server】 file 配置路径 然后在去配置路径下查看是否有此目录,没有创建即可 【file=/var/run/supervisor/supervisor.sock ; (the path to the socket file)】 ```