supervisord安装使用

Title
supervisord安装使用
Date
May 14, 2023

supervisord简介:

supervisord是一个c/s模式的进程管理程序,它可以用来监控应用程序的进程,并且可以管理应用程序的start/stop/restart/reload等功能。

安装supervisord:

root@dokcer:~# apt-get install supervisord -y #apt安装supervisord root@dokcer:~# supervisord -v #supervisord版本 3.3.1
supervisord配置文件:
supervisord配置文件默认路径:/etc/supervisor/supervisord.conf root@dokcer:~# vim /etc/supervisor/supervisord.conf ; supervisor config file [unix_http_server] file=/var/run/supervisor.sock ; (the path to the socket file) chmod=0700 ; sockef file mode (default 0700) [supervisord] logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP) ; 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] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket ; 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 = /etc/supervisor/conf.d/*.conf #进程监控配置路径 [inet_http_server] #web页面端口 port=*:9080 #web页面地址:9080或*:9080 username=admin #web页面的用户名和密码 password=admin
supervisord监控进程配置文件:
#配置监控的应用程序: root@dokcer:~# vim /etc/supervisor/conf.d/prometheus.conf #用户程序为prometheus [program:prometheus] #启动命令,不能使用nohup等后台运行命令否则应用程序会无限重启 command=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml autostart=true #自动启动 autorestart=true #自动重启 process_name=prometheus #进程名称 startretries=5 #尝试启动的次数

启动supervisord程序:

root@dokcer:~# systemctl start supervisor.service #
打开http://IP:9080,输入用户名和密码就可以在web页面查看监控的应用程序:
notion image

supervisordctl命令行

命令
参数
作用
supervisorctl
stop program:name
停止配置文件中的某个应用程序
supervisorctl
start program:name
启动配置文件中的某个应用程序
supervisorctl
restart program:name
重启配置文件中的某个应用程序
supervisorctl
stop all
停止全部进程
supervisorctl
update
载入新配置文件启动,没有改变就不重启进程
supervisorctl
tail program:name
查看应用程序的日志
root@dokcer:~# supervisorctl start prometheus prometheus: started root@dokcer:~# supervisorctl stop prometheus prometheus: stopped root@dokcer:~#
Built with Potion.so