supervisor管理集群(多个tomcat)#yyds干货盘点#

Posted wangzx_mm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了supervisor管理集群(多个tomcat)#yyds干货盘点#相关的知识,希望对你有一定的参考价值。

官网:http://www.supervisord.org/

1简介

Supervisor ( http:/lsupervisord.orgL ) CIS架构的进程控制系统,是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,基于linux操作系统的一款服务器管理工具,不支持Windows系统。用以监控服务器的运行,发现问题能立即自动预警及自动重启等功能。

Supervisor类似于monit ,monit和supervisor的一个比较大的差异是supervisor管理的进程必须由supervisor来启动,monit可以管理已经在运行的程序;supervisor还要求管理的程序是非daemon程序,supervisord会帮你把它转daemon程序,因此如果用supervisor来管理nginx的话,必须在nginx的配置文件里添加一行设置daemon offInginx以非

daemon方式启动。

因为Supervisor是Python开发的,安装前先检查一下系统否安装了Python2.4以上版本。下面以Cent0S7,Python2.7版本环境下,介绍Supervisor的安装与配置步聚:

2应用场景

公司服务器众多,项目多以tomcat为主,而且服务器上tomcat节点比较多,此时通过脚本管理tomcat已经非常棘手,就需要一个统一的进程管理工具去统一管理项目。因此选用supervisor来管理I

注意: supervisor只能管理前台进程。

3.安装

安装之前要确定你的虚拟机上是否有Python环境

3.1.安装supervisor

yum -y install supervisor
设置开启自启
systemctl enable supervisord
#常用supervisorctl命令
supervisorctl status
supervisorctl stop tomcat
supervisorctl start tomcat
supervisorctl restart tomcat
supervisorctl reread
supervisorctl update

3.2.通过supervisor管理tomcat,配置jdk环境

tar -zxvf jdk-8u60-linux-x64.tar.gz -C /usr/local/
chown -R root.root /usr/local/jdk1.8.0_60
cat>>/etc/profile<<\\EOF
###jdk环境###
export JAVA_HOME=/usr/local/jdk1.8.0_60
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
EOF
生效
source /etc/profile
java -version

3.3.安装tomcat

