03-《Apache Tomcat 9 User Guide》之安装

廉价感情. 提交于 2019-12-02 15:46:39

1.Introduction

There are several ways to set up Tomcat for running on different platforms. The main documentation for this is a file called RUNNING.txt. We encourage you to refer to that file if the information below does not answer some of your questions.

有几种方法可以将Tomcat设置为在不同平台上运行。这方面的主要文档是一个名为RUNNING.txt的文件 。如果以下信息无法回答您的一些问题,我们建议您参考该文件。

2.Windows

Installing Tomcat on Windows can be done easily using the Windows installer. Its interface and functionality is similar to other wizard based installers, with only a few items of interest.

使用Windows安装程序可以轻松地在Windows上安装Tomcat。它的界面和功能类似于其他基于向导的安装程序,只有几项需要注意的。

  • Installation as a service: Tomcat will be installed as a Windows service no matter what setting is selected. Using the checkbox on the component page sets the service as "auto" startup, so that Tomcat is automatically started when Windows starts. For optimal security, the service should be run as a separate user, with reduced permissions (see the Windows Services administration tool and its documentation).
  • 作为服务安装:无论选择何种设置,Tomcat都将作为Windows服务安装。使用组件页面上的复选框将服务设置为“自动”启动,以便在Windows启动时自动启动Tomcat。为获得最佳安全性,该服务应作为单独的用户运行,权限降低(请参阅Windows服务管理工具及其文档)。
  • Java location: The installer will provide a default JRE to use to run the service. The installer uses the registry to determine the base path of a Java 8 or later JRE, including the JRE installed as part of the full JDK. When running on a 64-bit operating system, the installer will first look for a 64-bit JRE and only look for a 32-bit JRE if a 64-bit JRE is not found. It is not mandatory to use the default JRE detected by the installer. Any installed Java 8 or later JRE (32-bit or 64-bit) may be used.
  • Java位置:安装程序将提供用于运行服务的默认JRE。安装程序使用注册表来确定Java 8或更高版本JRE的基本路径,包括作为完整JDK的一部分安装的JRE。在64位操作系统上运行时,安装程​​序将首先查找64位JRE,如果未找到64位JRE,则仅查找32位JRE。使用安装程序检测到的默认JRE不是必需的。可以使用任何已安装的Java 8或更高版本的JRE(32位或64位)。
  • Tray icon: When Tomcat is run as a service, there will not be any tray icon present when Tomcat is running. Note that when choosing to run Tomcat at the end of installation, the tray icon will be used even if Tomcat was installed as a service.
  • 托盘图标:当Tomcat作为服务运行时,Tomcat运行时不会出现任何托盘图标。请注意,在安装结束时选择运行Tomcat时,即使Tomcat作为服务安装,也将使用托盘图标。
  • Defaults: The defaults used by the installer may be overridden by use of the /C=<config file> command line argument. The configuration file uses the format name=value with each pair on a separate line. The names of the available configuration options are:
  • 默认值:可以使用/C=<config file>命令行参数覆盖安装程序使用的默认值。配置文件name=value在单独的行上使用每对的格式 。可用配置选项的名称是:
    • JavaHome
    • TomcatPortShutdown
    • TomcatPortHttp
    • TomcatPortAjp
    • TomcatMenuEntriesEnable
    • TomcatShortcutAllUsers
    • TomcatServiceDefaultName
    • TomcatServiceName
    • TomcatServiceFileName
    • TomcatServiceManagerFileName
    • TomcatAdminEnable
    • TomcatAdminUsername
    • TomcatAdminPassword
    • TomcatAdminRoles
    By using /C=... along with /S and /D= it is possible to perform fully configured unattended installs of Apache Tomcat. 通过/C=...一起使用/S, /D=可以执行Apache Tomcat的完全配置的无人参与安装。
  • Refer to the Windows Service HOW-TO for information on how to manage Tomcat as a Windows service.
  • 关如何将Tomcat作为Windows服务进行管理的信息,请参阅 Windows Service HOW-TO

The installer will create shortcuts allowing starting and configuring Tomcat. It is important to note that the Tomcat administration web application can only be used when Tomcat is running.

安装程序将创建允许启动和配置Tomcat的快捷方式。请务必注意,Tomcat管理Web应用程序只能在Tomcat运行时使用。

3.Unix daemon

Tomcat can be run as a daemon using the jsvc tool from the commons-daemon project. Source tarballs for jsvc are included with the Tomcat binaries, and need to be compiled. Building jsvc requires a C ANSI compiler (such as GCC), GNU Autoconf, and a JDK.

可以使用commons-daemon项目中的jsvc工具将Tomcat作为守护程序运行。jsvc的源代码压缩包包含在Tomcat二进制文件中,需要编译。构建jsvc需要C ANSI编译器(例如GCC),GNU Autoconf和JDK。

