阿里云服务器ECS    
弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新 [咨询更多]
阿里云存储OSS
简单易用、多重冗余、数据备份高可靠、多层次安全防护安全性更强、低成本 [咨询更多]
阿里云数据库RDS
稳定可靠、可弹性伸缩、更拥有容灾、备份、恢复、监控、迁移等方面的全套解决方案 [咨询更多]
阿里云安全产品
DDoS高防IP、web应用防火墙、安骑士、sll证书、态势感知众多阿里云安全产品热销中 [咨询更多]
阿里云折扣优惠    
云服务器ECS、数据库、负载均衡等产品新购、续费、升级联系客服获取更多专属折扣 [咨询更多]
Java应用服务器之tomcat部署
2020-7-15    点击量:
    Java应用服务器之tomcat部署
    一、相关术语简介
    首先我们来了解下tomcat是什么,tomcat是apache软件基金会中的一个项目,由apache、Sun和其他一些公司及个人共同开发而成。主要作用是提供servlet和jsp类库;tomcat是一个免费开源的web服务器,它和nginx、httpd服务不同的是,它不擅长处理HTML代码,更多的是处理JSP程序;有点类似fpm服务专门处理php程序;
    jdk:java开发工具箱(JavaDevelopmentKit),主要提供java开发相关工具包,库文件以及jre和jvm相关组件,可以理解为java编程语言的一个基础标准库环境相关组件包和开发公具相关组件。

    jre:java运行时环境(Javaruntimeenvironment),该软件主要提供运行Java程序的环境;我们可以理解jre就是jvm和一些标准类库组成的一个Java程序运行环境;



    提示:从上面的图可以了解到JDK包含JRE,JRE包含jvm;
    jvm:Java虚拟机(Javavirtualmachine)主要作用是让Java程序实现跨平台,我们可以理解Java虚拟机的作用就是在转换不同操作系统底层的API;这样一来Java程序员就直接面向jvm提供的API进行编程,从而不用考虑其他操作系统底层API的不同;如下图


    提示:从上图就可以了解到jvm的重要性,它可以实现程序员一次编码,到处运行,正是jvm解决了底层操作系统不同API问题,使得java程序可以在任何具有jvm的设备上运行;
    二、JDK安装
    1、oraclejdk安装
    oraclejdk是oracle官方提供的一个jdk,安装我们可以直接去官方下载对应版本的包,到本地服务器即可。


    提示:我这里是提前下载好了的,上面官方地址还需要注册挺麻烦的;下载好rpm,然后直接使用yum安装即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[root@lxc java]# yum install ./jdk-8u211-linux-x64.rpm
Loaded plugins: fastestmirror
Examining ./jdk-8u211-linux-x64.rpm: 2000:jdk1.8-1.8.0_211-fcs.x86_64
Marking ./jdk-8u211-linux-x64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package jdk1.8.x86_64 2000:1.8.0_211-fcs will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
====================================================================================================
 Package         Arch            Version                        Repository                     Size
====================================================================================================
Installing:
 jdk1.8          x86_64          2000:1.8.0_211-fcs             /jdk-8u211-linux-x64          297 M
 
Transaction Summary
====================================================================================================
Install  1 Package
 
Total size: 297 M
Installed size: 297 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2000:jdk1.8-1.8.0_211-fcs.x86_64                                                 1/1
Unpacking JAR files...
        tools.jar...
        plugin.jar...
        javaws.jar...
        deploy.jar...
        rt.jar...
        jsse.jar...
        charsets.jar...
        localedata.jar...
  Verifying  : 2000:jdk1.8-1.8.0_211-fcs.x86_64                                                 1/1
 
Installed:
  jdk1.8.x86_64 2000:1.8.0_211-fcs                                                                 
 
Complete!
[root@lxc java]#

    提示:当然直接使用rpm-ivh也是可以直接安装的,这个jdk几乎没有依赖关系,所以可以直接通过rpm安装;通常有依赖关系的包建议还是使用yum去解决依赖关系;
    查看jdk-8u211-linux-x64.rpm生成的文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[root@lxc java]# rpm -qpi ./jdk-8u211-linux-x64.rpm
