部署tomcat部署实战案例

简介: 本文是关于Tomcat部署实战案例的教程,包括通过yum和二进制方式部署Tomcat的详细步骤,以及如何监控Tomcat服务。

作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.tomcat概述

  起始于SUN的一个Servlet的参考实现项目Java Web Server,作者是James Duncan Davidson,后将项目贡献给了ASF。和ASF现有的项目合并,并开源成为顶级项目,官网地址:http://tomcat.apache.org/。

  Tomcat仅仅实现了Java EE规范的与Servlet、JSP相关的类库,是JavaEE不完整实现。

  著名图书出版商O'Reilly约稿该项目成员,Davidson希望使用一个公猫作为封面,但是公猫已经被另一本书使用,书出版后封面是一只雪豹。

  1999年发布初始版本是Tomcat 3.0,实现了Servlet 2.2和JSP1.1规范。

  Tomcat 4.x发布时,内建了Catalina(Servlet容器)和Jasper(JSP engine)等。

  商用的Servlet和JSP实现有IBM WebSphere、Oracle WebLogic(原属于BEA公司)、Oracle Oc4j、Glassfish、JBoss等。

  开源实现有Tomcat、Jetty、Resin。  

  《Tomcat权威指南》封面如下图所示。

二.基于yum方式部署tomcat

1>.部署JDK环境

  博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie/p/12199413.html

2>.查看tomcat相关的软件包

2>.安装tomcat应用程序

[root@tomcat201.yinzhengjie.org.cn ~]# yum -y install tomcat tomcat-admin-webapps tomcat-webapps


温馨提示:
  tomcat-admin-webapps:
    tomcat的应用程序的管理组件。

  tomcat-webapps:
    为提供tomcat的默认欢迎首页文件的组件。

3>.查看安装tomcat的相关目录

[root@tomcat201.yinzhengjie.org.cn ~]# rpm -ql tomcat 
/etc/logrotate.d/tomcat
/etc/sysconfig/tomcat
/etc/tomcat
/etc/tomcat/Catalina
/etc/tomcat/Catalina/localhost
/etc/tomcat/catalina.policy
/etc/tomcat/catalina.properties
/etc/tomcat/conf.d
/etc/tomcat/conf.d/README
/etc/tomcat/context.xml
/etc/tomcat/log4j.properties
/etc/tomcat/logging.properties
/etc/tomcat/server.xml
/etc/tomcat/tomcat-users.xml
/etc/tomcat/tomcat.conf
/etc/tomcat/web.xml
/usr/bin/tomcat-digest
/usr/bin/tomcat-tool-wrapper
/usr/lib/systemd/system/tomcat.service
/usr/lib/systemd/system/tomcat@.service
/usr/libexec/tomcat
/usr/libexec/tomcat/functions
/usr/libexec/tomcat/preamble
/usr/libexec/tomcat/server
/usr/sbin/tomcat
/usr/share/doc/tomcat-7.0.76
/usr/share/doc/tomcat-7.0.76/LICENSE
/usr/share/doc/tomcat-7.0.76/NOTICE
/usr/share/doc/tomcat-7.0.76/RELEASE-NOTES
/usr/share/tomcat
/usr/share/tomcat/bin/bootstrap.jar
/usr/share/tomcat/bin/catalina-tasks.xml
/usr/share/tomcat/conf
/usr/share/tomcat/lib
/usr/share/tomcat/logs
/usr/share/tomcat/temp
/usr/share/tomcat/webapps
/usr/share/tomcat/work
/var/cache/tomcat
/var/cache/tomcat/temp
/var/cache/tomcat/work
/var/lib/tomcat
/var/lib/tomcat/webapps
/var/lib/tomcats
/var/log/tomcat
/var/log/tomcat/catalina.out
[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]#

[root@tomcat201.yinzhengjie.org.cn ~]# rpm -ql tomcat /etc/logrotate.d/tomcat

4>.运行tomcat服务

[root@tomcat201.yinzhengjie.org.cn ~]# ss -ntl
State      Recv-Q Send-Q                                                                                          Local Address:Port                                                                                                         Peer Address:Port              
LISTEN     0      128                                                                                                         *:22                                                                                                                      *:*                  
LISTEN     0      128                                                                                                        :::22                                                                                                                     :::*                  
[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]# systemctl start tomcat
[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]# ss -ntl
State      Recv-Q Send-Q                                                                                          Local Address:Port                                                                                                         Peer Address:Port              
LISTEN     0      100                                                                                                         *:8009                                                                                                                    *:*                  
LISTEN     0      100                                                                                                         *:8080                                                                                                                    *:*                  
LISTEN     0      128                                                                                                         *:22                                                                                                                      *:*                  
LISTEN     0      1                                                                                                   127.0.0.1:8005                                                                                                                    *:*                  
LISTEN     0      128                                                                                                        :::22                                                                                                                     :::*                  
[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]# systemctl enable tomcat
Created symlink from /etc/systemd/system/multi-user.target.wants/tomcat.service to /usr/lib/systemd/system/tomcat.service.
[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]# systemctl list-unit-files | grep tomcat
tomcat.service                                enabled 
tomcat@.service                               disabled
[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]#

