本说明针对Tomcat7。此处记录以作备查。
1、CATALINA_HOME和CATALINA_BASE的定义
官方说明:
- CATALINA_HOME:Represents the root of your Tomcat installation, for example /home/tomcat/apache-tomcat-9.0.10 or C:\Program Files\apache-tomcat-9.0.10.
- CATALINA_BASE:Represents the root of a runtime configuration of a specific Tomcat instance. If you want to have multiple Tomcat instances on one machine, use the CATALINA_BASE property.
If you set the properties to different locations, the CATALINA_HOME location contains static sources, such as .jar files, or binary files. The CATALINA_BASE location contains configuration files, log files, deployed applications, and other runtime requirements.
由此可知:
CATALINA_HOME:代表Tomcat安装的根路径。
CATALINA_BASE:代表特定的Tomcat实例在运行时配置的根路径。如果希望在一台计算机上有多个Tomcat实例,请使用CATALINA_BASE属性。
更进一步,如果你设置了CATALINA_HOME和CATALINA_BASE两个属性,并且两个属性代表的路径不同,那么CATALINA_HOME路径包含的是静态资源,例如.jar文件,或者二进制文件; CATALINA_BASE路径包含的是配置文件、log日志文件、部署的应用程序和其它运行时所需的资源。
2、为什么使用CATALINA_BASE
官方说明:
By default, CATALINA_HOME and CATALINA_BASE point to the same directory. Set CATALINA_BASE manually when you require running multiple Tomcat instances on one machine. Doing so provides the following benefits:
- Easier management of upgrading to a newer version of Tomcat. Because all instances with single CATALINA_HOME location share one set of .jar files and binary files, you can easily upgrade the files to newer version and have the change propagated to all Tomcat instances using the same CATALIA_HOME directory.
- Avoiding duplication of the same static .jar files.
- The possibility to share certain settings, for example the setenv shell or bat script file (depending on your operating system).
由此可知,默认情况下,CATALINA_HOME和CATALINA_BASE指向相同的目录。当需要在一台机器上运行多个Tomcat实例时,需要手动设置CATALINA_BASE。这样做的好处是:
(1)、方便管理Tomcat升级到新版本。所有实例都使用同一个CATALINA_HOME路径,只需要更新该路径下的静态资源,例如.jar文件,那么所有使用CATALINA_HOME路径的实例都同时会升级。
(2)、避免相同静态.jar文件的重复,只需要相同的一份就可以了。
(3)、使某些设置共享变为可能。
3、CATALINA_BASE的目录
官方说明:
Before you start using CATALINA_BASE, first consider and create the directory tree used by CATALINA_BASE. Note that if you do not create all the recommended directories, Tomcat creates the directories automatically. If it fails to create the necessary directory, for example due to permission issues, Tomcat will either fail to start, or may not function correctly.
Consider the following list of directories:
- The bin directory with the setenv.sh, setenv.bat, and tomcat-juli.jar files.
Recommended: No.
Order of lookup: CATALINA_BASE is checked first; fallback is provided to CATALINA_HOME.
- The lib directory with further resources to be added on classpath.
Recommended: Yes, if your application depends on external libraries.
Order of lookup: CATALINA_BASE is checked first; CATALINA_HOME is loaded second.
- The logs directory for instance-specific log files.
Recommended: Yes.
- The webapps directory for automatically loaded web applications.
Recommended: Yes, if you want to deploy applications.
Order of lookup: CATALINA_BASE only.
- The work directory that contains temporary working directories for the deployed web applications.
Recommended: Yes.
- The temp directory used by the JVM for temporary files.
Recommended: Yes.
需要注意的几点:
(1)、在开始使用CATALINA_BASE属性前,首先在CATALINA_BASE指定的路径下至少要创建两个文件夹,conf和temp,其中conf目录中至少要包含server.xml和web.xml文件,推荐将CATALINA_HOME\conf目录的文件全部拷贝。并且要特别注意,Tomcat服务器只在CATALINA_BASE路径conf中查找配置文件,并不会回退到CATALINA_HOME路径下查找配置文件。
(2)、如果定义了lib目录,运行时查找的次序是,首先在CATALINA_BASE路径下查找,然后到CATALINA_HOME路径下查找。
(3)、如果部署应用程序,必须创建webapps目录。并且要特别注意的是Tomcat服务器查找应用的顺序是只在CATALINA_BASE路径下查找,并不会到CATALINA_HOME路径下查找。
4、如何使用CATALINA_BASE
官方说明:
The CATALINA_BASE property is an environment variable. You can set it before you execute the Tomcat start script, for example:
- On Unix: CATALINA_BASE=/tmp/tomcat_base1 bin/catalina.sh start
- On Windows: CATALINA_BASE=C:\tomcat_base1 bin/catalina.bat start
举例:在控制台命令窗口设置一个临时CATALINA_BASE变量进行测试
D:\Program Files\tomcat\tomcat-6.0_zhxy\bin>set CATALINA_BASE=D:\Program Files\tomcat
D:\Program Files\tomcat\tomcat-6.0_zhxy\bin>catalina.bat run

本文介绍了CATALINA_HOME和CATALINA_BASE在Tomcat中的区别和作用。CATALINA_HOME代表Tomcat安装路径,而CATALINA_BASE用于配置特定Tomcat实例。设置不同的CATALINA_BASE可以方便管理多个Tomcat实例,避免重复的静态资源,且允许共享设置。使用CATALINA_BASE需要创建包括bin、lib、logs、webapps、work和temp等目录,并注意配置文件和应用的查找顺序。
7485

被折叠的 条评论
为什么被折叠?



