foreword
Tomcat server is a free and open source Web application server , which belongs to the Apache Software Foundation and is a lightweight application server. It is the first choice for developing Java language and debugging JSP programs. Unlike Apache and Nginx, Tomcat's default port is 8080.
Tomcat's LOGO and mascot is designed as a male cat.
Now to install the tomcat service, you need to close the selinux and firewall in the server first, this is directly operated
setenforce 0
iptables -F
systemctl stop firewalld
The server used to install the tomcat service today is CentOS7.9, the tomcat version is above 10, and the jdk environment is 19.0.2.
server | IP | tomcat version | JDK version |
---|---|---|---|
CentOS7.9 | 192.168.116.128 | v10.1.7 | 19.0.2 |
1. Installation package location
The package location is still the same. Find the packages you need on the official website
JDK (Java Development Kit) is a Java language software development kit (SDK). To install tomcat, you need to start JDK first.
Both uploading and downloading are possible. It is recommended to install the compressed package locally first, and then upload it to the server, which will be faster. Of course, you can also use wget to download.
Both download methods are listed
The first method: download to the local and then use the rz command to upload
https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.7/bin/apache-tomcat-10.1.7.tar.gz —tomcat10.1.7 version
https://download.java.net/java/GA/jdk19.0.2/fdb695a9d9064ad6b064dc6df578380c/7/GPL/openjdk-19.0.2_linux-x64_bin.tar.gz — JDK19.0.2 Version
2: Download directly from the server
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.7/bin/apache-tomcat-10.1.7.tar.gz
wget https://download.java.net/java/GA/jdk19.0.2/fdb695a9d9064ad6b064dc6df578380c/7/GPL/openjdk-19.0.2_linux-x64_bin.tar.gz
You can choose one of the above two methods, and here we directly use the first method to upload the compressed package.
2. Upload the software package
Upload the compressed package to the current directory of the server
rz
[root@localhost ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg 公共 视频 文档 音乐
apache-tomcat-10.1.7.tar.gz openjdk-19.0.2_linux-x64_bin.tar.gz 模板 图片 下载 桌面
Since the tomcat service runs based on the jdk development environment, we need to deploy and install the jdk environment first.
3. Install JDK
JDK (Java Development Kit) is a Java language software development kit (SDK)
JDK official website address: https://jdk.java.net
3.1 Create a directory to store JDK and decompress it
tar xf
Indicates to decompress the compressed package file, -C
which means to store the decompressed file in the specified directory
[root@localhost ~]# mkdir -p /usr/local/jdk
[root@localhost ~]# tar xf openjdk-19.0.2_linux-x64_bin.tar.gz -C /usr/local/jdk
3.2 Setting environment variables
Environment variables need to be set so that JDK commands can be executed anywhere.
[root@localhost jdk]# cd jdk-19.0.2/
[root@localhost jdk-19.0.2]# pwd
/usr/local/jdk/jdk-19.0.2
[root@localhost jdk-19.0.2]# ls
bin conf include jmods legal lib release
[root@localhost jdk-19.0.2]# vim /etc/profile
[root@localhost jdk-19.0.2]# tail -4 !$
tail -4 /etc/profile
export JAVA_HOME=/usr/local/jdk/jdk-19.0.2
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH CLASSPATH
[root@localhost jdk-19.0.2]# source /etc/profile
Fill in the file path where jdk is located
export JAVA_HOME=/usr/local/jdk/jdk-19.0.2
Set the Java environment variable to tell the jvm what path to use or execute the class on, so that the JVM can load the class file,
.;
indicating the current path, tools.jar and dt.jar are the class library path
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
The command Java can be recognized in any path
PATH=$JAVA_HOME/bin:$PATH
After adding these contents to /etc/profile, the Java command can be used.
3.3 Check the JDK version
[root@localhost jdk-19.0.2]# java --version
openjdk 19.0.2 2023-01-17
OpenJDK Runtime Environment (build 19.0.2+7-44)
OpenJDK 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)
After the jdk development environment is in operation, you can start to install the tomcat service.
4. Install tomcat service
Tomcat official website address: https://tomcat.apache.org/
The speed of tomcat version update is relatively fast, with an average of 2-3 months to update a small version.
4.1 Unzip and move to the specified directory
Still use tar xf
the decompressed file and mv
rename the directory file for easy viewing.
[root@localhost ~]# ls
anaconda-ks.cfg openjdk-19.0.2_linux-x64_bin.tar.gz 视频 下载
apache-tomcat-10.1.7.tar.gz 公共 图片 音乐
initial-setup-ks.cfg 模板 文档 桌面
[root@localhost ~]# tar xf apache-tomcat-10.1.7.tar.gz -C /usr/local
[root@localhost ~]# cd !$
cd /usr/local
[root@localhost local]# mv apache-tomcat-10.1.7/ tomcat
[root@localhost local]# cd tomcat/
[root@localhost tomcat]# ls
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
4.2 View tomcat version
After entering bin
the directory, you can directly execute the script to view version
the version
[root@localhost tomcat]# cd bin/
[root@localhost bin]# ls
#后缀.bat是使用在windows平台的,而.sh是在Linux上启动的脚本。
bootstrap.jar configtest.bat migrate.sh tomcat-native.tar.gz
catalina.bat configtest.sh setclasspath.bat tool-wrapper.bat
catalina.sh daemon.sh setclasspath.sh tool-wrapper.sh
catalina-tasks.xml digest.bat shutdown.bat version.bat
ciphers.bat digest.sh shutdown.sh version.sh
ciphers.sh makebase.bat startup.bat
commons-daemon.jar makebase.sh startup.sh
commons-daemon-native.tar.gz migrate.bat tomcat-juli.jar
[root@localhost bin]# ./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/local/jdk/jdk-19.0.2
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Server version: Apache Tomcat/10.1.7
Server built: Feb 27 2023 20:25:27 UTC
Server number: 10.1.7.0
OS Name: Linux
OS Version: 3.10.0-1160.el7.x86_64
Architecture: amd64
JVM Version: 19.0.2+7-44
JVM Vendor: Oracle Corporation
4.3 start tomcat
tomcat
The startup script is in bin
the directory
[root@localhost bin]# ./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/local/jdk/jdk-19.0.2
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
See the last display tomcat started已
successfully started
4.4 tomcat listening port
Note that when you check the listening port, it is not 过滤tomcat
the name, but you need 过滤java
or 8080
to see whether the service has started successfully.
#查看tomcat默认端口是8080
[root@localhost bin]# netstat -antp | grep java
tcp6 0 0 :::8080 :::* LISTEN 56648/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 56648/java
4.5 Access and view on the web page
Use the method of IP plus port to access, where IP adds the IP of your own server.
http://192.168.116.128:8080/
The installation up to here tomcat
is complete.
Summarize
tomcat
The installation of .