Before running the script, the JAVA_HOME environment variable should be set to the base path of the JDK. Alternately, when calling the ./configure script, the path of the JDK may be specified using the --with-java parameter, such as ./configure --with-java=/usr/java.

在运行脚本之前,JAVA_HOME应将环境变量设置为JDK的基本路径。或者,在调用./configure脚本时,可以使用--with-java参数指定JDK的路径,例如 ./configure --with-java=/usr/java

Using the following commands should result in a compiled jsvc binary, located in the $CATALINA_HOME/bin folder. This assumes that GNU TAR is used, and that CATALINA_HOME is an environment variable pointing to the base path of the Tomcat installation.

使用以下命令应该会生成位于该$CATALINA_HOME/bin文件夹中的已编译的jsvc二进制文件。这假设使用了GNU TAR,这CATALINA_HOME是一个指向Tomcat安装基本路径的环境变量。

Please note that you should use the GNU make (gmake) instead of the native BSD make on FreeBSD systems.

请注意,您应该在FreeBSD系统上使用GNU make(gmake)而不是本机BSD make。

cd $CATALINA_HOME/bin
tar xvfz commons-daemon-native.tar.gz
cd commons-daemon-1.1.x-native-src/unix
./configure
make
cp jsvc ../..
cd ../..

Tomcat can then be run as a daemon using the following commands.

然后可以使用以下命令将Tomcat作为守护程序运行。

CATALINA_BASE=$CATALINA_HOME
cd $CATALINA_HOME
./bin/jsvc \
    -classpath $CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/tomcat-juli.jar \
    -outfile $CATALINA_BASE/logs/catalina.out \
    -errfile $CATALINA_BASE/logs/catalina.err \
    -Dcatalina.home=$CATALINA_HOME \
    -Dcatalina.base=$CATALINA_BASE \
    -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
    -Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties \
    org.apache.catalina.startup.Bootstrap

When running on Java 9 you will need to additionally specify the following when starting jsvc to avoid warnings on shutdown.

在Java 9上运行时,您需要在启动jsvc时另外指定以下内容以避免在关闭时发出警告。

...
--add-opens=java.base/java.lang=ALL-UNNAMED \
--add-opens=java.base/java.io=ALL-UNNAMED \
--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED \
...

You may also need to specify -jvm server if the JVM defaults to using a server VM rather than a client VM. This has been observed on OSX.

您可能还需要指定-jvm serverJVM是否默认使用服务器VM而不是客户端VM。这已在OSX上观察到。

jsvc has other useful parameters, such as -user which causes it to switch to another user after the daemon initialization is complete. This allows, for example, running Tomcat as a non privileged user while still being able to use privileged ports. Note that if you use this option and start Tomcat as root, you'll need to disable the org.apache.catalina.security.SecurityListener check that prevents Tomcat starting when running as root.

jsvc还有其他有用的参数,例如 -user 在守护进程初始化完成后它会切换到另一个用户。例如,这允许将Tomcat作为非特权用户运行,同时仍然可以使用特权端口。请注意,如果您使用此选项并以root身份启动Tomcat,则需要禁用org.apache.catalina.security.SecurityListener以root身份运行时阻止Tomcat启动的 检查。

jsvc --help will return the full jsvc usage information. In particular, the -debug option is useful to debug issues running jsvc.

jsvc --help将返回完整的jsvc使用信息。特别是,该-debug选项对于调试运行jsvc的问题很有用。

The file $CATALINA_HOME/bin/daemon.sh can be used as a template for starting Tomcat automatically at boot time from /etc/init.d with jsvc.

该文件$CATALINA_HOME/bin/daemon.sh可用作模板,以便在启动时/etc/init.d使用jsvc 自动启动Tomcat 。

Note that the Commons-Daemon JAR file must be on your runtime classpath to run Tomcat in this manner. The Commons-Daemon JAR file is in the Class-Path entry of the bootstrap.jar manifest, but if you get a ClassNotFoundException or a NoClassDefFoundError for a Commons-Daemon class, add the Commons-Daemon JAR to the -cp argument when launching jsvc.

请注意,Commons-Daemon JAR文件必须位于运行时类路径上才能以这种方式运行Tomcat。Commons-Daemon JAR文件位于bootstrap.jar清单的Class-Path条目中,但如果您获得Commons-Daemon类的ClassNotFoundException或NoClassDefFoundError,则在启动jsvc时将Commons-Daemon JAR添加到-cp参数。

 

      声明,本文内容来自于Apache基金会官网关于Tomcat项目的官方文档,本人在原文档内容基础上整理总结而得,中文翻译仅供参考,英语不还错的童鞋,可以直接去官方查看最新的官方文档哦!!!如果觉得对你有帮助,不要忘了点赞,评论,转发哟!!!

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!