Step-by-Step Guide to Installing Java and Tomcat, Configuring Multiple Instances on Linux
This tutorial walks through installing Java 1.8, setting up Apache Tomcat 8.5.43 on a Linux server, configuring its directories, starting and stopping the service, managing logs, securing the webapps folder, and creating multiple Tomcat instances with custom ports and reverse‑proxy settings.
First, install the Java runtime environment: yum install java-1.8.0 -y Verify the installation with java -version, which should display something like:
openjdk version "1.8.0_222" OpenJDK Runtime Environment (build 1.8.0_222-b10) OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
Set the TOMCAT_HOME environment variable for all users: echo 'export TOMCAT_HOME=/opt/tomcat' >> /etc/profile Next, install Tomcat:
Check the Java version again (optional) and list the /opt directory to confirm the Tomcat archive is present: ls /opt → apache-tomcat-8.5.43.tar.gz Extract the archive and create a symbolic link named tomcat:
tar -zxvf apache-tomcat-8.5.43.tar.gz -C /opt/ ln -s apache-tomcat-8.5.43 tomcatThe webapps directory now contains the default applications (docs, examples, host‑manager, manager, ROOT).
In the bin directory, the key scripts are: startup.sh – starts Tomcat shutdown.sh – stops Tomcat catalina.sh – core management script for JVM options and Tomcat parameters
Start Tomcat with: ./startup.sh The console will show the CATALINA paths and confirm that Tomcat has started. Verify the Java process: ps -ef | grep java Log files are located in /opt/tomcat/logs (e.g., catalina.out, catalina.YYYY-MM-DD.log, localhost_access_log.YYYY-MM-DD.txt).
To stop Tomcat, run: ./bin/shutdown.sh After shutdown, check that no Java processes remain and optionally use netstat -nltp to confirm ports are free.
For security, move all files out of the webapps directory except the ROOT folder:
mv docs examples host-manager manager /tmp/ mv ROOT/* /tmp/Deploy your website by placing its content directly into the ROOT directory.
To run multiple Tomcat instances, copy the original installation directory and adjust each instance’s conf/server.xml ports with sed:
cp -a apache-tomcat-8.5.43 tomcat_01 cp -a apache-tomcat-8.5.43 tomcat_02Example port changes for the first instance:
sed -i 's#8005#8006#g' tomcat_01/conf/server.xml sed -i 's#8009#8010#g' tomcat_01/conf/server.xml sed -i 's#8080#8081#g' tomcat_01/conf/server.xmlAnd for the second instance:
sed -i 's#8005#8007#g' tomcat_02/conf/server.xml sed -i 's#8009#8011#g' tomcat_02/conf/server.xml sed -i 's#8080#8082#g' tomcat_02/conf/server.xmlStart each instance with its own startup.sh and configure a reverse‑proxy (e.g., Nginx) to route traffic to the different ports.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
