Step‑by‑Step Guide to Install, Configure, and Optimize Apache Tomcat
This article provides a comprehensive tutorial on installing Apache Tomcat, setting up the required JDK, configuring environment variables, adjusting server ports, and applying performance optimizations such as disabling AJP, switching to NIO, enabling external thread pools, and tuning JVM options for production use.
Introduction
Apache Tomcat is an open‑source servlet container and JSP engine. It runs as an independent Java process and is commonly used for development and small‑to‑medium production deployments.
Prerequisites
Java Development Kit (JDK) must be installed; the JDK provides the JVM required to run Tomcat.
Installation Steps
1. Install JDK
# rm -rf $(which java)
# tar xf jdk-7u80-linux-x64.tar
# mv jdk1.7.0_80/ /usr/local/java2. Extract Tomcat
# tar xf apache-tomcat-8.5.20.tar.gz
# mv apache-tomcat-8.5.20 /usr/local/tomcat83. Configure environment variables
export JAVA_HOME="/usr/local/java"
export PATH=$PATH:$JAVA_HOME/bin:/usr/local/tomcat8/bin
. /etc/profile4. Verify Java installation
java -version5. Start and stop Tomcat
/usr/local/tomcat8/bin/startup.sh
/usr/local/tomcat8/bin/shutdown.sh6. Change default ports
Edit /usr/local/tomcat8/conf/server.xml and modify the values of the Connector ports (e.g., 8080 → 9528, 8005 → 9529, 8009 → 9530).
7. Firewall / SELinux
Open the chosen ports in the firewall or disable firewalld/SELinux for testing (e.g., systemctl stop firewalld, setenforce 0).
Tomcat Directory Layout
/usr/local/tomcat8
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 classesOptimization
Disable AJP connector
<!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/> -->Use NIO protocol
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"/>External thread pool
<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" disableUploadTimeout="true" 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
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"Sample server.xml connector configuration
<Connector executor="tomcatThreadPool" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="1000" minSpareThreads="100" maxSpareThreads="200" acceptCount="1000"
disableUploadTimeout="true" 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"/>Conclusion
Following these steps installs Tomcat, configures the required JDK, customizes ports, and applies performance enhancements such as NIO connectors, an external thread pool, and JVM options, preparing the server for production workloads.
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
