1、安装Supervisor
[root@localhost ~]# yum -y install supervisor
[root@localhost ~]# systemctl start supervisord
[root@localhost ~]# systemctl enable supervisord
2、应用Supervisor管理Python进程
#安装Python环境
[root@localhost ~]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ openssl-devel zlib zlib-devel python3 python3-devel -y
#安装Django
[root@localhost ~]# pip3 install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade pip
[root@localhost ~]# pip3 install -i https://mirrors.aliyun.com/pypi/simple/ django==2.1.8
[root@localhost ~]# django-admin.py startproject demosite
[root@localhost ~]# cd demosite/demosite/
#修改Django访问权限
[root@localhost demosite]# sed -i 's/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = \["*"\]/g' settings.py
#编写Supervisor管理Python的ini配置文件
[root@localhost ~]# cat /etc/supervisord.d/django.ini
[program:django-python]
direct=/root/demosite
command=/bin/bash -c "python3 /root/demosite/manage.py runserver 0.0.0.0:8002"
autostart=true
autorestart=true
stdout_logfile=/var/log/django_stdout.log
stderr_logfile=/var/log/django_stderr.log
user=root
stopsignal=TERM
startsecs=5
startretries=3
stopasgroup=true
killasgroup=true
#重新加载Supervisor的配置文件
[root@localhost ~]# supervisorctl update
#查看Supervisor管理的Python进程状态
[root@localhost ~]# supervisorctl
django-python RUNNING pid 13332, uptime 0:00:15
3、应用Supervisor管理JAVA进程
#安装Java环境
[root@localhost ~]# yum -y install java
[root@localhost ~]# wget https://gitee.com/chejiangyi/dingding-sonar/repository/archive/master.zip
[root@localhost ~]# unzip master.zip
[root@localhost ~]# cd dingding-sonar/releases/
[root@localhost releases]# ll
total 18724
-rw-r--r--. 1 root root 19172474 Sep 17 2020 dingding-sonar-1.0-SNAPSHOT.jar
#编写Supervisor管理Java的init配置文件,进行自动化管理
[root@localhost ~]# cat /etc/supervisord.d/sonar_dingding.ini
[program:sonar-dingding]
directory=/root/dingding-sonar/releases
command=/bin/bash -c "java -jar dingding-sonar-1.0-SNAPSHOT.jar --server.port=8082"
autostart=true
autorestart=true
stderr_logfile=/var/log/sonar_dingding_stderr.log
stdout_logfile=/var/log/sonar_dingding_stdout.log
user=root
stopsignal=QUIT
startsecs=10
startretries=5
stopasgroup=true
killasgroup=true
#重新加载Supervisor的配置文件
[root@localhost ~]# supervisorctl update
#查看Supervisor管理的Java进程的状态
[root@localhost ~]# supervisorctl
django-python RUNNING pid 13332, uptime 0:09:54
sonar-dingding RUNNING pid 13256, uptime 0:36:47
4、配置SupervisorWeb管理页面
#编辑Supervisor的主配置文件
[root@localhost ~]# cat /etc/supervisord.conf | grep inet_http_server -A 3
[inet_http_server] ; inet (TCP) server disabled by default
port=192.168.92.200: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))
#重启Supervisor重新加载主配置文件
[root@localhost ~]# systemctl restart supervisord
5、通过访问SupervisorWeb页面,管理进程
6、Supervisor相关命令
#添加好新的Supervisor的子配置文件xxx.ini后,更新配置到Supervisord
[root@localhost ~]# supervisorctl update
#重新启动配置中的所有程序
[root@localhost ~]# supervisorctl reload
#启动指定的某个进程(program_name = django-python)
[root@localhost ~]# supervisorctl start django-python
#查看当前正在守候的进程
[root@localhost ~]# supervisorctl
django-python RUNNING pid 13449, uptime 0:03:06
sonar-dingding RUNNING pid 13450, uptime 0:03:06
#停止某一进程(program_name = django-python)
[root@localhost ~]# supervisorctl stop django-python
#重启某一进程(program_name = django-python)
[root@localhost ~]# supervisorctl restart django-python
#停止全部进程(program_name = )
[root@localhost ~]# supervisorctl stop all