Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This guide covers downloading and installing Tomcat 9 on a linux server.

Prerequisites

You The following instructions assume that:

  • you can login as a non-root user with sudo access.

...

  • you have installed Java, with the required settings.

Step 1  Create Tomcat user

...

Excerpt
  1. Download

    1. To find the latest version, go to the Tomcat downloads page:
    2. for version 8: http://tomcat.apache.org/download-80.cgi
    3. for version 9https://tomcat.apache.org/download-90.cgi
    4. Find the latest Binary Distributions section, then the Core sub-heading, and copy the tar.gz link.
    5. To download Tomcat, on the Linux server, go to the tmp directory. Use the curl command to download from the the tar.gz link.

      Code Block
      cd /tmp
      curl -O http://mirror.ox.ac.uk/sites/rsync.apache.org/tomcat/tomcat-9/v9.0.38/bin/apache-tomcat-9.0.38.tar.gz


  2. Install
    1. Unpack the Tomcat tar.gz file into /opt/tomcat.

      Code Block
      sudo mkdir /opt/tomcat
      cd /opt/tomcat
      sudo tar xvf /tmp/apache-tomcat-9*tar.gz --strip-components=1


      This creates the tomcat folders (conf, logs, webapps etc.) directly under /opt/tomcat.
    2. Set the file ownership and permissions.

      Code Block
      cd /opt/tomcat
      sudo chown -R tomcat webapps/ work/ temp/ logs/
      sudo chgrp -R tomcat .
      sudo chmod -R g+r conf
      sudo chmod g+x conf


...

  1. JAVA_HOME points to the version of java that you want to use
  2. the memory settings (-Xms and -Xmx) on the line for CATALINECATALINA_OPTS are set as needed (this example assumes you are allocating 8GB of memory to tomcat)
  3. the location of the GC (Garbage Collection) log file, set in CATALINA_OPTS, is correct - in the examples below, this /opt/tomcat/logs

Java 8

Code Block
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/opt/jdk/jdk1.8.0_85/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms8096M -Xmx8096M -server -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/opt/tomcat/logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=10m'
-verbose:gcEnvironment='JAVA_OPTS=-Djava.awt.headless=true'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

WorkingDirectory=/opt/tomcat

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

Java 11

Code Block
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/opt/jdk/jdk-11.0.13+8
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms8096M -Xmx8096M -server -Xlog:gc:file=/opt/tomcat/logs/gc.log:time,level,tags:filecount=10,filesize=10m'
Environment='JAVA_OPTS=-Djava.awt.headless=true'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

WorkingDirectory=/opt/tomcat

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

...