Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame^] | 1 | ================================================================================
|
| 2 | Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 | contributor license agreements. See the NOTICE file distributed with
|
| 4 | this work for additional information regarding copyright ownership.
|
| 5 | The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 | (the "License"); you may not use this file except in compliance with
|
| 7 | the License. You may obtain a copy of the License at
|
| 8 |
|
| 9 | http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
|
| 11 | Unless required by applicable law or agreed to in writing, software
|
| 12 | distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 | See the License for the specific language governing permissions and
|
| 15 | limitations under the License.
|
| 16 | ================================================================================
|
| 17 |
|
| 18 | ===================================================
|
| 19 | Running The Apache Tomcat 6.0 Servlet/JSP Container
|
| 20 | ===================================================
|
| 21 |
|
| 22 | Apache Tomcat 6.0 requires a Java Standard Edition Runtime
|
| 23 | Environment (JRE) version 5.0 or later.
|
| 24 |
|
| 25 | =============================
|
| 26 | Running With JRE 5.0 Or Later
|
| 27 | =============================
|
| 28 |
|
| 29 | (1) Download and Install a Java SE Runtime Environment (JRE)
|
| 30 |
|
| 31 | (1.1) Download a Java SE Runtime Environment (JRE),
|
| 32 | release version 5.0 or later, from
|
| 33 | http://www.oracle.com/technetwork/java/javase/downloads/index.html
|
| 34 |
|
| 35 | (1.2) Install the JRE according to the instructions included with the
|
| 36 | release.
|
| 37 |
|
| 38 | You may also use a full Java Development Kit (JDK) rather than just
|
| 39 | a JRE.
|
| 40 |
|
| 41 |
|
| 42 | (2) Download and Install Apache Tomcat
|
| 43 |
|
| 44 | (2.1) Download a binary distribution of Tomcat from:
|
| 45 |
|
| 46 | http://tomcat.apache.org/
|
| 47 |
|
| 48 | (2.2) Unpack the binary distribution so that it resides in its own
|
| 49 | directory (conventionally named "apache-tomcat-[version]").
|
| 50 |
|
| 51 | For the purposes of the remainder of this document, the name
|
| 52 | "CATALINA_HOME" is used to refer to the full pathname of that
|
| 53 | directory.
|
| 54 |
|
| 55 | NOTE: As an alternative to downloading a binary distribution, you can
|
| 56 | create your own from the Tomcat source code, as described in
|
| 57 | "BUILDING.txt". You can either
|
| 58 |
|
| 59 | a) Do the full "release" build and find the created distribution in the
|
| 60 | "output/release" directory and then proceed with unpacking as above, or
|
| 61 |
|
| 62 | b) Do a simple build and use the "output/build" directory as
|
| 63 | "CATALINA_HOME". Be warned that there are some differences between the
|
| 64 | contents of the "output/build" directory and a full "release"
|
| 65 | distribution.
|
| 66 |
|
| 67 |
|
| 68 | (3) Configure Environment Variables
|
| 69 |
|
| 70 | Tomcat is a Java application and does not use environment variables. The
|
| 71 | variables are used by the Tomcat startup scripts. The scripts use the variables
|
| 72 | to prepare the command that starts Tomcat.
|
| 73 |
|
| 74 | (3.1) Set CATALINA_HOME (required) and CATALINA_BASE (optional)
|
| 75 |
|
| 76 | The CATALINA_HOME environment variable should be set to the location of the
|
| 77 | root directory of the "binary" distribution of Tomcat.
|
| 78 |
|
| 79 | An example was given in (2.2) above.
|
| 80 |
|
| 81 | The Tomcat startup scripts have some logic to set this variable
|
| 82 | automatically if it is absent, based on the location of the startup script
|
| 83 | in *nix and on the current directory in Windows. That logic might not work
|
| 84 | in all circumstances, so setting the variable explicitly is recommended.
|
| 85 |
|
| 86 | The CATALINA_BASE environment variable specifies location of the root
|
| 87 | directory of the "active configuration" of Tomcat. It is optional. It
|
| 88 | defaults to be equal to CATALINA_HOME.
|
| 89 |
|
| 90 | Using distinct values for the CATALINA_HOME and CATALINA_BASE variables is
|
| 91 | recommended to simplify further upgrades and maintenance. It is documented
|
| 92 | in the "Multiple Tomcat Instances" section below.
|
| 93 |
|
| 94 |
|
| 95 | (3.2) Set JRE_HOME or JAVA_HOME (required)
|
| 96 |
|
| 97 | These variables are used to specify location of a Java Runtime
|
| 98 | Environment or of a Java Development Kit that is used to start Tomcat.
|
| 99 |
|
| 100 | The JRE_HOME variable is used to specify location of a JRE. The JAVA_HOME
|
| 101 | variable is used to specify location of a JDK.
|
| 102 |
|
| 103 | Using JAVA_HOME provides access to certain additional startup options that
|
| 104 | are not allowed when JRE_HOME is used.
|
| 105 |
|
| 106 | If both JRE_HOME and JAVA_HOME are specified, JRE_HOME is used.
|
| 107 |
|
| 108 | The recommended place to specify these variables is a "setenv" script. See
|
| 109 | below.
|
| 110 |
|
| 111 |
|
| 112 | (3.3) Other variables (optional)
|
| 113 |
|
| 114 | Other environment variables exist, besides the four described above.
|
| 115 | See the comments at the top of catalina.bat or catalina.sh scripts for
|
| 116 | the list and a description of each of them.
|
| 117 |
|
| 118 | One frequently used variable is CATALINA_OPTS. It allows specification of
|
| 119 | additional options for the java command that starts Tomcat.
|
| 120 |
|
| 121 | See the Java documentation for the options that affect the Java Runtime
|
| 122 | Environment.
|
| 123 |
|
| 124 | See the "System Properties" page in the Tomcat Configuration Reference for
|
| 125 | the system properties that are specific to Tomcat.
|
| 126 |
|
| 127 | A similar variable is JAVA_OPTS. It is used less frequently. It allows
|
| 128 | specification of options that are used both to start and to stop Tomcat as well
|
| 129 | as for other commands.
|
| 130 |
|
| 131 | Note: Do not use JAVA_OPTS to specify memory limits. You do not need much
|
| 132 | memory for a small process that is used to stop Tomcat. Those settings
|
| 133 | belong to CATALINA_OPTS.
|
| 134 |
|
| 135 | Another frequently used variable is CATALINA_PID (on *nix only). It
|
| 136 | specifies the location of the file where process id of the forked Tomcat
|
| 137 | java process will be written. This setting is optional. It will enable the
|
| 138 | following features:
|
| 139 |
|
| 140 | * better protection against duplicate start attempts and
|
| 141 | * allows forceful termination of Tomcat process when it does not react to
|
| 142 | the standard shutdown command.
|
| 143 |
|
| 144 |
|
| 145 | (3.4) Using the "setenv" script (optional, recommended)
|
| 146 |
|
| 147 | Apart from CATALINA_HOME and CATALINA_BASE, all environment variables can
|
| 148 | be specified in the "setenv" script. The script is placed either into
|
| 149 | CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named
|
| 150 | setenv.bat (on Windows) or setenv.sh (on *nix). The file has to be
|
| 151 | readable.
|
| 152 |
|
| 153 | By default the setenv script file is absent. If the script file is present
|
| 154 | both in CATALINA_BASE and in CATALINA_HOME, the one in CATALINA_BASE is
|
| 155 | preferred.
|
| 156 |
|
| 157 | For example, to configure the JRE_HOME and CATALINA_PID variables you can
|
| 158 | create the following script file:
|
| 159 |
|
| 160 | On Windows, %CATALINA_BASE%\bin\setenv.bat:
|
| 161 |
|
| 162 | set "JRE_HOME=%ProgramFiles%\Java\jre6"
|
| 163 | exit /b 0
|
| 164 |
|
| 165 | On *nix, $CATALINA_BASE/bin/setenv.sh:
|
| 166 |
|
| 167 | JRE_HOME=/usr/java/latest
|
| 168 | CATALINA_PID="$CATALINA_BASE/tomcat.pid"
|
| 169 |
|
| 170 |
|
| 171 | The CATALINA_HOME and CATALINA_BASE variables cannot be configured in the
|
| 172 | setenv script, because they are used to locate that file.
|
| 173 |
|
| 174 | All the environment variables described here and the "setenv" script are
|
| 175 | used only if you use the standard scripts to launch Tomcat. For example, if
|
| 176 | you have installed Tomcat as a service on Windows, the service wrapper
|
| 177 | launches Java directly and does not use the script files.
|
| 178 |
|
| 179 |
|
| 180 | (4) Start Up Tomcat
|
| 181 |
|
| 182 | (4.1) Tomcat can be started by executing one of the following commands:
|
| 183 |
|
| 184 | On Windows:
|
| 185 |
|
| 186 | %CATALINA_HOME%\bin\startup.bat
|
| 187 |
|
| 188 | or
|
| 189 |
|
| 190 | %CATALINA_HOME%\bin\catalina.bat start
|
| 191 |
|
| 192 | On *nix:
|
| 193 |
|
| 194 | $CATALINA_HOME/bin/startup.sh
|
| 195 |
|
| 196 | or
|
| 197 |
|
| 198 | $CATALINA_HOME/bin/catalina.sh start
|
| 199 |
|
| 200 | (4.2) After startup, the default web applications included with Tomcat will be
|
| 201 | available by visiting:
|
| 202 |
|
| 203 | http://localhost:8080/
|
| 204 |
|
| 205 | (4.3) Further information about configuring and running Tomcat can be found in
|
| 206 | the documentation included here, as well as on the Tomcat web site:
|
| 207 |
|
| 208 | http://tomcat.apache.org/
|
| 209 |
|
| 210 |
|
| 211 | (5) Shut Down Tomcat
|
| 212 |
|
| 213 | (5.1) Tomcat can be shut down by executing one of the following commands:
|
| 214 |
|
| 215 | On Windows:
|
| 216 |
|
| 217 | %CATALINA_HOME%\bin\shutdown.bat
|
| 218 |
|
| 219 | or
|
| 220 |
|
| 221 | %CATALINA_HOME%\bin\catalina.bat stop
|
| 222 |
|
| 223 | On *nix:
|
| 224 |
|
| 225 | $CATALINA_HOME/bin/shutdown.sh
|
| 226 |
|
| 227 | or
|
| 228 |
|
| 229 | $CATALINA_HOME/bin/catalina.sh stop
|
| 230 |
|
| 231 | ==================================================
|
| 232 | Advanced Configuration - Multiple Tomcat Instances
|
| 233 | ==================================================
|
| 234 |
|
| 235 | In many circumstances, it is desirable to have a single copy of a Tomcat
|
| 236 | binary distribution shared among multiple users on the same server. To make
|
| 237 | this possible, you can set the CATALINA_BASE environment variable to the
|
| 238 | directory that contains the files for your 'personal' Tomcat instance.
|
| 239 |
|
| 240 | When running with a separate CATALINA_HOME and CATALINA_BASE, the files
|
| 241 | and directories are split as following:
|
| 242 |
|
| 243 | In CATALINA_BASE:
|
| 244 |
|
| 245 | * bin - Only the following files:
|
| 246 |
|
| 247 | * setenv.sh (*nix) or setenv.bat (Windows),
|
| 248 | * tomcat-juli.jar
|
| 249 |
|
| 250 | The setenv scripts were described above. The tomcat-juli library
|
| 251 | is documented in the Logging chapter in the User Guide.
|
| 252 |
|
| 253 | * conf - Server configuration files (including server.xml)
|
| 254 |
|
| 255 | * lib - Libraries and classes, as explained below
|
| 256 |
|
| 257 | * logs - Log and output files
|
| 258 |
|
| 259 | * webapps - Automatically loaded web applications
|
| 260 |
|
| 261 | * work - Temporary working directories for web applications
|
| 262 |
|
| 263 | * temp - Directory used by the JVM for temporary files (java.io.tmpdir)
|
| 264 |
|
| 265 |
|
| 266 | In CATALINA_HOME:
|
| 267 |
|
| 268 | * bin - Startup and shutdown scripts
|
| 269 |
|
| 270 | The following files will be used only if they are absent in
|
| 271 | CATALINA_BASE/bin:
|
| 272 |
|
| 273 | setenv.sh (*nix), setenv.bat (Windows), tomcat-juli.jar
|
| 274 |
|
| 275 | * lib - Libraries and classes, as explained below
|
| 276 |
|
| 277 | * endorsed - Libraries that override standard "Endorsed Standards"
|
| 278 | libraries provided by JRE. See Classloading documentation
|
| 279 | in the User Guide for details.
|
| 280 |
|
| 281 | By default this "endorsed" directory is absent.
|
| 282 |
|
| 283 | In the default configuration the JAR libraries and classes both in
|
| 284 | CATALINA_BASE/lib and in CATALINA_HOME/lib will be added to the common
|
| 285 | classpath, but the ones in CATALINA_BASE will be added first and thus will
|
| 286 | be searched first.
|
| 287 |
|
| 288 | The idea is that you may leave the standard Tomcat libraries in
|
| 289 | CATALINA_HOME/lib and add other ones such as database drivers into
|
| 290 | CATALINA_BASE/lib.
|
| 291 |
|
| 292 | In general it is advised to never share libraries between web applications,
|
| 293 | but put them into WEB-INF/lib directories inside the applications. See
|
| 294 | Classloading documentation in the User Guide for details.
|
| 295 |
|
| 296 |
|
| 297 | It might be useful to note that the values of CATALINA_HOME and
|
| 298 | CATALINA_BASE can be referenced in the XML configuration files processed
|
| 299 | by Tomcat as ${catalina.home} and ${catalina.base} respectively.
|
| 300 |
|
| 301 | For example, the standard manager web application can be kept in
|
| 302 | CATALINA_HOME/webapps/manager and loaded into CATALINA_BASE by using
|
| 303 | the following trick:
|
| 304 |
|
| 305 | * Copy the CATALINA_HOME/webapps/manager/META-INF/context.xml
|
| 306 | file as CATALINA_BASE/conf/Catalina/localhost/manager.xml
|
| 307 |
|
| 308 | * Add docBase attribute as shown below.
|
| 309 |
|
| 310 | The file will look like the following:
|
| 311 |
|
| 312 | <?xml version="1.0" encoding="UTF-8"?>
|
| 313 | <Context docBase="${catalina.home}/webapps/manager"
|
| 314 | antiResourceLocking="false" privileged="true" useHttpOnly="true" >
|
| 315 | <Valve className="org.apache.catalina.valves.RemoteAddrValve"
|
| 316 | allow="127\.0\.0\.1" />
|
| 317 | </Context>
|
| 318 |
|
| 319 | See Deployer chapter in User Guide and Context and Host chapters in the
|
| 320 | Configuration Reference for more information on contexts and web
|
| 321 | application deployment.
|
| 322 |
|
| 323 |
|
| 324 | ================
|
| 325 | Troubleshooting
|
| 326 | ================
|
| 327 |
|
| 328 | There are only really 2 things likely to go wrong during the stand-alone
|
| 329 | Tomcat install:
|
| 330 |
|
| 331 | (1) The most common hiccup is when another web server (or any process for that
|
| 332 | matter) has laid claim to port 8080. This is the default HTTP port that
|
| 333 | Tomcat attempts to bind to at startup. To change this, open the file:
|
| 334 |
|
| 335 | $CATALINA_HOME/conf/server.xml
|
| 336 |
|
| 337 | and search for '8080'. Change it to a port that isn't in use, and is
|
| 338 | greater than 1024, as ports less than or equal to 1024 require superuser
|
| 339 | access to bind under UNIX.
|
| 340 |
|
| 341 | Restart Tomcat and you're in business. Be sure that you replace the "8080"
|
| 342 | in the URL you're using to access Tomcat. For example, if you change the
|
| 343 | port to 1977, you would request the URL http://localhost:1977/ in your
|
| 344 | browser.
|
| 345 |
|
| 346 | (2) The 'localhost' machine isn't found. This could happen if you're behind a
|
| 347 | proxy. If that's the case, make sure the proxy configuration for your
|
| 348 | browser knows that you shouldn't be going through the proxy to access the
|
| 349 | "localhost".
|
| 350 |
|
| 351 | In Firefox, this is under Tools/Preferences -> Advanced/Network ->
|
| 352 | Connection -> Settings..., and in Internet Explorer it is Tools ->
|
| 353 | Internet Options -> Connections -> LAN Settings.
|
| 354 |
|
| 355 |
|
| 356 | ====================
|
| 357 | Optional Components
|
| 358 | ====================
|
| 359 |
|
| 360 | The following optional components may be included with the Apache Tomcat binary
|
| 361 | distribution. If they are not included, you can install them separately.
|
| 362 |
|
| 363 | 1. Apache Tomcat Native library
|
| 364 |
|
| 365 | 2. Apache Commons Daemon service launcher
|
| 366 |
|
| 367 | Both of them are implemented in C language and as such have to be compiled
|
| 368 | into binary code. The binary code will be specific for a platform and CPU
|
| 369 | architecture and it must match the Java Runtime Environment executables
|
| 370 | that will be used to launch Tomcat.
|
| 371 |
|
| 372 | The Windows-specific binary distributions of Apache Tomcat include binary
|
| 373 | files for these components. On other platforms you would have to look for
|
| 374 | binary versions elsewhere or compile them yourself.
|
| 375 |
|
| 376 | If you are new to Tomcat, do not bother with these components to start with.
|
| 377 | If you do use them, do not forget to read their documentation.
|
| 378 |
|
| 379 |
|
| 380 | Apache Tomcat Native library
|
| 381 | -----------------------------
|
| 382 |
|
| 383 | It is a library that allows to use the "Apr" variant of HTTP and AJP
|
| 384 | protocol connectors in Apache Tomcat. It is built around OpenSSL and Apache
|
| 385 | Portable Runtime (APR) libraries. Those are the same libraries as used by
|
| 386 | Apache HTTPD Server project.
|
| 387 |
|
| 388 | This feature was especially important in the old days when Java performance
|
| 389 | was poor. It is less important nowadays, but it is still used and respected
|
| 390 | by many. See Tomcat documentation for more details.
|
| 391 |
|
| 392 | For further reading:
|
| 393 |
|
| 394 | - Apache Tomcat documentation
|
| 395 |
|
| 396 | * Documentation for APR/Native library in the Tomcat User's Guide
|
| 397 |
|
| 398 | http://tomcat.apache.org/tomcat-6.0-doc/apr.html
|
| 399 |
|
| 400 | * Documentation for the HTTP and AJP protocol connectors in the Tomcat
|
| 401 | Configuration Reference
|
| 402 |
|
| 403 | http://tomcat.apache.org/tomcat-6.0-doc/config/http.html
|
| 404 |
|
| 405 | http://tomcat.apache.org/tomcat-6.0-doc/config/ajp.html
|
| 406 |
|
| 407 | - Apache Tomcat Native project home
|
| 408 |
|
| 409 | http://tomcat.apache.org/native-doc/
|
| 410 |
|
| 411 | - Other projects
|
| 412 |
|
| 413 | * OpenSSL
|
| 414 |
|
| 415 | http://openssl.org/
|
| 416 |
|
| 417 | * Apache Portable Runtime
|
| 418 |
|
| 419 | http://apr.apache.org/
|
| 420 |
|
| 421 | * Apache HTTP Server
|
| 422 |
|
| 423 | http://httpd.apache.org/
|
| 424 |
|
| 425 | To disable Apache Tomcat Native library:
|
| 426 |
|
| 427 | - To disable Apache Tomcat Native library when it is installed, or
|
| 428 | - To remove the warning that is logged during Tomcat startup when the
|
| 429 | library is not installed:
|
| 430 |
|
| 431 | Edit the "conf/server.xml" file and remove "AprLifecycleListener" from
|
| 432 | it.
|
| 433 |
|
| 434 | The binary file of Apache Tomcat Native library is usually named
|
| 435 |
|
| 436 | - "tcnative-1.dll" on Windows
|
| 437 | - "libtcnative-1.so" on *nix systems
|
| 438 |
|
| 439 |
|
| 440 | Apache Commons Daemon
|
| 441 | ----------------------
|
| 442 |
|
| 443 | Apache Commons Daemon project provides wrappers that can be used to
|
| 444 | install Apache Tomcat as a service on Windows or as a daemon on *nix
|
| 445 | systems.
|
| 446 |
|
| 447 | The Windows-specific implementation of Apache Commons Daemon is called
|
| 448 | "procrun". The *nix-specific one is called "jsvc".
|
| 449 |
|
| 450 | For further reading:
|
| 451 |
|
| 452 | - Apache Commons Daemon project
|
| 453 |
|
| 454 | http://commons.apache.org/daemon/
|
| 455 |
|
| 456 | - Apache Tomcat documentation
|
| 457 |
|
| 458 | * Installing Apache Tomcat
|
| 459 |
|
| 460 | http://tomcat.apache.org/tomcat-6.0-doc/setup.html
|
| 461 |
|
| 462 | * Windows service HOW-TO
|
| 463 |
|
| 464 | http://tomcat.apache.org/tomcat-6.0-doc/windows-service-howto.html
|
| 465 |
|
| 466 | The binary files of Apache Commons Daemon in Apache Tomcat distributions
|
| 467 | for Windows are named:
|
| 468 |
|
| 469 | - "tomcat6.exe"
|
| 470 | - "tomcat6w.exe"
|
| 471 |
|
| 472 | These files are renamed copies of "prunsrv.exe" and "prunmgr.exe" from
|
| 473 | Apache Commons Daemon distribution. The file names have a meaning: they are
|
| 474 | used as the service name to register the service in Windows, as well as the
|
| 475 | key name to store distinct configuration for this installation of
|
| 476 | "procrun". If you would like to install several instances of Tomcat 6.0
|
| 477 | in parallel, you have to further rename those files, using the same naming
|
| 478 | scheme.
|