更新升级Tomcat软件版本的解决方案

最近在一个客户进行外网安全审计工作中,安全团队发现一个应用的tomcat的版本较低,为了系统的安全性和稳定性。我们需要更新升级Tomcat软件版本到最新版。

一、下载地址

通过访问如下网址来下载对应版本的Tomcat。网址如下:https://archive.apache.org/dist/tomcat/

二、升级步骤

我们在日常运维工作中,常用如下两种升级方式,以供参考。

(一)小版本升级

如果类似于7.0.99到7.0.199的升级,那么只需要更换lib文件夹的内容即可。如下所示。

1.当前版本

当前的tomcat版本为7.0.69版本,如下所示。

[app01@yunweixia.com bin]$ ./version.sh 
Using CATALINA_BASE:   /home/app01/tomcat2
Using CATALINA_HOME:   /home/app01/tomcat2
Using CATALINA_TMPDIR: /home/app01/tomcat2/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk
Using CLASSPATH:       /home/app01/tomcat2/bin/bootstrap.jar:/home/app01/tomcat2/bin/tomcat-juli.jar
Using CATALINA_PID:    /home/app01/tomcat2/run/app01tomcat2.pid
Server version: Apache Tomcat/7.0.69
Server built:   Apr 11 2016 07:57:09 UTC
Server number:  7.0.69.0
OS Name:        Linux
OS Version:     3.10.0-693.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_141-b16
JVM Vendor:     Oracle Corporation

2.备份

备份生产环境tomcat目录下bin文件夹和lib文件夹。

[app01@yunweixia.com tomcat2]$ cp -arf lib/ lib-20230907

3.停止服务

停止老版本tomcat

[app01@yunweixia.com ~]$ cd tomcat2/bin
[app01@yunweixia.com bin]$ ./shutdown.sh 
Using CATALINA_BASE:   /home/app01/tomcat2
Using CATALINA_HOME:   /home/app01/tomcat2
Using CATALINA_TMPDIR: /home/app01/tomcat2/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk
Using CLASSPATH:       /home/app01/tomcat2/bin/bootstrap.jar:/home/app01/tomcat2/bin/tomcat-juli.jar
Using CATALINA_PID:    /home/app01/tomcat2/run/app01tomcat2.pid
$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted.

4.解压

将最新版本tomcat上传至服务器并解压。

[app01@yunweixia.com ~]$ tar -xzvf apache-tomcat-7.0.109.tar.gz

5.删除旧版本

删除旧版本tomcat目录下的lib文件夹中的内容