[root@tomcat201.yinzhengjie.org.cn ~]# systemctl start tomcat

5>.访问tomcat的默认端口

  tomcat首页文件默认的查找顺序如下所示:  
    index.htm  
    index.html  
    index.jsp(如果没有定义上面2个文件,tomcat默认提供了该文件,即tomcat的默认首页,如下图所示。)

6>.查看tomcat应用程序运行的主目录

[root@tomcat201.yinzhengjie.org.cn ~]# ll /usr/share/tomcat/webapps/ROOT/
total 188
-rw-r--r-- 1 tomcat tomcat 26447 Mar 12  2019 asf-logo-wide.svg
-rw-r--r-- 1 tomcat tomcat   713 Mar 12  2019 bg-button.png
-rw-r--r-- 1 tomcat tomcat  1918 Mar 12  2019 bg-middle.png
-rw-r--r-- 1 tomcat tomcat  1392 Mar 12  2019 bg-nav-item.png
-rw-r--r-- 1 tomcat tomcat  1401 Mar 12  2019 bg-nav.png
-rw-r--r-- 1 tomcat tomcat  3103 Mar 12  2019 bg-upper.png
-rw-r--r-- 1 tomcat tomcat 21630 Mar 12  2019 favicon.ico
-rw-r--r-- 1 tomcat tomcat 12186 Mar 12  2019 index.jsp
-rw-r--r-- 1 tomcat tomcat  8965 Mar 12  2019 RELEASE-NOTES.txt
-rw-r--r-- 1 tomcat tomcat  5581 Mar 12  2019 tomcat.css
-rw-r--r-- 1 tomcat tomcat  2066 Mar 12  2019 tomcat.gif
-rw-r--r-- 1 tomcat tomcat  5103 Mar 12  2019 tomcat.png
-rw-r--r-- 1 tomcat tomcat  2376 Mar 12  2019 tomcat-power.gif
-rw-r--r-- 1 tomcat tomcat 67795 Mar 12  2019 tomcat.svg
drwxr-xr-x 2 tomcat tomcat    21 Feb 17 03:57 WEB-INF
[root@tomcat201.yinzhengjie.org.cn ~]#

[root@tomcat201.yinzhengjie.org.cn ~]# ll /usr/share/tomcat/webapps/ROOT/

三.基于二进制方式部署tomcat

1>.部署JDK环境

  博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie/p/12199413.html

2>.下载tomcat相关的软件包

  访问tomcat的官网:
    http://tomcat.apache.org/

3>.下载tomcat软件包