warning: ./jdk-8u211-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Name        : jdk1.8
Epoch       : 2000
Version     : 1.8.0_211
Release     : fcs
Architecture: x86_64
Install Date: (not installed)
Group       : Development/Tools
Size        : 311820630
License     : https://java.com/bc_license
Signature   : RSA/SHA256, Tue 02 Apr 2019 12:06:57 AM EDT, Key ID 72f97b74ec551f03
Source RPM  : jdk1.8-1.8.0_211-fcs.src.rpm
Build Date  : Mon 01 Apr 2019 11:55:52 PM EDT
Build Host  : java.com
Relocations : /usr/java
Vendor      : Oracle Corporation
URL         : http://www.oracle.com/technetwork/java/javase/overview/index.html
Summary     : Java Platform Standard Edition Development Kit
Description :
The Java Platform Standard Edition Development Kit (JDK) includes both
the runtime environment (Java virtual machine, the Java platform classes
and supporting files) and development tools (compilers, debuggers,
tool libraries and other tools).
 
The JDK is a development environment for building applications, applets
and components that can be deployed with the Java Platform Standard
Edition Runtime Environment.
[root@lxc java]# rpm -ql jdk1.8
/usr
/usr/java
/usr/java/jdk1.8.0_211-amd64
/usr/java/jdk1.8.0_211-amd64/.java
/usr/java/jdk1.8.0_211-amd64/.java/.systemPrefs
/usr/java/jdk1.8.0_211-amd64/.java/.systemPrefs/.system.lock
/usr/java/jdk1.8.0_211-amd64/.java/.systemPrefs/.systemRootModFile
/usr/java/jdk1.8.0_211-amd64/.java/init.d
/usr/java/jdk1.8.0_211-amd64/.java/init.d/jexec
/usr/java/jdk1.8.0_211-amd64/COPYRIGHT
/usr/java/jdk1.8.0_211-amd64/LICENSE
/usr/java/jdk1.8.0_211-amd64/README.html
/usr/java/jdk1.8.0_211-amd64/THIRDPARTYLICENSEREADME-JAVAFX.txt
/usr/java/jdk1.8.0_211-amd64/THIRDPARTYLICENSEREADME.txt
/usr/java/jdk1.8.0_211-amd64/bin
/usr/java/jdk1.8.0_211-amd64/bin/ControlPanel
/usr/java/jdk1.8.0_211-amd64/bin/appletviewer
/usr/java/jdk1.8.0_211-amd64/bin/extcheck
……省略部分内容

    提示:下载好的rpm包安装后,如果要查询其对应安装了那些文件,我们首先要知道它的名称是什么,用rpm-qpi命令可以查看到对应名称,然后我们再通过rpm-ql查看对应名称的软件安装生成了那些文件;从上面的信息可以看到jdk1.8生成的文件都在/usr/java/目录下;

    提示:从上面的截图可以了解到在/usr/java/目录下有两个软连接,default默认指向了latest这个软连接,latest软连接指向了jdk1.8;这意味着jdk可以同时存在多个版本,我们只需要把对应软连接修改了即可更新到新的版本;这里需要提醒下,如果多版本并存的情况,我们可以使用alternatives工具来切换;
    alternatives工具多版本相互切换

    切换前,默认使用1.8.0.211版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[root@lxc java]# alternatives --config java
 
There is 1 program that provides 'java'.
 
  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk1.8.0_211-amd64/jre/bin/java
 
Enter to keep the current selection[+], or type selection number: 1
[root@lxc java]# alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_79/bin/java 2
[root@lxc java]# alternatives --config java
 
There are 2 programs which provide 'java'.
 
  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk1.8.0_211-amd64/jre/bin/java
   2           /usr/java/jdk1.7.0_79/bin/java
 
Enter to keep the current selection[+], or type selection number: 2
[root@lxc java]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
[root@lxc java]# alternatives --config java
 
There are 2 programs which provide 'java'.
 
  Selection    Command
-----------------------------------------------
*  1           /usr/java/jdk1.8.0_211-amd64/jre/bin/java
 + 2           /usr/java/jdk1.7.0_79/bin/java
 
Enter to keep the current selection[+], or type selection number: 1
[root@lxc java]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
[root@lxc java]#

    提示:可以看到可以根据自己需要来回切换jdk的版本;到此oraclejdk的安装就完成了;
    2、openjdk安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
