请求提供RHEL 8.10环境下Apache Tomcat从9.0.104版本迁移至9.0.105/9.0.109或最新版本的完整步骤
Hey there, let's get your Tomcat upgraded safely to patch those vulnerabilities. I’ll walk you through every step, assuming you’ve got a standard Tomcat setup (just adjust paths if yours is custom).
Prerequisites
- You have sudo/root access to your RHEL 8.10 server
- Tomcat is currently running (we’ll stop it first)
- You know the user/group Tomcat runs as (usually
tomcat:tomcat)
1. Stop Tomcat & Backup Everything First
Always start with a backup—this is your safety net if something goes wrong.
- Stop the Tomcat service:
# If using systemd (most common setup) sudo systemctl stop tomcat # If using the shutdown script directly sudo /usr/local/tomcat/bin/shutdown.sh - Create a full backup of your current Tomcat installation:
Store this backup in a safe location (preferably not on the same server).sudo tar -czf tomcat-backup-$(date +%Y%m%d).tar.gz /usr/local/tomcat
2. Download the Target Tomcat Version
Head over to the official Apache Tomcat 9 download page and grab the tar.gz package for your target version (9.0.105, 9.0.109, or the latest stable 9.x release). You can either transfer the file to your server via SCP, or use wget directly with the download link:
# Replace [DIRECT_DOWNLOAD_LINK] with the actual link from the Apache website sudo wget [DIRECT_DOWNLOAD_LINK]
3. Extract the New Tomcat Package
Unpack the downloaded tar.gz file in your current directory:
# Replace [TARGET_VERSION] with your chosen version (e.g., 9.0.109) sudo tar -xzf apache-tomcat-[TARGET_VERSION].tar.gz
4. Replace the Old Tomcat Installation
- Rename your existing Tomcat directory to keep it as a fallback:
sudo mv /usr/local/tomcat /usr/local/tomcat-old - Move the new Tomcat directory to the standard installation path:
sudo mv apache-tomcat-[TARGET_VERSION] /usr/local/tomcat
5. Migrate Your Custom Configurations & Applications
Don’t just copy everything blindly—we want to keep your custom settings but use the new default configs where possible.
- Copy your critical custom files from the old installation:
# Copy configuration files (server.xml, web.xml, context.xml, etc.) sudo cp -r /usr/local/tomcat-old/conf/* /usr/local/tomcat/conf/ # Copy your deployed web applications (war files or expanded directories) sudo cp -r /usr/local/tomcat-old/webapps/* /usr/local/tomcat/webapps/ # If you have custom libraries in lib/ (not default Tomcat libs), copy those too sudo cp /usr/local/tomcat-old/lib/*.jar /usr/local/tomcat/lib/ - Important: Compare the new default config files with your old ones to catch any changes. For example, check
server.xmlfor port configurations orweb.xmlfor security updates:
Merge any critical updates from the new config into your custom version (don’t just overwrite the new files entirely).sudo diff /usr/local/tomcat-old/conf/server.xml /usr/local/tomcat/conf/server.xml
6. Set Correct Permissions
Ensure the Tomcat user has full ownership of the new directory:
sudo chown -R tomcat:tomcat /usr/local/tomcat sudo chmod +x /usr/local/tomcat/bin/*.sh
7. Start Tomcat & Verify the Upgrade
- Start the Tomcat service:
# Systemd method sudo systemctl start tomcat # Direct script method sudo /usr/local/tomcat/bin/startup.sh - Check the logs to confirm successful startup:
Look for lines likesudo tail -f /usr/local/tomcat/logs/catalina.outServer startup in X ms—that means it’s running without issues. - Verify the version by accessing the Tomcat homepage (replace
your-server-ipwith your actual server IP):
You should see your target version listed here.curl -s http://your-server-ip:8080 | grep "Apache Tomcat" - Test your web applications thoroughly to make sure they’re working as expected.
8. Rollback Plan (Just in Case)
If something breaks, revert to the old version quickly:
- Stop the new Tomcat service:
sudo systemctl stop tomcat - Remove the new directory and restore the old one:
sudo rm -rf /usr/local/tomcat sudo mv /usr/local/tomcat-old /usr/local/tomcat - Start the old Tomcat service:
sudo systemctl start tomcat
内容的提问来源于stack exchange,提问作者AKASH BHAT

