Master Tomcat: Install, Configure, and Optimize Your Java Web Server
This guide walks you through Tomcat’s role as a lightweight Java web server, details the prerequisites and step‑by‑step installation, shows how to configure environment variables, adjust ports, and apply performance optimizations such as disabling AJP, switching to NIO, and tuning JVM settings for production use.
Tomcat Introduction
Tomcat is a free, open‑source web application server that serves as a lightweight servlet and JSP container, ideal for small‑to‑medium projects and for developing and debugging JSP programs. It runs as an independent process, often alongside Apache which handles static HTML.
Tomcat Installation
Prerequisites
Before installing Tomcat, install the Java Development Kit (JDK). The JDK provides the JVM, which executes compiled Java bytecode and ensures cross‑platform compatibility.
Download Links
JDK: http://www.oracle.com/technetwork/java/javase/downloads/
Tomcat: http://tomcat.apache.org
Installation Steps
# Remove existing OpenJDK
rm -rf $(which java)
# Extract JDK
tar xf jdk-7u80-linux-x64.tar
# Move JDK to /usr/local/java
mv jdk1.7.0_80/ /usr/local/java # Extract Tomcat
tar xf apache-tomcat-8.5.20.tar.gz
# Move Tomcat to /usr/local/tomcat8
mv apache-tomcat-8.5.20 /usr/local/tomcat8 # Set JAVA environment variables
vim /etc/profile.d/java.sh
export JAVA_HOME="/usr/local/java"
export PATH=$PATH:$JAVA_HOME/bin:/usr/local/tomcat8/bin
. /etc/profile # Verify Java version
java -version # Start Tomcat
/usr/local/tomcat7/bin/startup.sh # Stop Tomcat
/usr/local/tomcat7/bin/shutdown.shPort Modification
# Edit server.xml to change ports
vim /usr/local/tomcat8/conf/server.xml
# Example changes:
# 8080 -> 9528
# 8005 -> 9529
# 8009 -> 9530Tomcat Optimization
Disable AJP Connector
# Comment out the AJP connector in server.xml
<!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/> -->Switch BIO to NIO
# Use NIO protocol for better concurrency
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"/>Enable External Thread Pool
# Define an executor and reference it in the Connector
<Executor name="tomcatThreadPool" maxThreads="1000" minSpareThreads="100"/>
<Connector executor="tomcatThreadPool" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="1000" minSpareThreads="100" maxSpareThreads="200" acceptCount="1000" connectionTimeout="20000" URIEncoding="UTF-8" enableLookups="false" compression="on" compressionMinSize="2048" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,image/gif,image/jpg,image/png" redirectPort="8443"/>JVM Tuning for Production
# Add to catalina.sh
JAVA_OPTS="-server -Xms1024m -Xmx2048m -XX:PermSize=512m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+UseParallelGCThreads=8 -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseCMSCompactAtFullCollection -Xloggc:../logs/gc.log"Tomcat Directory Layout
/usr/local/tomcat (installation directory)
bin – startup/shutdown scripts
conf – configuration files (server.xml, web.xml, etc.)
lib – required JAR libraries
logs – log files
webapps – deployed web applications
work – compiled JSP classes
After applying the above configurations, restart Tomcat to apply changes and verify that the server listens on the new 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.
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.
