查阅资料
https://www.cnblogs.com/toutou/p/supervisor.html
https://www.jianshu.com/p/0b9054b33db3
https://www.cnblogs.com/52fhy/p/10161253.html
https://blog.csdn.net/huwh_/article/details/80497790
https://www.cnblogs.com/Hai–D/p/5820718.html
https://www.cnblogs.com/tianfengcc/p/13667010.html
https://www.cnblogs.com/ruanraun/p/supervisor.html
https://blog.csdn.net/qq_43923588/article/details/113178555?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242
https://blog.csdn.net/qq_38234594/article/details/89923583
一、安装supervisor
supervisor需要python环境,查看linux自带的python
python -V
方式一、yum install supervisor(已验证)
该方式会自动生成主配置文件,路径
/etc/supervisord.conf
1、 执行安装命令
yum install supervisor
2、如果提示【没有可用软件包】,依次执行
yum install epel-release
yum install supervisor
3、验证是否安装成功
supervisord -v
方式二、easy_install supervisor(未验证)
需安装有pip
yum install -y python-setuptools
easy_install supervisor
supervisord -v
方式三、pip install supervisor(未验证)
需安装有pip
yum -y install epel-release
yum -y install python-pip
pip -V
pip安装的meld3不可用,手动安装。
wget https://pypi.python.org/packages/source/m/meld3/meld3-1.0.2.tar.gz
tar -zxf meld3-1.0.2.tar.gz
cd meld3-1.0.2
python setup.py install
pip install supervisor
方式四、python setup.py install(未验证)
wget https://pypi.python.org/packages/source/s/supervisor/supervisor-3.1.3.tar.gz
tar zxvf supervisor-3.1.3.tar.gz
cd supervisor-3.1.3
python setup.py install
如果easy_install不好使就从官方下载:
wget https://pypi.python.org/packages/80/37/964c0d53cbd328796b1aeb7abea4c0f7b0e8c7197ea9b0b9967b7d004def/supervisor-3.3.1.tar.gz
然后通过python安装:
tar zxf supervisor-3.3.1.tar.gz
cd supervisor
python setup.py install
方式五、离线安装(未验证)
setuptools
meld3
supervisor
生成配置文件:echo_supervisor_conf > /etc/supervisor/supervisord.conf
Debian/Ubuntu可通过apt安装
apt-get install supervisor
二、修改主程序配置文件
文件已经自动创建,直接修改
vi /etc/supervisord.conf
1、开启可视化页面
访问地址
http://服务器地址:9001/
2、修改子程序配置文件路径
三、创建子程序配置文件
1、创建子程序配置文件
cd /etc/supervisord.d/
touch changChunBigDataPlatform.conf
2、添加配置信息
vi changChunBigDataPlatform.conf
添加如下内容:
[program:changChunBigDataPlatform]
;environment=JAVA_HOME="/usr/java/jdk1.8.0_181",JAVA_BIN="/usr/java/jdk1.8.0_181/bin"
;directory = /data/apache-tomcat-8.5.60/bin ; 程序的启动目录
command=/data/apache-tomcat-8.5.60/bin/catalina.sh run
priority=999 ; the relative start priority (default 999)
autostart=true ; start at supervisord start (default: true)
autorestart=true ; retstart at unexpected quit (default: true)
startsecs=10 ; number of secs prog must stay running (def. 10)
startretries=3 ; max # of serial start failures (default 3)
exitcodes=0,2 ; ‘expected’ exit codes for process (default 0,2)
stopsignal=QUIT ; signal used to kill process (default TERM)
stopwaitsecs=10 ; max num secs to wait before SIGKILL (default 10)
;user=root ; setuid to this UNIX account to run the program
stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默认 50MB
stdout_logfile_backups=1 ; stdout 日志文件备份数
;stdout_logfile=/etc/supervisord.d/changChunBigDataPlatform.stdout.log
stdout_logfile=/data/apache-tomcat-8.5.60/logs/catalina.out
redirect_stderr=true ; 重定向stderr到stdout
3、最少修改4处
4、通过搜索java文件,查找jdk默认安装目录
find / -name ‘java’
export JAVA_HOME=/usr/java/jdk1.8.0_181
export JRE_HOME=/usr/java/jdk1.8.0_181/jre
export CLASSPATH=.:
J
A
V
A
H
O
M
E
/
l
i
b
JAVA_HOME/lib
JAVAHOME/lib:JRE_HOME/lib:
C
L
A
S
S
P
A
T
H
e
x
p
o
r
t
P
A
T
H
=
CLASSPATH export PATH=
CLASSPATHexportPATH=JAVA_HOME/bin:
J
R
E
H
O
M
E
/
b
i
n
/
JRE_HOME/bin/
JREHOME/bin/JAVA_HOME:$PATH
四、配置开机自启
1、修改配置文件
cd /usr/lib/systemd/system/
vi supervisord.service
2、文件内容如下
[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service nss-user-lookup.target
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /usr/supervisor/supervisord.conf ;开机启动时执行
ExecStop=/usr/bin/supervisord shutdown
ExecReload=/usr/bin/supervisord reload
killMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
截图如下:
3、设置开机启动
systemctl enable supervisord
4、验证开机启动是否生效
systemctl is-enabled supervisord
启动
1、启动主程序及所有子程序
supervisord -c /etc/supervisord.conf
2、查看子程序
方式一:supervisorctl status
方式二:ps aux | grep supervisord
supervisord命令
supervisord -c /etc/supervisord.conf ;通过配置文件启动supervisor及所有子程序
supervisorctl命令
(sudo) supervisorctl -c /etc/supervisord.conf [start|restart|stop |status] [program-name|all] ; 启动、重启、停止、察看supervisor 管理的某个程序或所有程序
supervisorctl start all ;启动所有子进程
supervisorctl start ; 启动指定子进程
supervisorctl restart all ; 重启所有子进程
supervisorctl restart ; 重启指定子进程
supervisorctl stop all ; 停止所有子进程
supervisorctl stop ; 停止指定子进程
supervisorctl status ;查看所有进程状态
supervisorctl status ;查看指定进程状态
supervisorctl reread ;新增配置文件后,重新加载所有配置文件
supervisorctl update ;将配置文件里新增的子进程更新进程组,如果设置了autostart=true则会启动新新增的子进程
supervisorctl update ;
supervisorctl add ; 添加子进程到进程组
supervisorctl reomve ; 从进程组移除子进程,需要先stop。注意:移除后,需要使用reread和update才能重新运行该进程
supervisorctl reload ;重启supervisord
supervisorctl -c supervisor.conf reload 重新载入 配置文件 更新后可以选择重新载入
service命令,无效
service supervisor start
service supervisor stop
service supervisor restart
长春守护进程
supervisorctl start changChunBigDataPlatform
supervisorctl start jdlh
supervisorctl start backstage
supervisorctl stop changChunBigDataPlatform
supervisorctl stop jdlh
supervisorctl stop backstage