在CentOS上升级Tomcat的步骤
升级前务必备份旧版本Tomcat的安装目录、配置文件及web应用数据,避免升级失败导致数据丢失。
/usr/share/tomcat为例):sudo cp -r /usr/share/tomcat /usr/share/tomcat-backupserver.xml、context.xml):sudo cp -r /usr/share/tomcat/conf /usr/share/tomcat-conf-backupsudo cp -r /usr/share/tomcat/webapps /usr/share/tomcat-webapps-backup升级过程中需停止Tomcat以避免文件冲突:
sudo systemctl stop tomcat
若使用init.d脚本管理,可执行:sudo /etc/init.d/tomcat stop
.tar.gz格式)。wget命令下载(以Tomcat 9.0.56为例):wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.56/bin/apache-tomcat-9.0.56.tar.gz/usr/share/):sudo tar -xvzf apache-tomcat-9.0.56.tar.gz -C /usr/share/sudo mv /usr/share/tomcat /usr/share/tomcat-oldtomcat):sudo mv /usr/share/apache-tomcat-9.0.56 /usr/share/tomcatserver.xml、context.xml等配置文件,确保与应用需求一致(如端口、数据库连接等)确保系统环境变量指向新版本Tomcat:
/etc/profile.d/tomcat.sh):sudo nano /etc/profile.d/tomcat.shexport CATALINA_HOME=/usr/share/tomcat
export PATH=$PATH:$CATALINA_HOME/bin
source /etc/profile.d/tomcat.shsudo systemctl start tomcatsudo systemctl enable tomcatsudo systemctl status tomcat(需显示“active (running)”)http://服务器IP:8080,或执行curl http://localhost:8080,确认显示新版本信息;也可通过命令查看版本:/usr/share/tomcat/bin/versionLogger.sh确认新版本运行稳定后,删除旧版本备份文件以释放空间:
sudo rm -rf /usr/share/tomcat-backup /usr/share/tomcat-old /usr/share/apache-tomcat-9.0.56.tar.gz
/etc/systemd/system/tomcat.service文件中的路径是否指向新版本。