Apache Tomcat 9 is not available from the standard RHEL distributions, so this article provides information about the manual installation and basic configuration of Apache Tomcat 9 on RHEL and its clones from tarballs. The tarball approach to installation is largely unchanged compared to previous tomcat versions.

Apache Tomcat 9 Installation on Linux (RHEL and clones)-LMLPHP

Related articles.

Downloads

Download the following software. This article assumes these downloads are present in the "/tmp" directory on the server.

  • (I used jdk-8u131-linux-x64.tar.gz)
  • (I used apache-tomcat-9.0.0.M22.tar.gz)

Installation

Create a user called "tomcat" to own the Tomcat installation.

# useradd tomcat

Install the JDK from the tarball under the tomcat user.

# su - tomcat
$ tar xzf /tmp/jdk-8uu131-linux-x64.gz

Install Tomcat from the tarball under the home directory of the "tomcat" user.

$ tar xzf /tmp/apache-tomcat-9.0.0.M22.tar.gz

Set the following environment variables and append them to the "/home/tomcat/.bash_profile" so they are set for subsequent logins.

export JAVA_HOME=/home/tomcat/jdk1.8.0_131
export CATALINA_HOME=/home/tomcat/apache-tomcat-9.0.0.M22
export CATALINA_BASE=$CATALINA_HOME

Start and stop Tomcat using the following scripts.

$ $CATALINA_HOME/bin/startup.sh
$ $CATALINA_HOME/bin/shutdown.sh

The Tomcat logs are written to the "$CATALINA_HOME/logs/" directory by default.

Once Tomcat is started, the following URL should be available. Configuration for the management URLs is discussed below.



Remember to open up the port on the firewall if you want to access the site from other servers on the network. Information about the Linux firewall is available .

Checking the Status of Tomcat

There are several ways to check the status of the service.

$ netstat -nlp | grep 8080
tcp        0      0 :::8080                     :::*                        LISTEN      4470/java          
$

$ ps -ef | grep tomcat
tomcat   17848     1  7 10:43 pts/0    00:00:14 /u01/java/jdk1.8.0_131/bin/java -Djava.util.logging.config.file=/home/tomcat/apache-tomcat-9.0.0.M22/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -classpath /home/tomcat/apache-tomcat-9.0.0.M22/bin/bootstrap.jar:/home/tomcat/apache-tomcat-9.0.0.M22/bin/tomcat-juli.jar -Dcatalina.base=/home/tomcat/apache-tomca -9.0.0.M22 -Dcatalina.home=/home/tomcat/apache-tomcat-9.0.0.M22 -Djava.io.tmpdir=/home/tomcat/apache-tomcat-9.0.0.M22/temp org.apache.catalina.startup.Bootstrap start
tomcat   18055 17257  0 10:43 pts/0    00:00:00 ps -ef
tomcat   18056 17257  0 10:43 pts/0    00:00:00 grep tomcat
$

$ curl -I
HTTP/1.1 200
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 13 Jul 2017 09:49:56 GMT

$

The status is also available from the HTML management page.

Configuration Files

The main locations of configuration and log information are shown below.

Release Notes        : $CATALINA_HOME
Config               : $CATALINA_HOME/conf
Bin Directory        : $CATALINA_HOME/bin
Webapps              : $CATALINA_HOME/webapps
Logs                 : $CATALINA_HOME/logs

Enabling HTML Management Access

Edit the "$CATALINA_HOME/conf/tomcat-users.xml" file, adding the following entries inside "tomcat-users" tag. Adjust the password as required.

<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="MyPassw0rd!" roles="manager-gui,admin-gui"/>

Edit the "$CATALINA_HOME/webapps/manager/META-INF/context.xml" and "$CATALINA_HOME/webapps/host-manager/META-INF/context.xml" file, disable the "Value" tag.

<!--

<Valve className="org.apache.catalina.valves.RemoteAddrValve"

allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

-->

Restart Tomcat for the configuration to take effect.

$ $CATALINA_HOME/bin/shutdown.sh
$ $CATALINA_HOME/bin/startup.sh

The management application is now available from the "" URL.

Deploying Applications

You can get a sample application WAR file to test with from "".

If this is a redeployment, delete the existing deployment from the "$CATALINA_HOME/webapps" directory.

# rm -Rf $CATALINA_HOME/webapps/sample

Place the "sample.war" file in the "$CATALINA_HOME/webapps" directory and Tomcat with automatically deploy it. You will see a "sample" directory appear.

You don't need to stop and start Tomcat for this to work, but you can if you want.

$ $CATALINA_HOME/bin/shutdown.sh
$ $CATALINA_HOME/bin/startup.sh

For more information see:

Hope this helps. Regards Tim...

来自 <>

05-02 17:02