[root@tomcat201.yinzhengjie.org.cn ~]# ll
total 0
[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.tar.gz
--2020-02-17 04:44:09--  http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.tar.gz
Resolving mirror.bit.edu.cn (mirror.bit.edu.cn)... 114.247.56.117, 2001:da8:204:1205::22
Connecting to mirror.bit.edu.cn (mirror.bit.edu.cn)|114.247.56.117|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10315164 (9.8M) [application/octet-stream]
Saving to: ‘apache-tomcat-8.5.51.tar.gz’

100%[====================================================================================================================>] 10,315,164  5.06MB/s   in 1.9s   

2020-02-17 04:44:11 (5.06 MB/s) - ‘apache-tomcat-8.5.51.tar.gz’ saved [10315164/10315164]

[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]# ll
total 10076
-rw-r--r-- 1 root root 10315164 Feb  6 06:40 apache-tomcat-8.5.51.tar.gz
[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]#

[root@tomcat201.yinzhengjie.org.cn ~]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.tar.gz

4>.解压tomcat软件到指定目录

 [root@tomcat201.yinzhengjie.org.cn ~]# tar zxf apache-tomcat-8.5.51.tar.gz -C /yinzhengjie/softwares/

5>.创建tomcat的符号(软)链接

[root@tomcat201.yinzhengjie.org.cn ~]# ln -sv /yinzhengjie/softwares/apache-tomcat-8.5.51/ /yinzhengjie/softwares/tomcat

6>.运行tomcat

[root@tomcat201.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tomcat/bin/startup.sh

7>.第一次访问tomcat的web界面(index.jsp)可能会很慢

  我们知道tomcat首页文件默认的查找顺序如下所示:
    index.htm
    index.html
    index.jsp(如果没有定义上面index.htm或者index.html文件,tomcat默认提供了index.jsp文件,即tomcat的默认首页。)  

  当我们首次访问web页面时,可能小伙伴会很奇怪,为什么访问web界面会很慢,其实这是因为第一次访问index.jsp文件时,jasper会将index.jsp转换为servlet能识别的文件,即index_jsp.java,但是JVM并不能直接识别java文件,因此需要servlet通过java编译工具将index_jsp.java转换为index_jsp.class文件,此时JVM才能识别并运行程序。也就是我们所能看到的页面啦,如下图所示。

8>.停止tomcat服务

[root@tomcat201.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/tomcat/bin/shutdown.sh

9>.创建自定义用户用于管理tomcat服务

[root@tomcat201.yinzhengjie.org.cn ~]# useradd -r jason
[root@tomcat201.yinzhengjie.org.cn ~]#
[root@tomcat201.yinzhengjie.org.cn ~]# getent passwd jason
jason:x:998:996::/home/jason:/bin/bash
[root@tomcat201.yinzhengjie.org.cn ~]# 
[root@tomcat201.yinzhengjie.org.cn ~]# chown jason:jason /yinzhengjie/softwares/apache-tomcat-8.5.51/ -R

10>.使用自定义用户启动tomcat服务

11>.zabbix监控tomcat配置参数

  博主推荐阅读:
    https://www.cnblogs.com/yinzhengjie2020/p/12315341.html
目录
相关文章
|
30天前
|
XML 前端开发 Java
SpringMVC入门到实战------2、SpringMVC创建实例Hello SpringMVC(maven+tomcat)
这篇文章是SpringMVC框架的入门教程,详细指导了如何在IDEA中使用Maven和Tomcat创建SpringMVC工程,包括添加依赖、配置web.xml、编写控制器、创建配置文件、配置Tomcat服务器以及进行基本的测试,展示了一个简单的Hello SpringMVC示例。
SpringMVC入门到实战------2、SpringMVC创建实例Hello SpringMVC(maven+tomcat)
|
23天前
|
Java 应用服务中间件 Windows
【应用服务 App Service】App Service 中部署Java项目,查看Tomcat配置及上传自定义版本
【应用服务 App Service】App Service 中部署Java项目,查看Tomcat配置及上传自定义版本
|
3月前
|
Ubuntu 前端开发 JavaScript
技术笔记:Ubuntu:一个部署好的tomcat应用(war包)怎么用Nginx实现动静分离?
技术笔记:Ubuntu:一个部署好的tomcat应用(war包)怎么用Nginx实现动静分离?
|
27天前
|
应用服务中间件 Docker 容器
在服务器中使用Docker安装Tomcat、同时实现目录挂载、并且部署War包到服务器
这篇文章介绍了在Docker中安装Tomcat的过程,包括搜索Tomcat镜像、拉取镜像、目录挂载的准备、创建并挂载容器,以及如何进入容器和进行测试。文中还说明了如何将WAR包部署到Tomcat服务器并访问部署的应用。
在服务器中使用Docker安装Tomcat、同时实现目录挂载、并且部署War包到服务器
|
30天前
|
缓存 Java 应用服务中间件
SpringMVC入门到实战------七、SpringMVC创建JSP页面的详细过程+配置模板+实现页面跳转+配置Tomcat。JSP和HTML配置模板的差异对比(二)
这篇文章详细介绍了在SpringMVC中创建JSP页面的全过程,包括项目的创建、配置、Tomcat的设置,以及如何实现页面跳转和配置模板解析器,最后还对比了JSP和HTML模板解析的差异。
SpringMVC入门到实战------七、SpringMVC创建JSP页面的详细过程+配置模板+实现页面跳转+配置Tomcat。JSP和HTML配置模板的差异对比(二)
|
12天前
|
前端开发 Java 应用服务中间件
react自学(6) 部署到tomcat中
react自学(6) 部署到tomcat中
|
1月前
|
jenkins 持续交付 开发工具
"引爆效率革命!Docker+Jenkins+GIT+Tomcat:解锁持续集成魔法,一键部署Java Web应用的梦幻之旅!"
【8月更文挑战第9天】随着软件开发复杂度的增加,自动化变得至关重要。本文通过实例展示如何结合Docker、Jenkins、Git与Tomcat建立高效的持续集成(CI)流程。Docker确保应用环境一致性;Jenkins自动化处理构建、测试和部署;Git管理源代码版本;Tomcat部署Web应用。在Jenkins中配置Git插件并设置项目,集成Docker构建Tomcat应用镜像并运行容器。此外,通过自动化测试、代码质量检查、环境隔离和日志监控确保CI流程顺畅,从而显著提高开发效率和软件质量。
54 3
|
4月前
|
XML Java 应用服务中间件
Tomcat_servlet部署、编译、配置、打包
Tomcat_servlet部署、编译、配置、打包
62 0
|
2月前
|
Java 应用服务中间件 Shell
|
1月前
|
应用服务中间件
2022年最新最详细在IDEA中配置Tomcat(含有详细图解过程)、建立使用IEDA建立一个Web项目的案例
这篇文章提供了在IntelliJ IDEA中配置Tomcat服务器的详细步骤,包括添加Tomcat Server、选择安装路径、添加项目Artifact,以及创建和展示Web项目的流程。