本文章內容:
- 部署環境1:yum安裝jdk + tomcat
- 部署環境2:yum安裝jdk + 官方下載tomcat
- 部署環境3:官方下載jdk + yum安裝tomcat
- 部署環境4:官方下載jdk + 官方下載tomcat
1.前言
使用yum安裝因版本較老舊會開放8009 port監聽,而因為8009 port監聽有安全漏洞,故請參閱"https://blog.wongcw.com/2020/02/22/%E9%97%9C%E6%96%BCapache-tomcat%E5%AD%98%E5%9C%A8%E6%96%87%E4%BB%B6%E5%8C%85%E5%90%AB%E6%BC%8F%E6%B4%9E%E7%9A%84%E5%AE%89%E5%85%A8%E5%85%AC%E5%91%8A/"文章將其關閉。
那因安全漏洞的關係,官網釋放的版本已經取消8009 port的監聽。
8009 port安全漏洞相關文章:
- https://www.ithome.com.tw/news/137074
- https://blog.wongcw.com/2020/02/22/%E9%97%9C%E6%96%BCapache-tomcat%E5%AD%98%E5%9C%A8%E6%96%87%E4%BB%B6%E5%8C%85%E5%90%AB%E6%BC%8F%E6%B4%9E%E7%9A%84%E5%AE%89%E5%85%A8%E5%85%AC%E5%91%8A/
2. 機器準備
[root@tcsr-1 ~]# hostname
tcsr-1.lab.com
[root@tcsr-1 ~]# ifconfig ens33 | awk 'NR==2 {print $2}'
[root@tcsr-1 ~]# ifconfig ens33 | awk 'NR==2'
inet 192.168.211.148 netmask 255.255.255.0 broadcast 192.168.211.255
3. 部署環境
- 部署環境1:yum安裝jdk + tomcat
- 部署環境2:yum安裝jdk + 官方下載tomcat
- 部署環境3:官方下載jdk + yum安裝tomcat
- 部署環境4:官方下載jdk + 官方下載tomcat
4. 部署環境1 (yum安裝jdk + tomcat)
4.1 安裝tomcat
[root@tcsr-1 ~]# yum install java-1.8.0-openjdk-devel.x86_64 tomcat tomcat-webapps tomcat-admin-webapps tomcat-docs-webapp –y
4.2 查看java版本
[root@tcsr-1 ~]# java -version
openjdk version "1.8.0_272"
OpenJDK Runtime Environment (build 1.8.0_272-b10)
OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode)
4.3 查看tomcat版本
[root@localhost ~]# tomcat version
Server version: Apache Tomcat/7.0.76
Server built: Nov 16 2020 16:51:26 UTC
Server number: 7.0.76.0
OS Name: Linux
OS Version: 3.10.0-1062.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_272-b10
JVM Vendor: Red Hat, Inc.
or
執行curl ip:8080 | grep "Apache Tomcat"
4.4 啟動tomcat服務
[root@tcsr-1 ~]# systemctl start tomcat.service
[root@tcsr-1 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 1 [::ffff:127.0.0.1]:8005 [::]:*
LISTEN 0 100 [::]:8009 [::]:*
LISTEN 0 100 [::]:8080 [::]:*
…
4.5 訪問”http://192.168.211.148:8080”
5. 部署環境2 (yum安裝jdk + 官方下載tomcat)
5.1 安裝jdk
[root@tcsr-1 ~]# yum install java-11-openjdk-devel.x86_64 –y
5.2 查看java版本
[root@tcsr-1 ~]# java -version
openjdk version "11.0.9" 2020-10-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.9+11-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.9+11-LTS, mixed mode, sharing)
5.3 安裝tomcat
5.3.1 訪問tomcat官網” http://tomcat.apache.org/” -> 在”Dowanload”處點”Tomcat 9”
5.3.2 在”Binary Distributions”處滑鼠右鍵tar.gz複製連結網址
5.3.3 使用wget下載到本機
[root@tcsr-1 ~]# wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.40/bin/apache-tomcat-9.0.40.tar.gz
[root@tcsr-1 ~]# ls
anaconda-ks.cfg apache-tomcat-9.0.40.tar.gz
5.3.4 解壓縮下載的二進制包
[root@tcsr-1 ~]# tar xf apache-tomcat-9.0.40.tar.gz -C /usr/local/
[root@tcsr-1 ~]# ls /usr/local/
apache-tomcat-9.0.40 bin etc games include lib lib64 libexec sbin share src
5.3.5 設定鏈接以方便往後更版
[root@tcsr-1 ~]# ln -sv /usr/local/apache-tomcat-9.0.40 /usr/local/tomcat
‘/usr/local/tomcat’ -> ‘/usr/local/apache-tomcat-9.0.40’
[root@tcsr-1 ~]# ll /usr/local/
total 0
drwxr-xr-x. 9 root root 220 Dec 7 02:26 apache-tomcat-9.0.40
drwxr-xr-x. 2 root root 6 Apr 11 2018 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x. 5 root root 49 Nov 26 03:54 share
drwxr-xr-x. 2 root root 6 Apr 11 2018 src
lrwxrwxrwx. 1 root root 31 Dec 7 02:30 tomcat -> /usr/local/apache-tomcat-9.0.40
5.4 設定tomcat環境變量
[root@tcsr-1 ~]# vim /etc/profile.d/tomcat.sh
export CATALINA_HOME=/usr/local/tomcat
export PATH=$CATALINA_HOME/bin:$PATH
提示:也可以如下設定
CATALINA_HOME=/usr/local/tomcat
PATH=$CATALINA_HOME/bin:$PATH
export CATALINA_HOME PATH
[root@tcsr-1 ~]# . /etc/profile.d/tomcat.sh
提示:也可以執行exec bash表示重啟bash,然後執行printenv可以看當前bash環境的環境變量。
5.5 查看tomcat版本
[root@tcsr-1 ~]# catalina.sh version
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
Server version: Apache Tomcat/9.0.40
Server built: Nov 12 2020 15:35:02 UTC
Server number: 9.0.40.0
OS Name: Linux
OS Version: 3.10.0-1062.el7.x86_64
Architecture: amd64
JVM Version: 11.0.9+11-LTS
JVM Vendor: Red Hat, Inc.
or
執行curl ip:8080 | grep "Apache Tomcat"
5.6 啟動tomcat服務
[root@tcsr-1 ~]# catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@tcsr-1 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 1 [::ffff:127.0.0.1]:8005 [::]:*
LISTEN 0 100 [::]:8080 [::]:*
…
5.7 訪問”http://192.168.211.148:8080”
6. 部署環境3 (官方下載jdk + yum安裝tomcat)
6.1 安裝jdk
6.1.1 訪問openjdk官網” https://openjdk.java.net/” -> 點” jdk.java.net/15”
6.1.2 滑鼠右鍵”Linux/x64”的”tar.gz”複製連結網址
6.1.3 使用wget下載到本機
[root@tcsr-1 ~]# wget https://download.java.net/java/GA/jdk15.0.1/51f4f36ad4ef43e39d0dfdbaf6549e32/9/GPL/openjdk-15.0.1_linux-x64_bin.tar.gz
[root@tcsr-1 ~]# ls
anaconda-ks.cfg openjdk-15.0.1_linux-x64_bin.tar.gz
6.1.4 解壓縮下載的二進制包
[root@tcsr-1 ~]# tar xf openjdk-15.0.1_linux-x64_bin.tar.gz -C /usr/lib
6.1.5 設定鏈接以方便往後更版
[root@tcsr-1 ~]# ln -sv /usr/lib/jdk-15.0.1 /usr/lib/java
‘/usr/lib/java’ -> ‘/usr/lib/jdk-15.0.1’
[root@tcsr-1 ~]# ll /usr/lib/
total 32
drwxr-xr-x. 2 root root 6 Aug 8 2019 binfmt.d
lrwxrwxrwx. 1 root root 10 Nov 26 03:54 cpp -> ../bin/cpp
drwxr-xr-x. 3 root root 64 Apr 11 2018 debug
drwxr-xr-x. 4 root root 236 Nov 26 03:55 dracut
drwxr-xr-x. 7 root root 81 Nov 26 03:55 firewalld
drwxr-xr-x. 90 root root 12288 Nov 26 03:55 firmware
dr-xr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 3 root root 33 Aug 6 2019 gcc
drwxr-xr-x. 3 root root 21 Nov 26 03:54 grub
lrwxrwxrwx. 1 root root 19 Dec 7 03:19 java -> /usr/lib/jdk-15.0.1
drwxr-xr-x. 8 root root 96 Dec 7 03:15 jdk-15.0.1
drwxr-xr-x. 6 root root 76 Nov 26 03:54 kbd
drwxr-xr-x. 2 root root 56 Nov 26 03:55 kdump
drwxr-xr-x. 3 root root 23 Aug 8 2019 kernel
drwxr-xr-x. 2 root root 55 Nov 26 03:54 locale
drwxr-xr-x. 2 root root 55 Nov 26 03:55 modprobe.d
drwxr-xr-x. 3 root root 36 Nov 26 03:55 modules
drwxr-xr-x. 2 root root 6 Aug 8 2019 modules-load.d
drwxr-xr-x. 4 root root 31 Nov 26 03:55 NetworkManager
drwxr-xr-x. 2 root root 50 Nov 26 03:55 polkit-1
drwxr-xr-x. 3 root root 27 Nov 26 03:55 python2.7
drwxr-xr-x. 6 root root 4096 Nov 26 03:55 rpm
lrwxrwxrwx. 1 root root 30 Nov 26 03:55 sendmail -> /etc/alternatives/mta-sendmail
lrwxrwxrwx. 1 root root 24 Nov 26 03:55 sendmail.postfix -> ../sbin/sendmail.postfix
dr-xr-xr-x. 2 root root 6 Apr 11 2018 sse2
drwxr-xr-x. 2 root root 85 Nov 26 03:55 sysctl.d
drwxr-xr-x. 12 root root 4096 Nov 26 03:55 systemd
drwxr-xr-x. 2 root root 4096 Nov 26 03:55 tmpfiles.d
drwxr-xr-x. 13 root root 256 Nov 26 03:55 tuned
drwxr-xr-x. 4 root root 252 Nov 26 03:55 udev
drwxr-xr-x. 4 root root 34 Nov 26 03:55 x86_64-redhat-linux6E
drwxr-xr-x. 2 root root 80 Aug 8 2019 yum-plugins
6.2 設定java環境變量
[root@tcsr-1 ~]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/lib/java
export PATH=$JAVA_HOME/bin:$PATH
提示:也可以如下設定
JAVA_HOME=/usr/lib/java
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH
[root@tcsr-1 ~]# . /etc/profile.d/java.sh
提示:也可以執行exec bash表示重啟bash,然後執行printenv可以看當前bash環境的環境變量。
6.3 查看java版本
[root@tcsr-1 ~]# java -version
openjdk version "15.0.1" 2020-10-20
OpenJDK Runtime Environment (build 15.0.1+9-18)
OpenJDK 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
6.4 安裝tomcat
[root@tcsr-1 ~]# yum install tomcat tomcat-webapps tomcat-admin-webapps tomcat-docs-webapp –y
6.5 查看tomcat版本
[root@tcsr-1 ~]# tomcat version
Server version: Apache Tomcat/7.0.76
Server built: Nov 16 2020 16:51:26 UTC
Server number: 7.0.76.0
OS Name: Linux
OS Version: 3.10.0-1062.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_272-b10
JVM Vendor: Red Hat, Inc.
or
執行curl ip:8080 | grep "Apache Tomcat"
[root@tcsr-1 ~]# java -version #雖然我們有自己安裝jdk及設定java環境變量,但tomcat還是使用它自己依賴安裝的java版本
openjdk version "15.0.1" 2020-10-20
OpenJDK Runtime Environment (build 15.0.1+9-18)
OpenJDK 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
6.6 修改tomcat的java版本
[root@tcsr-1 ~]# vim /etc/tomcat/tomcat.conf
22 # Where your java installation lives
23 JAVA_HOME="/usr/lib/java" #修改這一行
[root@tcsr-1 ~]# tomcat version #再執行一次tomcat version,其java版本就變為我們要的版本了
Server version: Apache Tomcat/7.0.76
Server built: Nov 16 2020 16:51:26 UTC
Server number: 7.0.76.0
OS Name: Linux
OS Version: 3.10.0-1062.el7.x86_64
Architecture: amd64
JVM Version: 15.0.1+9-18
JVM Vendor: Oracle Corporation
6.7 啟動tomcat服務
[root@tcsr-1 ~]# systemctl start tomcat.service
[root@tcsr-1 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 1 [::ffff:127.0.0.1]:8005 [::]:*
LISTEN 0 100 [::]:8009 [::]:*
LISTEN 0 100 [::]:8080 [::]:*
…
6.8 訪問”http://192.168.211.148:8080”
7. 部署環境4 (官方下載jdk + 官方下載tomcat)
7.1 安裝jdk
7.1.1 訪問openjdk官網” https://openjdk.java.net/” -> 點” jdk.java.net/15”
7.1.2 滑鼠右鍵”Linux/x64”的”tar.gz”複製連結網址
7.1.3 使用wget下載到本機
[root@tcsr-1 ~]# wget https://download.java.net/java/GA/jdk15.0.1/51f4f36ad4ef43e39d0dfdbaf6549e32/9/GPL/openjdk-15.0.1_linux-x64_bin.tar.gz
[root@tcsr-1 ~]# ls
anaconda-ks.cfg openjdk-15.0.1_linux-x64_bin.tar.gz
7.1.4 解壓縮下載的二進制包
[root@tcsr-1 ~]# tar xf openjdk-15.0.1_linux-x64_bin.tar.gz -C /usr/lib
7.1.5 設定鏈接以方便往後更版
[root@tcsr-1 ~]# ln -sv /usr/lib/jdk-15.0.1 /usr/lib/java
‘/usr/lib/java’ -> ‘/usr/lib/jdk-15.0.1’
[root@tcsr-1 ~]# ll /usr/lib/
total 32
drwxr-xr-x. 2 root root 6 Aug 8 2019 binfmt.d
lrwxrwxrwx. 1 root root 10 Nov 26 03:54 cpp -> ../bin/cpp
drwxr-xr-x. 3 root root 64 Apr 11 2018 debug
drwxr-xr-x. 4 root root 236 Nov 26 03:55 dracut
drwxr-xr-x. 7 root root 81 Nov 26 03:55 firewalld
drwxr-xr-x. 90 root root 12288 Nov 26 03:55 firmware
dr-xr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 3 root root 33 Aug 6 2019 gcc
drwxr-xr-x. 3 root root 21 Nov 26 03:54 grub
lrwxrwxrwx. 1 root root 19 Dec 7 03:19 java -> /usr/lib/jdk-15.0.1
drwxr-xr-x. 8 root root 96 Dec 7 03:15 jdk-15.0.1
drwxr-xr-x. 6 root root 76 Nov 26 03:54 kbd
drwxr-xr-x. 2 root root 56 Nov 26 03:55 kdump
drwxr-xr-x. 3 root root 23 Aug 8 2019 kernel
drwxr-xr-x. 2 root root 55 Nov 26 03:54 locale
drwxr-xr-x. 2 root root 55 Nov 26 03:55 modprobe.d
drwxr-xr-x. 3 root root 36 Nov 26 03:55 modules
drwxr-xr-x. 2 root root 6 Aug 8 2019 modules-load.d
drwxr-xr-x. 4 root root 31 Nov 26 03:55 NetworkManager
drwxr-xr-x. 2 root root 50 Nov 26 03:55 polkit-1
drwxr-xr-x. 3 root root 27 Nov 26 03:55 python2.7
drwxr-xr-x. 6 root root 4096 Nov 26 03:55 rpm
lrwxrwxrwx. 1 root root 30 Nov 26 03:55 sendmail -> /etc/alternatives/mta-sendmail
lrwxrwxrwx. 1 root root 24 Nov 26 03:55 sendmail.postfix -> ../sbin/sendmail.postfix
dr-xr-xr-x. 2 root root 6 Apr 11 2018 sse2
drwxr-xr-x. 2 root root 85 Nov 26 03:55 sysctl.d
drwxr-xr-x. 12 root root 4096 Nov 26 03:55 systemd
drwxr-xr-x. 2 root root 4096 Nov 26 03:55 tmpfiles.d
drwxr-xr-x. 13 root root 256 Nov 26 03:55 tuned
drwxr-xr-x. 4 root root 252 Nov 26 03:55 udev
drwxr-xr-x. 4 root root 34 Nov 26 03:55 x86_64-redhat-linux6E
drwxr-xr-x. 2 root root 80 Aug 8 2019 yum-plugins
7.2 設定java環境變量
[root@tcsr-1 ~]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/lib/java
export PATH=$JAVA_HOME/bin:$PATH
提示:也可以如下設定
JAVA_HOME=/usr/lib/java
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH
[root@tcsr-1 ~]# . /etc/profile.d/java.sh
提示:也可以執行exec bash表示重啟bash,然後執行printenv可以看當前bash環境的環境變量。
7.3 查看java版本
[root@tcsr-1 ~]# java -version
openjdk version "15.0.1" 2020-10-20
OpenJDK Runtime Environment (build 15.0.1+9-18)
OpenJDK 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
7.4 安裝tomcat
7.4.1 訪問tomcat官網” http://tomcat.apache.org/” -> 在”Dowanload”處點”Tomcat 9”
7.4.2 在”Binary Distributions”處滑鼠右鍵tar.gz複製連結網址
7.4.3 使用wget下載到本機
[root@tcsr-1 ~]# wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.40/bin/apache-tomcat-9.0.40.tar.gz
[root@tcsr-1 ~]# ls
anaconda-ks.cfg apache-tomcat-9.0.40.tar.gz openjdk-15.0.1_linux-x64_bin.tar.gz
7.4.4 解壓縮下載的二進制包
[root@tcsr-1 ~]# tar xf apache-tomcat-9.0.40.tar.gz -C /usr/local/
[root@tcsr-1 ~]# ls /usr/local/
apache-tomcat-9.0.40 bin etc games include lib lib64 libexec sbin share src
7.4.5 設定鏈接以方便往後更版
[root@tcsr-1 ~]# ln -sv /usr/local/apache-tomcat-9.0.40 /usr/local/tomcat
‘/usr/local/tomcat’ -> ‘/usr/local/apache-tomcat-9.0.40’
[root@tcsr-1 ~]# ll /usr/local/
total 0
drwxr-xr-x. 9 root root 220 Dec 7 03:31 apache-tomcat-9.0.40
drwxr-xr-x. 2 root root 6 Apr 11 2018 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x. 5 root root 49 Nov 26 03:54 share
drwxr-xr-x. 2 root root 6 Apr 11 2018 src
lrwxrwxrwx. 1 root root 31 Dec 7 03:35 tomcat -> /usr/local/apache-tomcat-9.0.40
7.5 設定tomcat環境變量
[root@tcsr-1 ~]# vim /etc/profile.d/tomcat.sh
export CATALINA_HOME=/usr/local/tomcat
export PATH=$CATALINA_HOME/bin:$PATH
提示:也可以如下設定
CATALINA_HOME=/usr/local/tomcat
PATH=$CATALINA_HOME/bin:$PATH
export CATALINA_HOME PATH
[root@tcsr-1 ~]# . /etc/profile.d/tomcat.sh
提示:也可以執行exec bash表示重啟bash,然後執行printenv可以看當前bash環境的環境變量。
7.6 查看tomcat版本
[root@tcsr-1 ~]# catalina.sh version
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/lib/java
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
Server version: Apache Tomcat/9.0.40
Server built: Nov 12 2020 15:35:02 UTC
Server number: 9.0.40.0
OS Name: Linux
OS Version: 3.10.0-1062.el7.x86_64
Architecture: amd64
JVM Version: 15.0.1+9-18
JVM Vendor: Oracle Corporation
or
執行curl ip:8080 | grep "Apache Tomcat"
7.7 啟動tomcat服務
[root@tcsr-1 ~]# catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/lib/java
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@tcsr-1 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 1 [::ffff:127.0.0.1]:8005 [::]:*
LISTEN 0 100 [::]:8080 [::]:*
…