How To Install Apache Tomcat on CentOS Stream 10
In this tutorial, we will show you how to install Apache Tomcat on CentOS Stream 10. Apache Tomcat is a widely used open-source implementation of the Java Servlet, JavaServer Pages, and Java Expression Language technologies. It serves as a robust platform for running Java applications. This guide will walk you through the process of installing Apache Tomcat on CentOS Stream 10, ensuring you have a reliable environment for your Java web applications.
Prerequisites
Before we begin the installation process, ensure that your system meets the following prerequisites:
- Operating System: CentOS Stream 10
- Java Development Kit (JDK): Required for running Tomcat. Ensure that JDK is installed on your system.
- Sudo Privileges: You need to have administrative access to install packages and make system changes.
System Requirements
For optimal performance, consider the following system requirements:
- RAM: Minimum of 1 GB (2 GB recommended)
- Disk Space: At least 500 MB free for installation and additional space for applications.
- CPU: A modern multi-core processor for better performance.
Step 1: Update Your System
The first step in the installation process is to ensure your system is up-to-date. This helps prevent compatibility issues with packages.
sudo dnf update -y
Step 2: Install Java Development Kit (JDK)
Apache Tomcat requires a Java Runtime Environment (JRE) to run. We will install OpenJDK, which is the open-source implementation of the Java Platform.
Installation Steps:
sudo dnf install java-11-openjdk-devel -y
After installation, verify the JDK installation by checking the version:
java -version
You should see output indicating the installed version of Java.
Step 3: Create a Dedicated User for Tomcat
For security reasons, it is advisable to run Tomcat under a dedicated user account rather than as root. This reduces the risk of system-wide vulnerabilities.
sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat
Step 4: Download Apache Tomcat
The next step is to download the latest version of Apache Tomcat from the official website. As of January 2025, version 10.1.34 is the latest stable release.
wget https://downloads.apache.org/tomcat/tomcat-10/v10.1.34/bin/apache-tomcat-10.1.34.tar.gz
Step 5: Extract and Move Tomcat Files
Once downloaded, you need to extract the files and move them to the appropriate directory.
tar xzvf apache-tomcat-10.1.34.tar.gz
sudo mv apache-tomcat-10.1.34 /opt/tomcat
Step 6: Set Permissions
The next step is to set the correct permissions for the Tomcat directory to ensure that our dedicated user can manage it properly.
sudo chown -R tomcat: /opt/tomcat
sudo chmod +x /opt/tomcat/bin/*.sh
Step 7: Configure Environment Variables
You need to set environment variables for Tomcat to function correctly. Create a new file in the profile.d directory:
sudo nano /etc/profile.d/tomcat.sh
Add the following lines to this file:
export CATALINA_HOME="/opt/tomcat"
export PATH="$CATALINA_HOME/bin:$PATH"
This configuration allows you to run Tomcat commands from any terminal session.
Step 8: Configure Systemd Service for Tomcat
This step involves creating a systemd service file that enables you to manage the Tomcat service easily using systemctl commands.
sudo nano /etc/systemd/system/tomcat.service
Add the following content to this file:
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/java-openjdk"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_BASE=/opt/tomcat"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
Troubleshooting Tips:
- If you encounter issues starting Tomcat, check logs located in
/opt/tomcat/logs/
. - If SELinux is enabled, it may block some operations; consider setting SELinux to permissive mode temporarily using
sestatus
. - If you face permission issues, ensure that ownership and permissions are correctly set as described in previous steps.
Step 9: Start and Enable Tomcat Service
You can now start the Tomcat service and enable it to run at boot time with these commands:
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl enable tomcat
Step 10: Configure Firewall (if applicable)
If your server has a firewall enabled, you will need to allow traffic on port 8080, which is used by Tomcat by default.
sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
sudo firewall-cmd --reload
Step 11: Verify Installation
Your installation is now complete! To verify that Apache Tomcat is running correctly, open a web browser and navigate to:
http://your_server_ip:8080
You should see the Apache Tomcat welcome page, indicating that your server is up and running successfully.
Troubleshooting Common Issues
-
- If you cannot access the Tomcat page:
- Ensure that your firewall settings allow traffic on port 8080.
- Check if the service is running using
sudo systemctl status tomcat
. - If there are errors in starting up, review logs in
/opt/tomcat/logs/
. - If SELinux is enabled and causing issues, consider temporarily disabling it with
sestatus -v | grep "SELinux status"
. - If you receive errors related to Java not being found or similar issues, ensure JAVA_HOME is correctly set in your environment variables.
- If you encounter permission denied errors when accessing certain directories or files within Tomcat, verify ownership and permissions are correctly set as specified in earlier steps.
- If you face issues with service management commands not working as expected (e.g., starting or stopping), check if there are syntax errors in your service file located at
/etc/systemd/system/tomcat.service
. - If you see errors related to memory or resource limits when starting Tomcat, consider adjusting resource limits in your system configuration files or increasing available memory on your server.
- If you’re using a cloud provider or virtual machine setup, ensure that security groups or network ACLs allow traffic on port 8080 from your IP address or range.
- If you want to configure SSL/TLS for secure connections:
- You can follow Apache’s official documentation on configuring SSL/TLS for Tomcat by visiting their website at SSL/TLS Configuration How-To.
- If you want to deploy Java web applications:
- You can place your .war files into the
/opt/tomcat/webapps/
d directory for deployment automatically upon startup.
- You can place your .war files into the
- If you’re interested in configuring Nginx as a reverse proxy:
- This can help manage traffic more efficiently by serving static content directly while forwarding dynamic requests to Tomcat. More information can be found in various online tutorials specific to Nginx and Tomcat integration.
- If you’re looking for performance tuning:
- You may want to explore options such as adjusting JVM options in
/opt/tomcat/bin/setenv.sh
, increasing heap size or garbage collection settings based on application requirements.
- You may want to explore options such as adjusting JVM options in
- If you’re considering monitoring solutions:
- You can use tools like Prometheus or Grafana along with JMX Exporter for monitoring your Tomcats performance metrics effectively over time.
- If you’re planning on scaling your application:
- You might want to look into clustering options available within Apache Tomcats documentation or consider containerizing applications using Docker for easier management across multiple instances.
- If you’re interested in logging configurations:
- You can customize logging settings by editing configuration files located under
/opt/tomcats/conf/logging.properties
.
- You can customize logging settings by editing configuration files located under
- If you cannot access the Tomcat page:
Congratulations! You have successfully installed Apache Tomcat. Thanks for using this tutorial for installing the Apache Tomcat on CentOS Stream 10 system. For additional help or useful information, we recommend you check the official Apache website.