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
tomcat - CATALINA_BASE and CATALINA_HOME 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_HOME
and CATALINA_BASE
variables.
我在同一台服务器 (Linux) 上运行了多个 tomcat 6 实例,并且它按预期工作。我试图找出关于设置CATALINA_HOME
和CATALINA_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 withCATALINA_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_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. 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.txt
file 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.sh
sets the variables that Tomcat needs to work out of the box. It also says that CATALINA_BASE
is 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_BASE
is the same as CATALINA_HOME
.
CATALINA_BASE
与 相同CATALINA_HOME
。
回答by kenorb
CATALINA_HOME
vs 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_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. If multiple instances are not configured,$CATALINA_BASE
is the same as$CATALINA_HOME
.
可选地,可以通过
$CATALINA_BASE
为每个实例定义来为多个实例配置 Tomcat 。如果没有配置多个实例,$CATALINA_BASE
则与$CATALINA_HOME
.
See: Apache Tomcat 7 - Introduction
Running with separate CATALINA_HOME
and CATALINA_BASE
is documented in RUNNING.txt which say:
单独运行CATALINA_HOME
并CATALINA_BASE
记录在 RUNNING.txt 中,其中说:
The
CATALINA_HOME
andCATALINA_BASE
environment variables are used to specify the location of Apache Tomcat and the location of its active configuration, respectively.You cannot configure
CATALINA_HOME
andCATALINA_BASE
variables in thesetenv
script, because they are used to find that file.
的
CATALINA_HOME
和CATALINA_BASE
环境变量用于指定的Apache Tomcat的位置和它的活动配置的位置,分别。您不能在脚本中配置
CATALINA_HOME
和CATALINA_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_BASE
environment variable to the directory that contains the files for your 'personal' Tomcat instance.When running with a separate
CATALINA_HOME
andCATALINA_BASE
, the files and directories are split as following:In
CATALINA_BASE
:
bin
- Only: setenv.sh (*nix) or setenv.bat (Windows), tomcat-juli.jarconf
- Server configuration files (including server.xml)lib
- Libraries and classes, as explained belowlogs
- Log and output fileswebapps
- Automatically loaded web applicationswork
- Temporary working directories for web applicationstemp
- Directory used by the JVM for temporary files>In
CATALINA_HOME
:
bin
- Startup and shutdown scriptslib
- Libraries and classes, as explained belowendorsed
- Libraries that override standard "Endorsed Standards". By default it's absent.
在许多情况下,希望在同一服务器上的多个用户之间共享 Tomcat 二进制分发的单个副本。为了实现这一点,您可以将
CATALINA_BASE
环境变量设置为包含“个人”Tomcat 实例文件的目录。使用单独的
CATALINA_HOME
and运行时CATALINA_BASE
,文件和目录拆分如下:在
CATALINA_BASE
:
bin
- 仅:setenv.sh (*nix) 或 setenv.bat (Windows)、tomcat-juli.jarconf
- 服务器配置文件(包括 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_BASE
and CATALINA_HOME
is by running startup.sh
, for example:
最简单的方法来检查什么是你CATALINA_BASE
和CATALINA_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
以下工具(Debian / Ubuntu)检查Tomcat文件的安装位置:
dpkg -L tomcat7-common
回答by isapir
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
(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 makebase
utility. 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_BASE
environment variable. You will have to put some files in that directory:
要利用此功能,只需创建 config 目录并使用CATALINA_BASE
环境变量指向它。您必须在该目录中放置一些文件:
- Copy the
conf
directory 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
logs
directory ifconf/logging.properties
points to${catalina.base}/logs
, and ensure that Tomcat has read/write permissions to it. - 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. - Create a
work
directory 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_TMPDIR
which 指向的默认值,请创建一个目录${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 会有所帮助。
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.
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 个以上的 tomcat 实例在同一台主机上运行时
- 这有助于只有 1 个 tomcat 安装运行时,多个 CATALINA_BASE 服务器配置在不同的端口上运行。
- 如果需要任何修补或版本升级,只需进行 1 次安装更改,或需要测试/验证/签署。
关注点分离(单一责任)
- Tomcat 运行时是标准的,不会在每个发布过程中更改。即Tomcat二进制文件
- 发布过程可能会添加更多的东西,如 webapplication(webapps 文件夹)、环境配置(conf 目录)、logs/temp/work 目录