[app01@yunweixia.com ~]$ rm -rf tomcat2/lib/*

6.更新

将新版本tomcat目录下lib文件夹中的内容复制到旧版本lib目录下

[app01@yunweixia.com ~]$ cp -arf apache-tomcat-7.0.109/lib/* tomcat2/lib/

7.启动服务

启动已经替换了lib文件夹内容的旧tomcat

[app01@yunweixia.com ~]$ cd tomcat2/bin
[app01@yunweixia.com bin]$ ./startup.sh 
Using CATALINA_BASE:   /home/app01/tomcat2
Using CATALINA_HOME:   /home/app01/tomcat2
Using CATALINA_TMPDIR: /home/app01/tomcat2/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk
Using CLASSPATH:       /home/app01/tomcat2/bin/bootstrap.jar:/home/app01/tomcat2/bin/tomcat-juli.jar
Using CATALINA_PID:    /home/app01/tomcat2/run/app01tomcat2.pid
Tomcat started.

8.验证

查看验证tomcat版本号

[app01@yunweixia.com bin]$ ./version.sh 
Using CATALINA_BASE:   /home/app01/tomcat2
Using CATALINA_HOME:   /home/app01/tomcat2
Using CATALINA_TMPDIR: /home/app01/tomcat2/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk
Using CLASSPATH:       /home/app01/tomcat2/bin/bootstrap.jar:/home/app01/tomcat2/bin/tomcat-juli.jar
Using CATALINA_PID:    /home/app01/tomcat2/run/app01tomcat2.pid
Server version: Apache Tomcat/7.0.109
Server built:   Apr 22 2021 18:43:38 UTC
Server number:  7.0.109.0
OS Name:        Linux
OS Version:     3.10.0-693.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_141-b16
JVM Vendor:     Oracle Corporation

(二)大版本升级

类似于7.0->8.5的升级、那么需要更换lib文件夹和bin文件夹下的内容即可。
如下所示。

1.当前版本

当前的tomcat版本为7.0.109版本,如下所示。

[app01@yunweixia.com ~]$ cd tomcat2/bin
[app01@yunweixia.com bin]$ ./version.sh 
Using CATALINA_BASE:   /home/app01/tomcat2
Using CATALINA_HOME:   /home/app01/tomcat2
Using CATALINA_TMPDIR: /home/app01/tomcat2/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk
Using CLASSPATH:       /home/app01/tomcat2/bin/bootstrap.jar:/home/app01/tomcat2/bin/tomcat-juli.jar
Using CATALINA_PID:    /home/app01/tomcat2/run/app01tomcat2.pid
Server version: Apache Tomcat/7.0.109
Server built:   Apr 22 2021 18:43:38 UTC
Server number:  7.0.109.0
OS Name:        Linux
OS Version:     3.10.0-693.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_141-b16
JVM Vendor:     Oracle Corporation

2.备份

备份生产环境tomcat目录下bin文件夹和lib文件夹。

[app01@yunweixia.com tomcat2]$ cp -arf bin bin-20230907
[app01@yunweixia.com tomcat2]$ cp -arf lib lib-20230907_2

3.停止服务

停止老版本tomcat

[app01@yunweixia.com ~]$ cd tomcat2/bin
[app01@yunweixia.com bin]$ ./shutdown.sh 
Using CATALINA_BASE:   /home/app01/tomcat2
Using CATALINA_HOME:   /home/app01/tomcat2
Using CATALINA_TMPDIR: /home/app01/tomcat2/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk
Using CLASSPATH:       /home/app01/tomcat2/bin/bootstrap.jar:/home/app01/tomcat2/bin/tomcat-juli.jar
Using CATALINA_PID:    /home/app01/tomcat2/run/app01tomcat2.pid
$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted.

4.解压

将最新版本tomcat上传至服务器并解压

[app01@yunweixia.com ~]$ tar -xzvf apache-tomcat-8.0.53.tar.gz

5.删除旧版本

删除旧版本tomcat目录下bin和lib文件夹

[app01@yunweixia.com ~]$ rm -rf tomcat2/bin/*
[app01@yunweixia.com ~]$ rm -rf tomcat2/lib/*

6.更新

将新版本tomcat下bin和lib文件夹复制到旧版本目录下

[app01@yunweixia.com ~]$ cp -arf apache-tomcat-8.0.53/bin/* tomcat2/bin
[app01@yunweixia.com ~]$ cp -arf apache-tomcat-8.0.53/lib/* tomcat2/lib

7.启动服务

启动已经替换了lib文件夹内容的旧tomcat

[app01@yunweixia.com ~]$ cd tomcat2/bin
[app01@yunweixia.com bin]$ ./startup.sh 
Using CATALINA_BASE:   /home/app01/tomcat2
Using CATALINA_HOME:   /home/app01/tomcat2
Using CATALINA_TMPDIR: /home/app01/tomcat2/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk
Using CLASSPATH:       /home/app01/tomcat2/bin/bootstrap.jar:/home/app01/tomcat2/bin/tomcat-juli.jar
Tomcat started.

8.验证

查看验证tomcat版本号

[app01@yunweixia.com bin]$ ./version.sh 
Using CATALINA_BASE:   /home/app01/tomcat2
Using CATALINA_HOME:   /home/app01/tomcat2
Using CATALINA_TMPDIR: /home/app01/tomcat2/temp
Using JRE_HOME:        /usr/lib/jvm/java-1.8.0-openjdk
Using CLASSPATH:       /home/app01/tomcat2/bin/bootstrap.jar:/home/app01/tomcat2/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.0.53
Server built:   Jun 29 2018 14:42:45 UTC
Server number:  8.0.53.0
OS Name:        Linux
OS Version:     3.10.0-693.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_141-b16
JVM Vendor:     Oracle Corporation

总结

至此,更新升级tomcat软件版本的两种方式介绍完毕。如此简易的升级方式在生产环境使用前,一定要验证代码适配哦。

原创文章,作者:运维侠,如若转载,请注明出处:https://www.yunweixia.com/solutions/tomcat-version-upgrade-solution-guide.html

(0)
运维侠的头像运维侠共建用户
上一篇 2025年5月22日 22:47
下一篇 2025年5月24日 18:11

相关推荐

发表回复

登录后才能评论