tar zxf apache-tomcat-8.5.29.tar.gz
mkdir -p /opt/app01
cp -a apache-tomcat-8.5.29/* /opt/app01/
#删除没有用的
rm -f NOTICE LICENSE RELEASE-NOTES RUNNING.txt
#启动tomcat
./bin/startup.sh
##查看一下有没有起来
ps -ef | grep java
#关闭tomcat
./bin/shutdown.sh

3.4.创建supervisor管理tomcat的子配置文件

[root@ c7-41 app01]# vim /etc/supervisord.d/app01.ini

[program:app01]
command=/opt/app01/bin/catalina.sh run
environment=JAVA_HOME="/usr/local/jdk1.8.0_60",JAVA_BIN="/usr/local/jdk1.8.0_60/bin"
directory=/opt/app01/bin/
numprocs=1
user = root
autostart = true
autorestart=true
startsecs = 5

3.5.启动supervisor,会把它下面的都给带起来

[root@ c7-41 app01]# systemctl status supervisord.service
● supervisord.service - Process Monitoring and Control Daemon
Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
Active: inactive (dead)
[root@ c7-41 app01]# systemctl start supervisord.service
[root@ c7-41 app01]# ps -ef | grep java
root 3839 3838 67 15:19 ? 00:00:05 /usr/local/jdk1.8.0_60/bin/java -Djava.util.logging.config.file=/opt/app01/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -classpath /opt/app01/bin/bootstrap.jar:/opt/app01/bin/tomcat-juli.jar -Dcatalina.base=/opt/app01 -Dcatalina.home=/opt/app01 -Djava.io.tmpdir=/opt/app01/temp org.apache.catalina.startup.Bootstrap start
root 3887 3380 0 15:19 pts/0 00:00:00 grep --color=auto java

3.6.bash终端管理

[root@ c7-41 app01]# supervisorctl status   #命令行模式
app01 RUNNING pid 3839, uptime 0:02:09

[root@ c7-41 app01]# supervisorctl #交互模式
app01 RUNNING pid 3839, uptime 0:13:57
supervisor> help

default commands (type help <topic>):
=====================================
add exit open reload restart start tail
avail fg pid remove shutdown status update
clear maintail quit reread signal stop version

supervisor>
#ctrl+c退出

3.7.常用命令supervisorctl

[root@ c7-41 app01]# supervisorctl status app01
app01 RUNNING pid 3839, uptime 0:15:31
[root@ c7-41 app01]# supervisorctl start app01
app01: ERROR (already started)
supervisorctl stop app01
supervisorctl reload app01

3.8.看一下是否有问题

[root@ c7-41 app01]# curl -I 10.0.0.41:8080
HTTP/1.1 200
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 20 Apr 2020 07:22:28 GMT

进入到主配置文件(ctrl+v可以删除多行,选中就好了)(按一下esc,然后ctrl+c,然后在i,添加完之后按一个esc)把注释去掉

supervisor管理集群(多个tomcat)#yyds干货盘点#_tomcat

3.9.启动一下

[root@ c7-41 ~]# systemctl restart supervisord
[root@ c7-41 ~]# supervisorctl start app01
app01: ERROR (already started)
[root@ c7-41 ~]# supervisorctl status app01
app01 RUNNING pid 4506, uptime 0:00:14
[root@ c7-41 ~]#

3.10.测试

supervisor管理集群(多个tomcat)#yyds干货盘点#_tomcat_02

supervisor管理集群(多个tomcat)#yyds干货盘点#_tomcat_03

怎么弄多个tomcat

[root@ c7-41 opt]# cp -a app01 app02
[root@ c7-41 conf]# vim server.xml
[root@ c7-41 conf]# pwd
/opt/app02/conf

修改一下端口号

supervisor管理集群(多个tomcat)#yyds干货盘点#_tomcat_04

supervisor管理集群(多个tomcat)#yyds干货盘点#_unix_05

supervisor管理集群(多个tomcat)#yyds干货盘点#_java_06

创建supervisor管理tomcat的子配置文件

[root@ c7-41 app02]# cd /opt/app02/
[root@ c7-41 app02]# cd /etc/supervisord.d/
[root@ c7-41 supervisord.d]# ls
app01.ini
[root@ c7-41 supervisord.d]# cp app01.ini app02.ini
[root@ c7-41 supervisord.d]# vim app02
[root@ c7-41 supervisord.d]# vim app02.ini

[program:app02]
command=/opt/app02/bin/catalina.sh run
environment=JAVA_HOME="/usr/local/jdk1.8.0_60",JAVA_BIN="/usr/local/jdk1.8.0_60/bin"
directory=/opt/app02/bin/
numprocs=1
user = root
autostart = true
autorestart=true
startsecs = 5

更新(添加)启动

supervisor管理集群(多个tomcat)#yyds干货盘点#_tomcat_07

supervisor管理集群(多个tomcat)#yyds干货盘点#_unix_08

页面刷新一下

supervisor管理集群(多个tomcat)#yyds干货盘点#_java_09

知识点

传统的将程序放置后台启动:

1

(1)、&放置后台启动;但是一般和nohup(不挂断运行命令)一起用;常用方法;nohup command &

(2)工具类:可以用supervisor等守护进程工具管理


2、

(1)nohup /opt/app01/bin/catalina.sh run & #后台启动

(2)nohup /opt/app01/bin/catalina.sh run #前台启动


3、cat /etc/supervisord.conf(这里面不用修改就是为了让你了解一下)

yum安装的supervisor的主配置文件详解

[root@ c7-41 app01]# cat /etc/supervisord.conf
; Sample supervisor config file.

[unix_http_server] #下面这个是supervisorctl和supervisord主程序通讯使用的
file=/var/run/supervisor/supervisor.sock ; (the path to the socket file)
;chmod=0700 ; sockef file mode (default 0700)
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))

;[inet_http_server] #supervisor自带UI界面有关; inet (TCP) server disabled by default
;port=127.0.0.1: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))

[supervisord] #supervisord主程序的配置
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false#在后台启动 ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
;umask=022 ; (process file creation umask;default 022)
;user=chrism ; (default is current user, required if root)
;identifier=supervisor ; (supervisord identifier, default is supervisor)
;directory=/tmp ; (default is not to cd during start)
;nocleanup=true ; (dont clean up tempfiles at start;default false)
;childlogdir=/tmp ; (AUTO child log dir, default $TEMP)
;environment=KEY=value ; (key value pairs to add to environment)
;strip_ansi=false ; (strip ansi escape codes in logs; def. false)

; 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] #supervisorctl命令行(客户端)
serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris ; should be same as http_username if set
;password=

以上是关于supervisor管理集群(多个tomcat)#yyds干货盘点#的主要内容,如果未能解决你的问题,请参考以下文章

supervisor管理单机多实例Tomcat

supervisor集群方式-supervisor-monitor

supervisor集群方式-supervisor-monitor

supervisor集群方式-supervisor-monitor

Supervisor在CentOS7下的安装及管理tomcat进程

Apache Storm Supervisor 自动停止