[root@docker_node01 ~]# yum install java-1.8.0-openjdk
Loaded plugins: fastestmirror
base                                                                         | 3.6 kB  00:00:00    
docker-ce-stable                                                             | 3.5 kB  00:00:00    
epel                                                                         | 4.7 kB  00:00:00    
extras                                                                       | 2.9 kB  00:00:00    
updates                                                                      | 2.9 kB  00:00:00    
(1/4): epel/x86_64/updateinfo                                                | 1.0 MB  00:00:00    
(2/4): extras/7/x86_64/primary_db                                            | 205 kB  00:00:00    
(3/4): updates/7/x86_64/primary_db                                           | 3.0 MB  00:00:01    
(4/4): epel/x86_64/primary_db                                                | 6.8 MB  00:00:01    
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirror.bit.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.252.b09-2.el7_8 will be installed
--> Processing Dependency: java-1.8.0-openjdk-headless(x86-64) = 1:1.8.0.252.b09-2.el7_8 for package: 1:java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64
--> Processing Dependency: xorg-x11-fonts-Type1 for package: 1:java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64
--> Processing Dependency: libjvm.so(SUNWprivate_1.1)(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64
……省略部分内容
Installed:
  java-1.8.0-openjdk.x86_64 1:1.8.0.252.b09-2.el7_8                                                
 
Dependency Installed:
  atk.x86_64 0:2.28.1-2.el7                                                                        
  cairo.x86_64 0:1.15.12-4.el7                                                                     
  copy-jdk-configs.noarch 0:3.3-10.el7_5                                                           
  cups-libs.x86_64 1:1.6.3-43.el7                                                                  
  fribidi.x86_64 0:1.0.2-1.el7_7.1                                                                 
  gdk-pixbuf2.x86_64 0:2.36.12-3.el7                                                               
  giflib.x86_64 0:4.1.6-9.el7                                                                      
  graphite2.x86_64 0:1.3.10-1.el7_3                                                                
  gtk-update-icon-cache.x86_64 0:3.22.30-5.el7                                                     
  gtk2.x86_64 0:2.24.31-1.el7                                                                      
  harfbuzz.x86_64 0:1.7.5-2.el7                                                                    
  hicolor-icon-theme.noarch 0:0.12-7.el7                                                           
  jasper-libs.x86_64 0:1.900.1-33.el7                                                              
  java-1.8.0-openjdk-headless.x86_64 1:1.8.0.252.b09-2.el7_8                                       
  javapackages-tools.noarch 0:3.4.1-11.el7                                                         
  jbigkit-libs.x86_64 0:2.0-11.el7                                                                 
  libICE.x86_64 0:1.0.9-9.el7                                                                      
  libSM.x86_64 0:1.2.2-2.el7                                                                       
  libXcomposite.x86_64 0:0.4.4-4.1.el7                                                             
  libXcursor.x86_64 0:1.1.15-1.el7                                                                 
  libXdamage.x86_64 0:1.1.4-4.1.el7                                                                
  libXext.x86_64 0:1.3.3-3.el7                                                                     
  libXfixes.x86_64 0:5.0.3-1.el7                                                                   
  libXft.x86_64 0:2.3.2-2.el7                                                                      
  libXi.x86_64 0:1.7.9-1.el7                                                                       
  libXinerama.x86_64 0:1.1.3-2.1.el7                                                               
  libXrandr.x86_64 0:1.5.1-2.el7                                                                   
  libXrender.x86_64 0:0.9.10-1.el7                                                                 
  libXtst.x86_64 0:1.2.3-1.el7                                                                     
  libXxf86vm.x86_64 0:1.1.4-1.el7                                                                  
  libfontenc.x86_64 0:1.1.3-3.el7                                                                  
  libglvnd.x86_64 1:1.0.1-0.8.git5baa1e5.el7                                                       
  libglvnd-egl.x86_64 1:1.0.1-0.8.git5baa1e5.el7                                                   
  libglvnd-glx.x86_64 1:1.0.1-0.8.git5baa1e5.el7                                                   
  libthai.x86_64 0:0.1.14-9.el7                                                                    
  libtiff.x86_64 0:4.0.3-32.el7                                                                    
  libwayland-client.x86_64 0:1.15.0-1.el7                                                          
  libwayland-server.x86_64 0:1.15.0-1.el7                                                          
  libxshmfence.x86_64 0:1.2-1.el7                                                                  
  lksctp-tools.x86_64 0:1.0.17-2.el7                                                               
  mesa-libEGL.x86_64 0:18.3.4-7.el7_8.1                                                            
  mesa-libGL.x86_64 0:18.3.4-7.el7_8.1                                                             
  mesa-libgbm.x86_64 0:18.3.4-7.el7_8.1                                                            
  mesa-libglapi.x86_64 0:18.3.4-7.el7_8.1                                                          
  pango.x86_64 0:1.42.4-4.el7_7                                                                    
  pcsc-lite-libs.x86_64 0:1.8.8-8.el7                                                              
  pixman.x86_64 0:0.34.0-1.el7                                                                     
  python-javapackages.noarch 0:3.4.1-11.el7                                                        
  python-lxml.x86_64 0:3.2.1-4.el7                                                                 
  ttmkfdir.x86_64 0:3.0.9-42.el7                                                                   
  tzdata-java.noarch 0:2020a-1.el7                                                                 
  xorg-x11-font-utils.x86_64 1:7.5-21.el7                                                          
  xorg-x11-fonts-Type1.noarch 0:7.5-9.el7                                                          
 
Dependency Updated:
  glib2.x86_64 0:2.56.1-5.el7                      libdrm.x86_64 0:2.4.97-2.el7                    
 
Complete!
[root@docker_node01 ~]#

    提示:安装openjdk使用yum安装需要注意命名,通常是java-版本号-openjdk;到此openjdk就安装好了,后续的版本切换也可以使用alternatives命令来切换即可和oraclejdk使用没有特别的不同;除了以上方式安装,当然我们也可以去下载二进制包,直接展开就可以,二进制包安装需要注意创建环境变量文件;好了安装jdk就不过多阐述了;接下来我们就可以安装tomcat了;
    三、tomcat安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@docker_node01 ~]# yum info tomcat
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirror.bit.edu.cn
Available Packages
Name        : tomcat
Arch        : noarch
Version     : 7.0.76
Release     : 12.el7_8
Size        : 92 k
Repo        : updates/7/x86_64
Summary     : Apache Servlet/JSP Engine, RI for Servlet 3.0/JSP 2.2 API
URL         : http://tomcat.apache.org/
License     : ASL 2.0
Description : Tomcat is the servlet container that is used in the official Reference
            : Implementation for the Java Servlet and JavaServer Pages technologies.
            : The Java Servlet and JavaServer Pages specifications are developed by
            : Sun under the Java Community Process.
            :
            : Tomcat is developed in an open and participatory environment and
            : released under the Apache Software License version 2.0. Tomcat is intended
            : to be a collaboration of the best-of-breed developers from around the world.
 
