Java tomcat - CATALINA_BASE 和 CATALINA_HOME 变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3090398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:20:50  来源:igfitidea点击:

tomcat - CATALINA_BASE and CATALINA_HOME variables

javatomcatenvironment-variables

提问by souser

I have multiple instances of tomcat 6 running on the same server (Linux) and it works as expected. I am trying to find out what the standard practice is with regards to setting the CATALINA_HOMEand CATALINA_BASEvariables.

我在同一台服务器 (Linux) 上运行了多个 tomcat 6 实例,并且它按预期工作。我试图找出关于设置CATALINA_HOMECATALINA_BASE变量的标准做法是什么。

In my tomcat installation, I have setup CATALINA_HOMEto point to a "common" folder (say /tomcat6) and the CATALINA_BASEvariable 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_HOMEand do away with CATALINA_BASE(or vice-versa) ?
  • 我真的需要两个变量吗?
  • 或者我可以只拥有一个CATALINA_HOME并取消 CATALINA_BASE(或反之亦然)?

采纳答案by Russ

If you are running multiple instances of Tomcat on a single host you should set CATALINA_BASEto be equal to the .../tomcat_instance1or .../tomcat_instance2directory as appropriate for each instance and the CATALINA_HOMEenvironment 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_BASEenvironment is optional if you are running a single Tomcat instance on the host and will default to CATALINA_HOMEin that case. If you are running multiple instances as you are it should be provided.

CATALINA_BASE,如果你正在运行在主机上一个Tomcat实例,并且默认将环境是可选CATALINA_HOME在这种情况下。如果您按原样运行多个实例,则应提供它。

There is a pretty good description of this setup in the RUNNING.txtfile in the root of the Apache Tomcat distribution under the heading Advanced Configuration - Multiple Tomcat Instances

RUNNING.txt在 Apache Tomcat 发行版根目录下的高级配置 - 多个 Tomcat 实例标题下的文件中对此设置有很好的描述

回答by Lauri Lehtinen

I can't say I know the best practice, but here's my perspective.

我不能说我知道最佳实践,但这是我的观点。

Are youusing these variables for anything?

是否将这些变量用于任何用途?

Personally, I haven't needed to change neither, on Linux nor Windows, in environments varying from development to production. Unless you are doing something particular that relies on them, chances are you could leave them alone.

就我个人而言,无论是在 Linux 还是 Windows 上,在从开发到生产的不同环境中,我都不需要更改。除非您正在做一些依赖于它们的特定事情,否则您很可能可以不理会它们。

catalina.shsets the variables that Tomcat needs to work out of the box. It also says that CATALINA_BASEis optional:

catalina.sh设置 Tomcat 需要开箱即用的变量。它还说这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.

我很确定您会在启动服务器时发现您的设置是否有效。

回答by Guru

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_BASEis the same as CATALINA_HOME.

CATALINA_BASE与 相同CATALINA_HOME

回答by kenorb

CATALINA_HOMEvs CATALINA_BASE

CATALINA_HOME对比 CATALINA_BASE

If you're running multiple instances, then you need both variables, otherwise only CATALINA_HOME.

如果您正在运行多个实例,那么您需要两个变量,否则只需要CATALINA_HOME.

In other words: CATALINA_HOMEis required and CATALINA_BASEis optional.

换句话说:CATALINA_HOME是必需的,CATALINA_BASE是可选的。

CATALINA_HOMErepresents the root of your Tomcat installation.

CATALINA_HOME代表 Tomcat 安装的根目录。

Optionally, Tomcat may be configured for multiple instances by defining $CATALINA_BASEfor each instance. If multiple instances are not configured, $CATALINA_BASEis the same as $CATALINA_HOME.

可选地,可以通过$CATALINA_BASE为每个实例定义来为多个实例配置 Tomcat 。如果没有配置多个实例,$CATALINA_BASE则与$CATALINA_HOME.

See: Apache Tomcat 7 - Introduction

请参阅:Apache Tomcat 7 - 介绍

Running with separate CATALINA_HOMEand CATALINA_BASEis documented in RUNNING.txt which say:

单独运行CATALINA_HOMECATALINA_BASE记录在 RUNNING.txt 中,其中说:

The CATALINA_HOMEand CATALINA_BASEenvironment variables are used to specify the location of Apache Tomcat and the location of its active configuration, respectively.

You cannot configure CATALINA_HOMEand CATALINA_BASEvariables in the setenvscript, because they are used to find that file.

