Before proceeding with Apache Tomcat installation, please check current Java version by executing the following command:
java -versionIf Java isn't installed, please follow the Java installation manual: Apache Tomcat & Java download links for Linux
or use the following command to install the newest Java version:
sudo apt install default-jdk
After verifying that Java is installed, proceed with the Apache Tomcat installation.
For security reasons it's advised not to run Apache Tomcat under the root user. Alternatively, create a new group and system user to run the Apache Tomcat service from the /opt/tomcat directory.
sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
Download Apache Tomcat 9:
In the terminal switch to the /tmp directory by executing the following command:
cd /tmp
Use the curl command to download the package:
curl -O https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.97/bin/apache-tomcat-9.0.97.tar.gz
To extract the tar.gz Apache Tomcat installation file, create a new /opt/tomcat/ directory by executing the following command:
sudo mkdir /opt/tomcat
Extract the file into the new directory by implementing the following command:
sudo tar xzvf apache-tomcat-9.0.97.tar.gz -C /opt/tomcat --strip-components=1Note: the file name must be consistent with the file name installed in the previous step.
Switch to the directory where the Apache Tomcat installation is located using the following command:
cd /opt/tomcat
Grant group and user ownership over the installation directory to the tomcat group and user using the command:
sudo chown -RH tomcat: /opt/tomcat
Lastly, update the script permissions to grant execute access in /opt/tomcat/bin/with using the following command:
sudo sh -c 'chmod +x /opt/tomcat/bin/*.sh'
Since we are going to use Apache Tomcat as a service, we need to create a systemd service file.
To configure the file, you first must locate the JAVA_HOME path, which is the exact location of the Java installation package.
To do this, prompt the system for information about the installed Java packages. In the terminal, type:
sudo update-java-alternatives -lCreate and open a new file in the /PATH_TO_TOMCAT_FOLDER/bin under the name setenv.sh:
sudo vi /PATH_TO_TOMCAT_FOLDER/bin/setenv.sh
Once the file is open, copy and paste the content provided below, and update the parameter values to match the relevant values according to your configuration (java path & memory size):
export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
export JRE_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
# Java options
export JAVA_OPTS="-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true -Xms512m -Xmx1024m -server -XX:+CMSClassUnloadingEnabled"
# Tomcat-specific options
export CATALINA_OPTS="-Xms512m -Xmx1024m -server -XX:+UseParallelGC"Set up the JAVA_HOME path in the line:
- Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
Set up the JRE_HOME path in the line:
- Environment="JRE_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
Set up the Java allowed memory values in the line:
- "..JAVA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
Set up the quilliup service allowed memory values in the line:
- "..CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
Save the file and make it executable:
chmod +x setenv.sh
Now you can run the service.
For more details about running the service and replacing the *.war file (quilliup installation package) follow the relevant quilliup upgrade user guide (Linux)
Note: before installing the *.war file, delete the temporary ROOT folder that was created with Apache Tomcat installation:
cd /opt/tomcat/webapps
rm -rf ROOT
Comments
0 comments
Please sign in to leave a comment.