[root@docker_node01 ~]#

    提示:可以看到在updates仓库中有tomcat包,但是版本有点低,如果想要安装新一点的包,可以去官网下载对应包安装即可;官网地址:http://tomcat.apache.org/;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
[root@docker_node01 ~]# yum install tomcat -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirror.bit.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package tomcat.noarch 0:7.0.76-12.el7_8 will be installed
--> Processing Dependency: tomcat-lib = 7.0.76-12.el7_8 for package: tomcat-7.0.76-12.el7_8.noarch
--> Processing Dependency: apache-commons-pool for package: tomcat-7.0.76-12.el7_8.noarch
--> Processing Dependency: apache-commons-logging for package: tomcat-7.0.76-12.el7_8.noarch
--> Processing Dependency: apache-commons-dbcp for package: tomcat-7.0.76-12.el7_8.noarch
--> Processing Dependency: apache-commons-daemon for package: tomcat-7.0.76-12.el7_8.noarch
--> Processing Dependency: apache-commons-collections for package: tomcat-7.0.76-12.el7_8.noarch
--> Running transaction check
……省略部分内容
Installed:
  tomcat.noarch 0:7.0.76-12.el7_8                                                                  
 
Dependency Installed:
  apache-commons-collections.noarch 0:3.2.1-22.el7_2                                               
  apache-commons-daemon.x86_64 0:1.0.13-7.el7                                                      
  apache-commons-dbcp.noarch 0:1.4-17.el7                                                          
  apache-commons-logging.noarch 0:1.1.2-7.el7                                                      
  apache-commons-pool.noarch 0:1.6-9.el7                                                           
  avalon-framework.noarch 0:4.3-10.el7                                                             
  avalon-logkit.noarch 0:2.1-14.el7                                                                
  ecj.x86_64 1:4.5.2-3.el7                                                                         
  geronimo-jms.noarch 0:1.1.1-19.el7                                                               
  geronimo-jta.noarch 0:1.1.1-17.el7                                                               
  javamail.noarch 0:1.4.6-8.el7                                                                    
  log4j.noarch 0:1.2.17-16.el7_4                                                                   
  tomcat-el-2.2-api.noarch 0:7.0.76-12.el7_8                                                       
  tomcat-jsp-2.2-api.noarch 0:7.0.76-12.el7_8                                                      
  tomcat-lib.noarch 0:7.0.76-12.el7_8                                                              
  tomcat-servlet-3.0-api.noarch 0:7.0.76-12.el7_8                                                  
  xalan-j2.noarch 0:2.7.1-23.el7                                                                   
  xerces-j2.noarch 0:2.11.0-17.el7_0                                                               
  xml-commons-apis.noarch 0:1.4.01-16.el7                                                          
  xml-commons-resolver.noarch 0:1.2-15.el7                                                         
 
Complete!
[root@docker_node01 ~]#

    查看tomcat包安装所生成的文件
1
2
3
4
5
6
7
8
9
10
11