一、相关术语简介
首先我们来了解下tomcat是什么,tomcat是apache软件基金会中的一个项目,由apache、Sun 和其他一些公司及个人共同开发而成。主要作用是提供servlet和jsp类库;tomcat是一个免费开源的web服务器,它和nginx、httpd服务不同的是,它不擅长处理HTML代码,更多的是处理JSP程序;有点类似fpm服务专门处理php程序;
jdk:java开发工具箱(Java Development Kit ),主要提供java开发相关工具包,库文件以及jre和jvm相关组件,可以理解为java编程语言的一个基础标准库环境相关组件包和开发公具相关组件。
jre:java运行时环境(Java runtime environment),该软件主要提供运行Java程序的环境;我们可以理解jre就是jvm和一些标准类库组成的一个Java程序运行环境;
提示:从上面的图可以了解到JDK包含JRE,JRE包含jvm;
jvm:Java虚拟机(Java virtual machine)主要作用是让Java程序实现跨平台,我们可以理解Java虚拟机的作用就是在转换不同操作系统底层的API;这样一来Java程序员就直接面向jvm提供的API进行编程,从而不用考虑其他操作系统底层API的不同;如下图
提示:从上图就可以了解到jvm的重要性,它可以实现程序员一次编码,到处运行,正是jvm解决了底层操作系统不同API问题,使得java程序可以在任何具有jvm的设备上运行;
二、JDK安装
1、oracle jdk安装
oracle jdk 是oracle官方提供的一个jdk,安装我们可以直接去官方下载对应版本的包,到本地服务器即可;官方下载地址https://www.oracle.com/cn/java/technologies/javase-downloads.html;
提示:我这里是提前下载好了的,上面官方地址还需要注册挺麻烦的;下载好rpm ,然后直接使用yum安装即可
[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生成的文件
[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版本
[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的版本;到此oracle jdk的安装就完成了;
2、openjdk安装
[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命令来切换即可和oracle jdk使用没有特别的不同;除了以上方式安装,当然我们也可以去下载二进制包,直接展开就可以,二进制包安装需要注意创建环境变量文件;好了安装jdk就不过多阐述了;接下来我们就可以安装tomcat了;
三、tomcat安装
[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/;
[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包安装所生成的文件
[root@docker_node01 ~]# 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@docker_node01 ~]#
提示:/etc/tomcat/是tomcat的配置文件目录,存放tomcat配置相关文件;/usr/lib/systemd/system/tomcat.service是tomcat的unit file启动脚本;/var/log/tomcat/catalina.out是tomcat的日志文件;
启动tomcat
提示:tomcat默认监听在tcp的8080端口;
测试:用浏览器访问对应服务器上的8080端口,看看是否访问到tomcat的默认提供的页面?
提示:可以看到用浏览器展示访问不到对应页面,提示我们404;这说明我们访问的页面不存在,原因是我们只安装了tomcat的程序包,并没有安装任何webapp,所以对应目录下都没有页面存在,所以我们现在访问提示我们404;
提示:对应目录下并没有任何的页面,所以我们访问时访问不到的;
安装tomcat-webapps、tomcat-docs-webapp 、tomcat-admin-webapps
[root@docker_node01 ~]# yum install -y tomcat-webapps tomcat-admin-webapps tomcat-docs-webapp 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-admin-webapps.noarch 0:7.0.76-12.el7_8 will be installed ---> Package tomcat-docs-webapp.noarch 0:7.0.76-12.el7_8 will be installed ---> Package tomcat-webapps.noarch 0:7.0.76-12.el7_8 will be installed --> Processing Dependency: jakarta-taglibs-standard >= 1.1 for package: tomcat-webapps-7.0.76-12.el7_8.noarch --> Running transaction check ---> Package jakarta-taglibs-standard.noarch 0:1.1.2-14.el7_1 will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================== Package Arch Version Repository Size ==================================================================================================== Installing: tomcat-admin-webapps noarch 7.0.76-12.el7_8 updates 40 k tomcat-docs-webapp noarch 7.0.76-12.el7_8 updates 721 k tomcat-webapps noarch 7.0.76-12.el7_8 updates 341 k Installing for dependencies: jakarta-taglibs-standard noarch 1.1.2-14.el7_1 base 303 k Transaction Summary ==================================================================================================== Install 3 Packages (+1 Dependent package) Total download size: 1.4 M Installed size: 5.4 M Downloading packages: (1/4): jakarta-taglibs-standard-1.1.2-14.el7_1.noarch.rpm | 303 kB 00:00:00 (2/4): tomcat-admin-webapps-7.0.76-12.el7_8.noarch.rpm | 40 kB 00:00:00 (3/4): tomcat-webapps-7.0.76-12.el7_8.noarch.rpm | 341 kB 00:00:00 (4/4): tomcat-docs-webapp-7.0.76-12.el7_8.noarch.rpm | 721 kB 00:00:00 ---------------------------------------------------------------------------------------------------- Total 2.7 MB/s | 1.4 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : jakarta-taglibs-standard-1.1.2-14.el7_1.noarch 1/4 Installing : tomcat-webapps-7.0.76-12.el7_8.noarch 2/4 Installing : tomcat-docs-webapp-7.0.76-12.el7_8.noarch 3/4 Installing : tomcat-admin-webapps-7.0.76-12.el7_8.noarch 4/4 Verifying : tomcat-admin-webapps-7.0.76-12.el7_8.noarch 1/4 Verifying : jakarta-taglibs-standard-1.1.2-14.el7_1.noarch 2/4 Verifying : tomcat-webapps-7.0.76-12.el7_8.noarch 3/4 Verifying : tomcat-docs-webapp-7.0.76-12.el7_8.noarch 4/4 Installed: tomcat-admin-webapps.noarch 0:7.0.76-12.el7_8 tomcat-docs-webapp.noarch 0:7.0.76-12.el7_8 tomcat-webapps.noarch 0:7.0.76-12.el7_8 Dependency Installed: jakarta-taglibs-standard.noarch 0:1.1.2-14.el7_1 Complete! [root@docker_node01 ~]#
查看/usr/shar/tomcat/webapps/下是否有文件?
提示:可以看到在/usr/share/tomcat/webapps/下已经有文件生成了,接下来我们再用浏览器访问下8080端口,看看是否能够访问到页面呢?
提示:可以看到我们能够正常访问到页面,说明tomcat环境搭建已经完成;后续我们就可以把java开发的一些jsp程序部署到tomcat上使用了;
官方下载tomcat部署
[root@lxc java]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.57/bin/apache-tomcat-8.5.57.tar.gz --2020-07-14 13:09:04-- https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.57/bin/apache-tomcat-8.5.57.tar.gz Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1 Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 10379806 (9.9M) [application/octet-stream] Saving to: ‘apache-tomcat-8.5.57.tar.gz’ 100%[==========================================================>] 10,379,806 1.90MB/s in 5.2s 2020-07-14 13:09:10 (1.90 MB/s) - ‘apache-tomcat-8.5.57.tar.gz’ saved [10379806/10379806] [root@lxc java]# ls apache-tomcat-8.5.57.tar.gz jdk-7u79-linux-x64.rpm jdk-8u211-linux-x64.rpm [root@lxc java]#
提示:官方默认只提供了二进制包和源码包,没有rpm包,所以我们下载二进制包解压到对应目录即可;
[root@lxc java]# mkdir /usr/share/tomcat [root@lxc java]# tar xf apache-tomcat-8.5.57.tar.gz -C /usr/share/tomcat [root@lxc java]# cd /usr/share/tomcat [root@lxc tomcat]# ls apache-tomcat-8.5.57 [root@lxc tomcat]#
创建软连接
[root@lxc tomcat]# ln -s apache-tomcat-8.5.57 tomcat [root@lxc tomcat]# ll total 0 drwxr-xr-x 9 root root 220 Jul 14 13:10 apache-tomcat-8.5.57 lrwxrwxrwx 1 root root 20 Jul 14 13:12 tomcat -> apache-tomcat-8.5.57 [root@lxc tomcat]#
创建tomcat用户
[root@lxc tomcat]# useradd -r tomcat [root@lxc tomcat]# getent passwd tomcat tomcat:x:996:992::/home/tomcat:/bin/bash [root@lxc tomcat]#
更改/usr/share/tomcat/tomcat属主/组权限为tomcat
[root@lxc tomcat]# ll total 124 drwxr-x--- 2 root root 4096 Jul 14 13:10 bin -rw-r----- 1 root root 19318 Jun 30 17:53 BUILDING.txt drwx------ 2 root root 238 Jun 30 17:53 conf -rw-r----- 1 root root 5408 Jun 30 17:53 CONTRIBUTING.md drwxr-x--- 2 root root 4096 Jul 14 13:10 lib -rw-r----- 1 root root 57011 Jun 30 17:53 LICENSE drwxr-x--- 2 root root 6 Jun 30 17:49 logs -rw-r----- 1 root root 1726 Jun 30 17:53 NOTICE -rw-r----- 1 root root 3255 Jun 30 17:53 README.md -rw-r----- 1 root root 7136 Jun 30 17:53 RELEASE-NOTES -rw-r----- 1 root root 16262 Jun 30 17:53 RUNNING.txt drwxr-x--- 2 root root 30 Jul 14 13:10 temp drwxr-x--- 7 root root 81 Jun 30 17:50 webapps drwxr-x--- 2 root root 6 Jun 30 17:49 work [root@lxc tomcat]# chown -R tomcat:tomcat ./* [root@lxc tomcat]# ll total 124 drwxr-x--- 2 tomcat tomcat 4096 Jul 14 13:10 bin -rw-r----- 1 tomcat tomcat 19318 Jun 30 17:53 BUILDING.txt drwx------ 2 tomcat tomcat 238 Jun 30 17:53 conf -rw-r----- 1 tomcat tomcat 5408 Jun 30 17:53 CONTRIBUTING.md drwxr-x--- 2 tomcat tomcat 4096 Jul 14 13:10 lib -rw-r----- 1 tomcat tomcat 57011 Jun 30 17:53 LICENSE drwxr-x--- 2 tomcat tomcat 6 Jun 30 17:49 logs -rw-r----- 1 tomcat tomcat 1726 Jun 30 17:53 NOTICE -rw-r----- 1 tomcat tomcat 3255 Jun 30 17:53 README.md -rw-r----- 1 tomcat tomcat 7136 Jun 30 17:53 RELEASE-NOTES -rw-r----- 1 tomcat tomcat 16262 Jun 30 17:53 RUNNING.txt drwxr-x--- 2 tomcat tomcat 30 Jul 14 13:10 temp drwxr-x--- 7 tomcat tomcat 81 Jun 30 17:50 webapps drwxr-x--- 2 tomcat tomcat 6 Jun 30 17:49 work [root@lxc tomcat]#
添加环境变量
[root@lxc tomcat]# cat /etc/profile.d/tomcat.sh CATALINA_BASE=/usr/share/tomcat/tomcat PATH=$CATALINA_BASE/bin:$PATH export CATALINA_BASE PATH [root@lxc tomcat]#
切换tomcat用户启动tomcat
[root@lxc tomcat]# su - tomcat Last login: Tue Jul 14 13:26:15 EDT 2020 on pts/0 su: warning: cannot change directory to /home/tomcat: No such file or directory -bash-4.2$ catalina.sh --help Using CATALINA_BASE: /usr/share/tomcat/tomcat Using CATALINA_HOME: /usr/share/tomcat/tomcat Using CATALINA_TMPDIR: /usr/share/tomcat/tomcat/temp Using JRE_HOME: / Using CLASSPATH: /usr/share/tomcat/tomcat/bin/bootstrap.jar:/usr/share/tomcat/tomcat/bin/tomcat-juli.jar Usage: catalina.sh ( commands ... ) commands: debug Start Catalina in a debugger debug -security Debug Catalina with a security manager jpda start Start Catalina under JPDA debugger run Start Catalina in the current window run -security Start in the current window with security manager start Start Catalina in a separate window start -security Start in a separate window with security manager stop Stop Catalina, waiting up to 5 seconds for the process to end stop n Stop Catalina, waiting up to n seconds for the process to end stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running configtest Run a basic syntax check on server.xml - check exit code for result version What version of tomcat are you running? Note: Waiting for the process to end and use of the -force option require that $CATALINA_PID is defined -bash-4.2$ catalina.sh start Using CATALINA_BASE: /usr/share/tomcat/tomcat Using CATALINA_HOME: /usr/share/tomcat/tomcat Using CATALINA_TMPDIR: /usr/share/tomcat/tomcat/temp Using JRE_HOME: / Using CLASSPATH: /usr/share/tomcat/tomcat/bin/bootstrap.jar:/usr/share/tomcat/tomcat/bin/tomcat-juli.jar Tomcat started. -bash-4.2$ ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:6033 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:3306 *:* LISTEN 0 128 *:3306 *:* LISTEN 0 128 *:3306 *:* LISTEN 0 128 *:3306 *:* LISTEN 0 100 :::8080 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* LISTEN 0 128 :::2377 :::* LISTEN 0 128 :::7946 :::* -bash-4.2$
提示:启动tomcat要使用内部的shell脚本catalina.sh 来启动;当然startup.sh也是可以的;可以看到8080端口已经处于监听的状态,接下来我们用浏览器尝试访问下,看看是否能够访问到页面?
提示:可以看到tomcat提供的页面我们是能够正常访问,说明我们安装部署的tomcat环境就准备就绪了;到此tomcat环境安装就部署完毕了;总结一点,部署tomcat环境,首先要安装jdk,因为tomcat本身就是java语言编写,我们要在服务器上安装好java程序运行环境和标准类库等组件,tomcat才可以服务器上正常的运行起来;其实从上面的演示我们大概也能知道tomcat就是为Java jsp程序提供一个运行环境,后续的jsp代码主要就是在tomcat上运行,而非jdk上;jdk是运行Java程序(tomcat)而必须有的组件;后续本人会持续更新有关tomcat配置使用相关的话题,感兴趣的同学可以关注关注;