安装JDK
1、下载jdk17
[root@mysql80 ~]# wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
[root@mysql80 ~]# ll -h jdk-17_linux-x64_bin.tar.gz
-rw-r--r--. 1 root root 174M Mar 18 03:53 jdk-17_linux-x64_bin.tar.gz
2、安装目录
[root@mysql80 ~]# mkdir -p /usr/local/tomcat
3、解压缩
[root@mysql80 ~]# tar -zxf jdk-17_linux-x64_bin.tar.gz -C /usr/local/tomcat/
4、设置软连接
[root@mysql80 ~]# ln -s /usr/local/tomcat/jdk-17.0.7/ /usr/local/tomcat/jdk17
[root@mysql80 ~]# ll -h /usr/local/tomcat/jdk17
lrwxrwxrwx. 1 root root 29 Jul 18 14:42 /usr/local/tomcat/jdk17 -> /usr/local/tomcat/jdk-17.0.7/
5、配置环境变量
[root@mysql80 ~]# vim .bash_profile
export JAVA_HOME=/usr/local/tomcat/jdk17
export PATH=$PATH:$JAVA_HOME/bin
[root@mysql80 ~]# source .bash_profile
6、配置java执行程序的软链接
[root@mysql80 ~]# java -version
-bash: java: command not found
[root@mysql80 ~]# ln -s /usr/local/cluster/jdk /usr/bin/java
[root@mysql80 ~]# ll -h /usr/bin/java
lrwxrwxrwx. 1 root root 32 Jul 18 14:45 /usr/bin/java -> /usr/local/tomcat/jdk17/bin/java
[root@mysql80 ~]# java -version
java version "17.0.7" 2023-04-18 LTS
Java(TM) SE Runtime Environment (build 17.0.7+8-LTS-224)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.7+8-LTS-224, mixed mode, sharing)
[root@mysql80 ~]# javac -version
-bash: javac: command not found
[root@mysql80 ~]# ln -s /usr/local/tomcat/jdk17/bin/javac /usr/bin/javac
[root@mysql80 ~]# javac -version
javac 17.0.7
测试Java
[root@mysql80 ~]# vim JavaTest.java
public class JavaTest{
public static void main(String args[]){
System.out.println("Hello World!");
}
}
[root@mysql80 ~]# javac JavaTest.java
[root@mysql80 ~]# java JavaTest
Hello World!
安装Tomcat
1、创建tomcat用户和用户组
[root@mysql80 ~]# groupadd -g 3306 tomcat
[root@mysql80 ~]# useradd -g tomcat -u 3306 tomcat
[root@mysql80 ~]# id tomcat
uid=3306(tomcat) gid=3306(tomcat) groups=3306(tomcat)
[root@mysql80 ~]# echo "oracle" | passwd --stdin tomcat
Changing password for user tomcat.
passwd: all authentication tokens updated successfully.
2、下载tomcat
[root@mysql80 ~]# su - tomcat
[tomcat@mysql80 ~]$ wget https://downloads.apache.org/tomcat/tomcat-10/v10.1.11/bin/apache-tomcat-10.1.11.tar.gz
--2023-07-18 15:02:12-- https://downloads.apache.org/tomcat/tomcat-10/v10.1.11/bin/apache-tomcat-10.1.11.tar.gz
Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 135.181.214.104, 2a01:4f8:10a:201a::2, ...
Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12146928 (12M) [application/x-gzip]
Saving to: ‘apache-tomcat-10.1.11.tar.gz’
100%[===================================================>] 12,146,928 1.64MB/s in 8.9s
2023-07-18 15:02:22 (1.30 MB/s) - ‘apache-tomcat-10.1.11.tar.gz’ saved [12146928/12146928]
[tomcat@mysql80 ~]$ ll -h apache-tomcat-10.1.11.tar.gz
-rw-rw-r--. 1 tomcat tomcat 12M Jul 6 22:16 apache-tomcat-10.1.11.tar.gz
[root@mysql80 ~]# tar -zxf /home/tomcat/apache-tomcat-10.1.11.tar.gz -C /usr/local/tomcat/
[tomcat@mysql80 ~]$ ll -h /usr/local/tomcat/
total 0
drwxr-xr-x. 9 root root 220 Jul 18 15:05 apache-tomcat-10.1.11
lrwxrwxrwx. 1 root root 29 Jul 18 14:42 jdk17 -> /usr/local/tomcat/jdk-17.0.7/
drwxr-xr-x. 9 root root 136 Jul 18 14:41 jdk-17.0.7
3、创建软连接
[root@mysql80 ~]# ln -s /usr/local/tomcat/apache-tomcat-10.1.11/ /usr/local/tomcat/tomcat10
4、修改tomcat安装目录权限
[root@mysql80 ~]# chown -R tomcat:tomcat /usr/local/tomcat/tomcat10/
5、启动tomcat
[root@mysql80 ~]# su - tomcat
[tomcat@mysql80 ~]$ cd /usr/local/tomcat/tomcat10/bin
[tomcat@mysql80 bin]$ ll -h
total 776K
-rw-r-----. 1 tomcat tomcat 36K Jul 6 21:45 bootstrap.jar
-rw-r-----. 1 tomcat tomcat 15K Jul 6 21:45 catalina.bat
-rwxr-x---. 1 tomcat tomcat 23K Jul 6 21:45 catalina.sh
-rw-r-----. 1 tomcat tomcat 1.7K Jul 6 21:45 catalina-tasks.xml
-rw-r-----. 1 tomcat tomcat 2.1K Jul 6 21:45 ciphers.bat
-rwxr-x---. 1 tomcat tomcat 2.0K Jul 6 21:45 ciphers.sh
-rw-r-----. 1 tomcat tomcat 26K Jul 6 21:45 commons-daemon.jar
-rw-r-----. 1 tomcat tomcat 210K Jul 6 21:45 commons-daemon-native.tar.gz
-rw-r-----. 1 tomcat tomcat 2.0K Jul 6 21:45 configtest.bat
-rwxr-x---. 1 tomcat tomcat 1.9K Jul 6 21:45 configtest.sh
-rwxr-x---. 1 tomcat tomcat 8.2K Jul 6 21:45 daemon.sh
-rw-r-----. 1 tomcat tomcat 2.1K Jul 6 21:45 digest.bat
-rwxr-x---. 1 tomcat tomcat 2.0K Jul 6 21:45 digest.sh
-rw-r-----. 1 tomcat tomcat 3.6K Jul 6 21:45 makebase.bat
-rwxr-x---. 1 tomcat tomcat 3.4K Jul 6 21:45 makebase.sh
-rw-r-----. 1 tomcat tomcat 2.1K Jul 6 21:45 migrate.bat
-rwxr-x---. 1 tomcat tomcat 2.0K Jul 6 21:45 migrate.sh
-rw-r-----. 1 tomcat tomcat 3.4K Jul 6 21:45 setclasspath.bat
-rwxr-x---. 1 tomcat tomcat 3.9K Jul 6 21:45 setclasspath.sh
-rw-r-----. 1 tomcat tomcat 2.0K Jul 6 21:45 shutdown.bat
-rwxr-x---. 1 tomcat tomcat 1.9K Jul 6 21:45 shutdown.sh
-rw-r-----. 1 tomcat tomcat 2.0K Jul 6 21:45 startup.bat
-rwxr-x---. 1 tomcat tomcat 1.9K Jul 6 21:45 startup.sh
-rw-r-----. 1 tomcat tomcat 48K Jul 6 21:45 tomcat-juli.jar
-rw-r-----. 1 tomcat tomcat 312K Jul 6 21:45 tomcat-native.tar.gz
-rw-r-----. 1 tomcat tomcat 3.6K Jul 6 21:45 tool-wrapper.bat
-rwxr-x---. 1 tomcat tomcat 4.5K Jul 6 21:45 tool-wrapper.sh
-rw-r-----. 1 tomcat tomcat 2.0K Jul 6 21:45 version.bat
-rwxr-x---. 1 tomcat tomcat 1.9K Jul 6 21:45 version.sh
[root@mysql80 ~]# netstat -anp | grep 8080
启动
[tomcat@mysql80 bin]$ ./startup.sh
Using CATALINA_BASE: /usr/local/tomcat/tomcat10
Using CATALINA_HOME: /usr/local/tomcat/tomcat10
Using CATALINA_TMPDIR: /usr/local/tomcat/tomcat10/temp
Using JRE_HOME: /
Using CLASSPATH: /usr/local/tomcat/tomcat10/bin/bootstrap.jar:/usr/local/tomcat/tomcat10/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[tomcat@mysql80 bin]$ ps -ef | grep java | grep -v grep
tomcat 22275 1 13 16:27 pts/0 00:00:03 //bin/java -Djava.util.logging.config.file=/usr/local/tomcat/tomcat10/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED -classpath /usr/local/tomcat/tomcat10/bin/bootstrap.jar:/usr/local/tomcat/tomcat10/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat/tomcat10 -Dcatalina.home=/usr/local/tomcat/tomcat10 -Djava.io.tmpdir=/usr/local/tomcat/tomcat10/temp org.apache.catalina.startup.Bootstrap start
[root@mysql80 ~]# netstat -anp | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 22275/java
查看日志
[tomcat@mysql80 logs]$ tail -100f catalina.out
18-Jul-2023 16:27:24.168 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/10.1.11
18-Jul-2023 16:27:24.171 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jul 6 2023 13:45:39 UTC
18-Jul-2023 16:27:24.172 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 10.1.11.0
18-Jul-2023 16:27:24.172 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
18-Jul-2023 16:27:24.172 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 3.10.0-1062.el7.x86_64
18-Jul-2023 16:27:24.172 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
18-Jul-2023 16:27:24.173 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/local/tomcat/jdk-17.0.7
18-Jul-2023 16:27:24.173 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 17.0.7+8-LTS-224
18-Jul-2023 16:27:24.173 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
18-Jul-2023 16:27:24.173 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat/apache-tomcat-10.1.11
18-Jul-2023 16:27:24.173 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat/apache-tomcat-10.1.11
18-Jul-2023 16:27:24.191 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/tomcat10/conf/logging.properties
18-Jul-2023 16:27:24.191 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
18-Jul-2023 16:27:24.191 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
18-Jul-2023 16:27:24.191 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
18-Jul-2023 16:27:24.191 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
18-Jul-2023 16:27:24.191 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
18-Jul-2023 16:27:24.191 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
18-Jul-2023 16:27:24.191 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
18-Jul-2023 16:27:24.192 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
18-Jul-2023 16:27:24.192 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
18-Jul-2023 16:27:24.192 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat/tomcat10
18-Jul-2023 16:27:24.192 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat/tomcat10
18-Jul-2023 16:27:24.192 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/tomcat10/temp
18-Jul-2023 16:27:24.193 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib]
18-Jul-2023 16:27:24.542 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
18-Jul-2023 16:27:24.573 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [645] milliseconds
18-Jul-2023 16:27:24.622 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
18-Jul-2023 16:27:24.623 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/10.1.11]
18-Jul-2023 16:27:24.636 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/apache-tomcat-10.1.11/webapps/ROOT]
18-Jul-2023 16:27:24.985 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/apache-tomcat-10.1.11/webapps/ROOT] has finished in [348] ms
18-Jul-2023 16:27:24.985 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/apache-tomcat-10.1.11/webapps/docs]
18-Jul-2023 16:27:25.007 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/apache-tomcat-10.1.11/webapps/docs] has finished in [22] ms
18-Jul-2023 16:27:25.011 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/apache-tomcat-10.1.11/webapps/examples]
18-Jul-2023 16:27:25.388 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/apache-tomcat-10.1.11/webapps/examples] has finished in [378] ms
18-Jul-2023 16:27:25.389 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/apache-tomcat-10.1.11/webapps/host-manager]
18-Jul-2023 16:27:25.419 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/apache-tomcat-10.1.11/webapps/host-manager] has finished in [30] ms
18-Jul-2023 16:27:25.419 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/apache-tomcat-10.1.11/webapps/manager]
18-Jul-2023 16:27:25.470 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/apache-tomcat-10.1.11/webapps/manager] has finished in [51] ms
18-Jul-2023 16:27:25.479 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
18-Jul-2023 16:27:25.535 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [961] milliseconds
6、开放8080端口
[root@mysql80 ~]# firewall-cmd --add-port=8080/tcp --permanent
success
[root@mysql80 ~]# firewall-cmd --reload
success
[root@mysql80 ~]# nmap localhost
Starting Nmap 6.40 ( http://nmap.org ) at 2023-07-18 16:30 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000027s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
3306/tcp open mysql
8080/tcp open http-proxy
Nmap done: 1 IP address (1 host up) scanned in 1.61 seconds
[root@mysql80 ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: dhcpv6-client http ssh
ports: 3306/tcp 8080/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
7、测试
http://192.168.255.111:8080/