简体   繁体   English

Tomcat - CATALINA_BASE 和 CATALINA_HOME 变量

[英]Tomcat - CATALINA_BASE and CATALINA_HOME variables

I have multiple instances of tomcat 6 running on the same server (Linux) and it works as expected.我在同一台服务器 (Linux) 上运行了多个 tomcat 6 实例,并且它按预期工作。 I am trying to find out what the standard practice is with regards to setting the CATALINA_HOME and CATALINA_BASE variables.我试图找出关于设置CATALINA_HOMECATALINA_BASE变量的标准做法是什么。

In my tomcat installation, I have setup CATALINA_HOME to point to a "common" folder (say /tomcat6 ) and the CATALINA_BASE variable varies depending on the instance name (say /tomcat_instance1 , /tomcat_instance2 )在我的 tomcat 安装中,我已将CATALINA_HOME设置为指向“公共”文件夹(例如/tomcat6 ),并且CATALINA_BASE变量因实例名称而异(例如/tomcat_instance1/tomcat_instance2

My question is this:我的问题是这样的:

  • Do I really need two variables?我真的需要两个变量吗?
  • Or Can I just have one CATALINA_HOME and do away with CATALINA_BASE (or vice-versa) ?或者我可以只拥有一个CATALINA_HOME并取消CATALINA_BASE (反之亦然)吗?

If you are running multiple instances of Tomcat on a single host you should set CATALINA_BASE to be equal to the .../tomcat_instance1 or .../tomcat_instance2 directory as appropriate for each instance and the CATALINA_HOME environment variable to the common Tomcat installation whose files will be shared between the two instances.如果您在单个主机上运行多个 Tomcat 实例,您应该将CATALINA_BASE设置为与每个实例对应的.../tomcat_instance1.../tomcat_instance2目录,并将CATALINA_HOME环境变量设置为公共 Tomcat 安装的文件将在两个实例之间共享。

The CATALINA_BASE environment is optional if you are running a single Tomcat instance on the host and will default to CATALINA_HOME in that case.如果您在主机上运行单个 Tomcat 实例,则CATALINA_BASE环境是可选的,并且在这种情况下将默认为CATALINA_HOME If you are running multiple instances as you are it should be provided.如果您按原样运行多个实例,则应提供它。

There is a pretty good description of this setup in the RUNNING.txt file in the root of the Apache Tomcat distribution under the heading Advanced Configuration - Multiple Tomcat Instances在 Apache Tomcat 发行版根目录下的RUNNING.txt文件中,在Advanced Configuration - Multiple Tomcat Instances标题下对此设置有很好的描述

CATALINA_HOME vs CATALINA_BASE CATALINA_HOME VS CATALINA_BASE

If you're running multiple instances, then you need both variables, otherwise only CATALINA_HOME .如果您正在运行多个实例,那么您需要两个变量,否则只需要CATALINA_HOME

In other words: CATALINA_HOME is required and CATALINA_BASE is optional.换句话说: CATALINA_HOME是必需的, CATALINA_BASE是可选的。

CATALINA_HOME represents the root of your Tomcat installation. CATALINA_HOME代表 Tomcat 安装的根目录。

Optionally, Tomcat may be configured for multiple instances by defining $CATALINA_BASE for each instance.或者,可以通过为每个实例定义$CATALINA_BASE来为多个实例配置 Tomcat。 If multiple instances are not configured, $CATALINA_BASE is the same as $CATALINA_HOME .如果未配置多个实例,则$CATALINA_BASE$CATALINA_HOME相同。

See: Apache Tomcat 7 - Introduction请参阅: Apache Tomcat 7 - 介绍

Running with separate CATALINA_HOME and CATALINA_BASE is documented in RUNNING.txt which say:使用单独的CATALINA_HOMECATALINA_BASE运行记录在 RUNNING.txt 中,其中说:

The CATALINA_HOME and CATALINA_BASE environment variables are used to specify the location of Apache Tomcat and the location of its active configuration, respectively. CATALINA_HOMECATALINA_BASE环境变量分别用于指定 Apache Tomcat 的位置及其活动配置的位置。

You cannot configure CATALINA_HOME and CATALINA_BASE variables in the setenv script, because they are used to find that file.您不能在setenv脚本中配置CATALINA_HOMECATALINA_BASE变量,因为它们用于查找该文件。

For example:例如:

(4.1) Tomcat can be started by executing one of the following commands: (4.1) Tomcat可以通过执行以下命令之一来启动:

 %CATALINA_HOME%\\bin\\startup.bat (Windows) $CATALINA_HOME/bin/startup.sh (Unix)

or或者

 %CATALINA_HOME%\\bin\\catalina.bat start (Windows) $CATALINA_HOME/bin/catalina.sh start (Unix)

Multiple Tomcat Instances多个Tomcat实例

In many circumstances, it is desirable to have a single copy of a Tomcat binary distribution shared among multiple users on the same server.在许多情况下,希望在同一服务器上的多个用户之间共享 Tomcat 二进制分发的单个副本。 To make this possible, you can set the CATALINA_BASE environment variable to the directory that contains the files for your 'personal' Tomcat instance.为了实现这一点,您可以将CATALINA_BASE环境变量设置为包含“个人”Tomcat 实例文件的目录。

When running with a separate CATALINA_HOME and CATALINA_BASE , the files and directories are split as following:当使用单独的CATALINA_HOMECATALINA_BASE运行时,文件和目录拆分如下:

In CATALINA_BASE :CATALINA_BASE

  • bin - Only: setenv.sh (*nix) or setenv.bat (Windows), tomcat-juli.jar bin - 仅:setenv.sh (*nix) 或 setenv.bat (Windows)、tomcat-juli.jar
  • conf - Server configuration files (including server.xml) conf - 服务器配置文件(包括 server.xml)
  • lib - Libraries and classes, as explained below lib - 库和类,如下所述
  • logs - Log and output files logs - 日志和输出文件
  • webapps - Automatically loaded web applications webapps - 自动加载的 Web 应用程序
  • work - Temporary working directories for web applications work - Web 应用程序的临时工作目录
  • temp - Directory used by the JVM for temporary files> temp - JVM 用于临时文件的目录>

In CATALINA_HOME :CATALINA_HOME

  • bin - Startup and shutdown scripts bin - 启动和关闭脚本
  • lib - Libraries and classes, as explained below lib - 库和类,如下所述
  • endorsed - Libraries that override standard "Endorsed Standards". endorsed - 覆盖标准“认可标准”的库。 By default it's absent.默认情况下它不存在。

How to check如何检查

The easiest way to check what's your CATALINA_BASE and CATALINA_HOME is by running startup.sh , for example:检查您的CATALINA_BASECATALINA_HOME的最简单方法是运行startup.sh ,例如:

$ /usr/share/tomcat7/bin/startup.sh
Using CATALINA_BASE:   /usr/share/tomcat7
Using CATALINA_HOME:   /usr/share/tomcat7

You may also check where the Tomcat files are installed, by dpkg tool as below (Debian/Ubuntu):您还可以通过dpkg工具检查 Tomcat 文件的安装位置,如下所示(Debian/Ubuntu):

dpkg -L tomcat7-common

I can't say I know the best practice, but here's my perspective.我不能说我知道最佳实践,但这是我的观点。

Are you using these variables for anything?是否将这些变量用于任何用途?

Personally, I haven't needed to change neither, on Linux nor Windows, in environments varying from development to production.就个人而言,无论是在 Linux 还是 Windows 上,从开发到生产的不同环境中,我都不需要更改。 Unless you are doing something particular that relies on them, chances are you could leave them alone.除非您正在做一些依赖于它们的特定事情,否则您很可能可以不理会它们。

catalina.sh sets the variables that Tomcat needs to work out of the box. catalina.sh设置 Tomcat 开箱即用所需的变量。 It also says that CATALINA_BASE is optional:它还说CATALINA_BASE是可选的:

#   CATALINA_HOME   May point at your Catalina "build" directory.
#
#   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
#                   of a Catalina installation.  If not present, resolves to
#                   the same directory that CATALINA_HOME points to.

I'm pretty sure you'll find out whether or not your setup works when you start your server.我很确定您会在启动服务器时发现您的设置是否有效。

Pointing CATALINA_BASE to a different directory from CATALINA_HOME allows you to separate the configuration directory from the binaries directory.指着CATALINA_BASE从不同的目录CATALINA_HOME允许您配置目录从二进制文件目录分开。

By default, CATALINA_BASE (configurations) and CATALINA_HOME (binaries) point to the same folder, but separating the configurations from the binaries can help you to run multiple instances of Tomcat side by side without duplicating the binaries.默认情况下, CATALINA_BASE (配置)和CATALINA_HOME (二进制文件)指向同一个文件夹,但将配置与二进制文件分开可以帮助您并行运行多个 Tomcat 实例,而无需复制二进制文件。

It is also useful when you want to update the binaries, without modifying, or needing to backup/restore your configuration files for Tomcat.当您想要更新二进制文件而不修改或需要备份/恢复 Tomcat 的配置文件时,它也很有用。

Update 2018 2018 年更新

There is an easier way to set CATALINA_BASE now with the makebase utility.现在有一种更简单的方法可以使用makebase实用程序来设置 CATALINA_BASE。 I have posted a tutorial that covers this subject at http://blog.rasia.io/blog/how-to-easily-setup-lucee-in-tomcat.html along with a video tutorial at https://youtu.be/nuugoG5c-7M我在http://blog.rasia.io/blog/how-to-easily-setup-lucee-in-tomcat.html 上发布了一个涵盖这个主题的教程以及一个在https://youtu.be上的视频教程/nuugoG5c-7M

Original answer continued below原始答案在下面继续

To take advantage of this feature, simply create the config directory and point to it with the CATALINA_BASE environment variable.要利用此功能,只需创建 config 目录并使用CATALINA_BASE环境变量指向它。 You will have to put some files in that directory:您必须在该目录中放置一些文件:

  • Copy the conf directory from the original Tomcat installation directory, including its contents, and ensure that Tomcat has read permissions to it.从原来的Tomcat安装目录复制conf目录,包括其内容,并确保Tomcat对其具有读取权限。 Edit the configuration files according to your needs.根据您的需要编辑配置文件。
  • Create a logs directory if conf/logging.properties points to ${catalina.base}/logs , and ensure that Tomcat has read/write permissions to it.如果conf/logging.properties指向${catalina.base}/logs ,则创建一个logs目录,并确保 Tomcat 对其具有读/写权限。
  • Create a temp directory if you are not overriding the default of $CATALINA_TMPDIR which points to ${CATALINA_BASE}/temp , and ensure that Tomcat has write permissions to it.如果您没有覆盖指向${CATALINA_BASE}/temp$CATALINA_TMPDIR的默认值,请创建一个temp目录,并确保 Tomcat 对其具有写入权限。
  • Create a work directory which defaults to ${CATALINA_BASE}/work , and ensure that Tomcat has write permissions to it.创建一个默认为${CATALINA_BASE}/workwork目录,并确保 Tomcat 对其具有写入权限。

CATALINA_BASE is optional. CATALINA_BASE 是可选的。

However, in the following scenarios it helps to setup CATALINA_BASE that is separate from CATALINA_HOME.但是,在以下场景中,设置与 CATALINA_HOME 分开的 CATALINA_BASE 会有所帮助。

  1. When more than 1 instances of tomcat are running on same host当 1 个以上的 tomcat 实例在同一台主机上运行时

    • This helps have only 1 runtime of tomcat installation, with multiple CATALINA_BASE server configurations running on separate ports.这有助于只有 1 个 tomcat 安装运行时,多个 CATALINA_BASE 服务器配置在不同的端口上运行。
    • If any patching, or version upgrade needs be, only 1 installation changes required, or need to be tested/verified/signed-off.如果需要任何修补或版本升级,只需进行 1 次安装更改,或需要测试/验证/签署。
  2. Separation of concern (Single responsibility)关注点分离(单一责任)

    • Tomcat runtime is standard and does not change during every release process. Tomcat 运行时是标准的,不会在每个发布过程中更改。 ie Tomcat binaries即Tomcat二进制文件
    • Release process may add more stuff as webapplication (webapps folder), environment configuration (conf directory), logs/temp/work directory发布过程可能会添加更多的东西,如 webapplication(webapps 文件夹)、环境配置(conf 目录)、logs/temp/work 目录

That is the parent folder of bin which contains tomcat.exe file:那是包含 tomcat.exe 文件的 bin 的父文件夹:

CATALINA_HOME='C:\Program Files\Apache Software Foundation\Tomcat 6.0'

CATALINA_BASE is the same as CATALINA_HOME . CATALINA_BASECATALINA_HOME相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM