1,tomcat多实例: 作为Windows服务进行管理
http://tomcat.apache.org/tomcat-8.0-doc/windows-service-howto.html
- 1, 递归创建目录: apache-tomcat-8-muti-instance/instances/instance1
- 2 , 解压tomcat: 把bin, lib 放到apache-tomcat-8-muti-instance目录里
- 3,把conf放到apache-tomcat-8-muti-instance目录里,把conf/{server.xml, web.xml} 两个文件挑出来
- 4,把其余目录放到instances/instance1里面,保持instance1里面的conf只有server.xml, web.xml
D:\software\apache-tomcat-8-muti-instance
λ ls
bin/ conf/ instances/ lib/
D:\software\apache-tomcat-8-muti-instance
λ ls instances\node_instance1
conf/ logs/ temp/ webapps/ work/
D:\software\apache-tomcat-8-muti-instance
λ ls conf\ ##把server.xml , web.xml转移到instances/instance1,2,3里面
Catalina/ catalina.policy catalina.properties context.xml jaspic-providers.xml jaspic-providers.xsd logging.properties tomcat-users.xml tomcat-users.xsd
D:\software\apache-tomcat-8-muti-instance
λ ls instances\node_instance1\conf\
Catalina/ server.xml web.xml
#### 设置变量: CATALINA_HOME是基本目录, 里面有多个instance: CATALINA_BASE
############### 安装实例1 ###############
D:\software\apache-tomcat-8-muti-instance\bin
λ set CATALINA_HOME=D:\software\apache-tomcat-8-muti-instance
D:\software\apache-tomcat-8-muti-instance\bin
λ set CATALINA_BASE=D:\software\apache-tomcat-8-muti-instance\instances\node_instance1
D:\software\apache-tomcat-8-muti-instance\bin
λ service.bat install tomcat8_instance1
Installing the service 'tomcat8_instance1' ...
Using CATALINA_HOME: "D:\software\apache-tomcat-8-muti-instance"
Using CATALINA_BASE: "D:\software\apache-tomcat-8-muti-instance\instances\node_instance1"
Using JAVA_HOME: "D:\software\jdk1.8.0_3"
Using JRE_HOME: "D:\software\jdk1.8.0_3\jre"
Using JVM: "D:\software\jdk1.8.0_3\jre\bin\server\jvm.dll"
The service 'tomcat8_instance1' has been installed.
############### 安装实例2 ###############
D:\software\apache-tomcat-8-muti-instance\bin
λ set CATALINA_BASE=D:\software\apache-tomcat-8-muti-instance\instances\node_instance2
D:\software\apache-tomcat-8-muti-instance\bin
λ service.bat install tomcat8_instance2
Installing the service 'tomcat8_instance2' ...
Using CATALINA_HOME: "D:\software\apache-tomcat-8-muti-instance"
Using CATALINA_BASE: "D:\software\apache-tomcat-8-muti-instance\instances\node_instance2"
Using JAVA_HOME: "D:\software\jdk1.8.0_3"
Using JRE_HOME: "D:\software\jdk1.8.0_3\jre"
Using JVM: "D:\software\jdk1.8.0_3\jre\bin\server\jvm.dll"
The service 'tomcat8_instance2' has been installed.
2,修改tomcat环境变量
- catalina.bat/.sh文件说明
# windows 版: CATALINA_BASE/bin/setenv.bat
rem Do not set the variables in this script. Instead put them into a script
rem setenv.bat in CATALINA_BASE/bin to keep your customizations separate.
#
D:\software\apache-tomcat-8.5.54\bin
λ cat setenv.bat
set JAVA_OPTS=%JAVA_OPTS% ^
-Xmx 2g -Xms 1g
# linux 版: CATALINA_BASE/bin/setenv.sh
# Do not set the variables in this script. Instead put them into a script
# setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
#
[root@test-c6 ~]# cat apache-tomcat-8.5.54/bin/setenv.sh
JAVA_OPTS="$JAVA_OPTS -Xmx2g -Xms1g"
CATALINA_PID="$CATALINA_BASE/bin/tomcat.pid"
3,tomcat日志保留期限
文档:http://tomcat.apache.org/tomcat-8.5-doc/logging.html#Access_logging
#修改server.xml: 添加属性参数 maxDays="1"
##localhost_access_log.2020-03-23.txt 保留期限
[wang@c6 ~]# grep AccessLogValve /opt/apache-tomcat-8.5.54/conf/server.xml -A 1
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" maxDays="1"
prefix="localhost_access_log" suffix=".txt"
#修改logging.properties: 添加四行配置 maxDays="1"
#catalina.out maxDays=1
#localhost.2020-03-23.log maxDays=1
#host-manager.2021-02-04.log maxDays=1
[wang@c6 ~]# grep maxDays /opt/apache-tomcat-8.5.54/conf/logging.properties
1catalina.org.apache.juli.AsyncFileHandler.maxDays=1
2localhost.org.apache.juli.AsyncFileHandler.maxDays=1
3manager.org.apache.juli.AsyncFileHandler.maxDays=1
4host-manager.org.apache.juli.AsyncFileHandler.maxDays=1