CATALINA_HOMECATALINA_BASE环境变量用于指定的Apache Tomcat的位置和它的活动配置的位置,分别。

您不能在脚本中配置CATALINA_HOMECATALINA_BASE变量 setenv,因为它们用于查找该文件。

For example:

例如:

(4.1) Tomcat can be started by executing one of the following commands:

  %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)

(4.1) Tomcat可以通过执行以下命令之一来启动:

  %CATALINA_HOME%\bin\startup.bat         (Windows)

  $CATALINA_HOME/bin/startup.sh           (Unix)

或者

  %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. To make this possible, you can set the CATALINA_BASEenvironment variable to the directory that contains the files for your 'personal' Tomcat instance.

When running with a separate CATALINA_HOMEand CATALINA_BASE, the files and directories are split as following:

In CATALINA_BASE:

  • bin- Only: setenv.sh (*nix) or setenv.bat (Windows), tomcat-juli.jar
  • conf- Server configuration files (including server.xml)
  • lib- Libraries and classes, as explained below
  • logs- Log and output files
  • webapps- Automatically loaded web applications
  • work- Temporary working directories for web applications
  • temp- Directory used by the JVM for temporary files>

In CATALINA_HOME:

  • bin- Startup and shutdown scripts
  • lib- Libraries and classes, as explained below
  • endorsed- Libraries that override standard "Endorsed Standards". By default it's absent.

在许多情况下,希望在同一服务器上的多个用户之间共享 Tomcat 二进制分发的单个副本。为了实现这一点,您可以将CATALINA_BASE环境变量设置为包含“个人”Tomcat 实例文件的目录。

使用单独的CATALINA_HOMEand运行时CATALINA_BASE,文件和目录拆分如下:

CATALINA_BASE

  • bin- 仅:setenv.sh (*nix) 或 setenv.bat (Windows)、tomcat-juli.jar
  • conf- 服务器配置文件(包括 server.xml)
  • lib- 库和类,如下所述
  • logs- 日志和输出文件
  • webapps- 自动加载的网络应用程序
  • work- Web 应用程序的临时工作目录
  • temp- JVM 用于临时文件的目录>

CATALINA_HOME

  • bin- 启动和关闭脚本
  • lib- 库和类,如下所述
  • endorsed- 覆盖标准“认可标准”的库。默认情况下它不存在。

How to check

如何检查

The easiest way to check what's your CATALINA_BASEand CATALINA_HOMEis 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 dpkgtool as below (Debian/Ubuntu):

您还可以通过dpkg以下工具(Debian / Ubuntu)检查Tomcat文件的安装位置:

dpkg -L tomcat7-common

回答by isapir

Pointing CATALINA_BASEto a different directory from CATALINA_HOMEallows 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(configuration) 和CATALINA_HOME(binaries) 指向同一个文件夹,但是将配置与二进制文件分开可以帮助您并行运行多个 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 makebaseutility. I have posted a tutorial that covers this subject at http://blog.rasia.io/blog/how-to-easily-setup-lucee-in-tomcat.htmlalong with a video tutorial at https://youtu.be/nuugoG5c-7M

现在使用该makebase实用程序有一种更简单的方法来设置 CATALINA_BASE 。我在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_BASEenvironment variable. You will have to put some files in that directory:

要利用此功能,只需创建 config 目录并使用CATALINA_BASE环境变量指向它。您必须在该目录中放置一些文件:

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

回答by Amit Kaneria

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

    • This helps have only 1 runtime of tomcat installation, with multiple CATALINA_BASE server configurations running on separate ports.
    • If any patching, or version upgrade needs be, only 1 installation changes required, or need to be tested/verified/signed-off.
  2. Separation of concern (Single responsibility)

    • Tomcat runtime is standard and does not change during every release process. i.e. Tomcat binaries
    • Release process may add more stuff as webapplication (webapps folder), environment configuration (conf directory), logs/temp/work directory
  1. 当 1 个以上的 tomcat 实例在同一台主机上运行时

    • 这有助于只有 1 个 tomcat 安装运行时,多个 CATALINA_BASE 服务器配置在不同的端口上运行。
    • 如果需要任何修补或版本升级,只需进行 1 次安装更改,或需要测试/验证/签署。
  2. 关注点分离(单一责任)

    • Tomcat 运行时是标准的,不会在每个发布过程中更改。即Tomcat二进制文件
    • 发布过程可能会添加更多的东西,如 webapplication(webapps 文件夹)、环境配置(conf 目录)、logs/temp/work 目录