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

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.html

有幾種方法能夠將Tomcat設置爲在不一樣平臺上運行。這方面的主要文檔是一個名爲RUNNING.txt的文件 。若是如下信息沒法回答您的一些問題,咱們建議您參考該文件。java

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.web

使用Windows安裝程序能夠輕鬆地在Windows上安裝Tomcat。它的界面和功能相似於其餘基於嚮導的安裝程序,只有幾項須要注意的。apache

  • 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.bootstrap

安裝程序將建立容許啓動和配置Tomcat的快捷方式。請務必注意,Tomcat管理Web應用程序只能在Tomcat運行時使用。windows

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.tomcat

能夠使用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.bash

在運行腳本以前,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項目的官方文檔,本人在原文檔內容基礎上整理總結而得,中文翻譯僅供參考,英語不還錯的童鞋,能夠直接去官方查看最新的官方文檔哦!!!若是以爲對你有幫助,不要忘了點贊,評論,轉發喲!!!

相關文章
相關標籤/搜索