Master Tomcat: Install, Configure, and Deploy Multi-Instance Java Apps
This guide walks you through installing Tomcat on Linux, configuring its core components, understanding its directory layout, deploying a sample Java web application, and setting up multiple independent Tomcat instances on a single server for efficient resource utilization.
Tomcat Overview
Tomcat Concept
Tomcat is an open‑source lightweight application server written in Java, part of the Apache Software Foundation. It implements Java Servlet, JSP, and EL, enabling dynamic web applications on the Java platform.
Tomcat Role
Tomcat is a Java Servlet container used to run Java web applications.
Running Java Web Applications
Servlet and JSP support: Tomcat processes servlet and JSP requests, allowing developers to create dynamic content such as login functionality.
Web application deployment: Tomcat can deploy WAR files by placing them in the webapps directory, automatically extracting and starting them.
Web Server Functionality
HTTP/HTTPS service: Tomcat listens on ports (default 8080) and serves HTTP/HTTPS requests.
Static resource service: Tomcat serves static files like HTML, CSS, JavaScript, and images.
Development and Testing
Development environment support: Tomcat provides hot deployment, allowing changes to be reflected without restart.
IDE integration: Tomcat integrates with IDEs such as Eclipse and IntelliJ IDEA for deployment and debugging.
Installation and Deployment of Tomcat
Environment Information
Before installing Tomcat, install JDK 8. Use OpenJDK from https://jdk.java.net/java-se-ri/8-MR6.
mkdir -p /app/tools && cd /app/tools
wget https://download.java.net/openjdk/jdk8u44/ri/openjdk-8u44-linux-x64.tar.gz
tar -xf openjdk-8u44-linux-x64.tar.gz
ln -s /app/tools/java-se-8u44-ri/ /app/tools/jdk
echo "export JAVA_HOME=/app/tools/jdk" >> /etc/profile
echo "export PATH=$JAVA_HOME/bin:$PATH" >> /etc/profile
source /etc/profile
java -versionInstall Tomcat
Download Tomcat 9.0.50 from the Apache archive.
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.50/bin/apache-tomcat-9.0.50.tar.gz
tar -xf apache-tomcat-9.0.50.tar.gz
ln -s $(pwd)/apache-tomcat-9.0.50 tomcatStart Tomcat
cd tomcat/bin
./startup.sh
# Verify process and port
ps -ef | grep java
ss -lntup | grep 8080Open http://10.0.0.21:8080 in a browser to confirm Tomcat is running.
Tomcat Directory Structure
Tomcat contains several directories, each serving a specific purpose.
bin directory
The bin directory holds executable scripts such as startup.sh, shutdown.sh, catalina.sh, etc.
conf directory
The conf directory stores configuration files. server.xml – configures HTTP/HTTPS ports and other server settings. web.xml – auxiliary configuration file.
server.xml details
<?xml version="1.0" encoding="UTF-8"?>
<!-- 8005 shutdown port -->
<Server port="8005" shutdown="SHUTDOWN">
...
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>
<Engine name="Catalina" defaultHost="localhost">
...
</Engine>
</Server>Log format
%h – client IP address
%l – remote logical username
%u – remote user
%t – access time
%r – request line
%s – HTTP status code
%b – bytes sent
" – double quote
logs directory
Stores Tomcat logs such as catalina.out, daily rotated catalina.YYYY-MM-DD.log, and access logs.
webapps directory
Contains deployed web applications. The ROOT directory is the default web app.
Case: Deploy zrlog Application
Download the zrlog WAR file and deploy it as ROOT.war.
mkdir -p /app/war && cd /app/war
wget https://dl.zrlog.com/release/zrlog.war
mv /app/tools/tomcat/tomcat/webapps /app/tools/tomcat/tomcat/webapps_bak_$(date +%Y%m%d)
mkdir -p /app/tools/tomcat/tomcat/webapps
mv zrlog.war /app/tools/tomcat/tomcat/webapps/ROOT.warAccess the application at http://10.0.0.21:8080.
Create a MySQL container for the database.
docker run -d --name mysql_5.7 -p 3306:3306 --restart always -v /data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=1 mysql:5.7
docker exec -it mysql_5.7 mysql -uroot -p1 -e "create database zrlog;"Configure the database connection in zrlog and complete the setup.
Tomcat Multi-Instance Deployment
Background
When a server has ample resources, multiple Tomcat instances can be deployed to utilize the hardware efficiently.
Deployment Steps
Prepare multiple Tomcat directories
tar -xf apache-tomcat-9.0.50.tar.gz
cp -r apache-tomcat-9.0.50 tomcat_8081
cp -r apache-tomcat-9.0.50 tomcat_8082Modify ports
# For tomcat_8081
sed -i 's#8005#8006#g' tomcat_8081/conf/server.xml
sed -i 's#8080#8081#g' tomcat_8081/conf/server.xml
sed -i 's#8443#8444#g' tomcat_8081/conf/server.xml
# For tomcat_8082
sed -i 's#8006#8007#g' tomcat_8082/conf/server.xml
sed -i 's#8081#8082#g' tomcat_8082/conf/server.xml
sed -i 's#8444#8445#g' tomcat_8082/conf/server.xmlStart instances
./tomcat_8081/bin/startup.sh
./tomcat_8082/bin/startup.shVerify
ss -lntup | grep 8081
ss -lntup | grep 8082Access the instances at http://10.0.0.21:8081 and http://10.0.0.21:8082.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
