zoukankan      html  css  js  c++  java
  • 部署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
  • 相关阅读:
    《C#从现象到本质》读书笔记(八)第10章反射
    《C#从现象到本质》读书笔记(七)第9章 泛型
    《C#从现象到本质》读书笔记(六)第8章委托和事件
    《C#从现象到本质》读书笔记(五)第5章字符串第6章垃圾回收第7章异常与异常处理
    求1+2+……+n的和
    回溯法的应用举例
    回溯法
    翻转单词顺序列
    左旋转字符串
    和为S的两个数字
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/12199468.html
Copyright © 2011-2022 走看看