...
This guide covers downloading and installing Tomcat 8 on an Ubuntu Linux 9 on a linux server.
Prerequisites
You have installed Ubuntu 16 Linux.
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.
Instructions
Step 1 Create Tomcat user
Warning |
---|
Do not run Tomcat as root as this constitutes a security risk. |
...
Code Block |
---|
sudo groupadd tomcat sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat |
Step 2 Download and
...
install Tomcat
Excerpt |
---|
|
...
|
...
|
Download Tomcat
...
|
...
|
...
|
...
|
...
|
...
|
...
|
...
|
Step 3 Create a service wrapper
This stage step creates a wrapper which that allows tomcat Tomcat to be managed as a service. Using a service ; this allows tomcat to be stopped and started means you can stop and start Tomcat reliably, and ensures that the running environment (e.g. the starting directory) is well defined.
Specifically, these These instructions create a systemd
service.
First, create a service definition file:
...
- JAVA_HOME points to the version of java that you want to use
- 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)
- 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'
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 |
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 -verboseXlog: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 |
...