一、相關術語簡介
首先我們來了解下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配置使用相關的話題,感興趣的同學可以關注關注;