tomcat download installation & configuration tutorial

tomcat needs java environment so jdk needs to be installed

1 Install jdk

1.1 Install jdk

Create a new java directory under /usr/local/, then download jdk-xxxxx.tar.gz, extract it to the /usr/local/java directory,

[root@localhost /]# mkdir /usr/local/java`
[root@localhost /]# tar fx jdk-xxxx.tar.gz -C /usr/local/java

1.2 Setting environment variables after installing JDK

[root@localhost ~]# vi /etc/profile

Edit the profile file and add the following three lines
export JAVA_HOME=/usr/local/java/jdk-19
export PATH= PATH : PATH:PATH:MYSQL_HOME/bin: J A V A H O M E / b i n e x p o r t C L A S S P A T H = JAVA_HOME/bin export CLASSPATH= JAVAHOME/binexportCLASSPATH=JAVA_HOME/lib/tools.jar: J A V A H O M E / l i b / d t . j a r : JAVA_HOME/lib/dt.jar: JAVAHOME/lib/dt.jar:JAVA_HOME/lib

1.3 Make environment variables take effect

[root@localhost ~]# source /etc/profile

1.4 View java version

[root@localhost ~]# java -version

insert image description here

2 Install tomcat

2.1 Create a new folder tomcat in the /usr/local directory

Transfer the downloaded compressed package apache-tomcat-7.0.100.tar.gz to the tomcat directory through the FTP tool

[root@localhost ~]# mkdir /usr/local/tomcat`
[root@localhost ~]# tar fx /apache-tomcat-8.5.82.tar.gz -C /usr/local/tomcat/

2.2 Modify the profile file in the /etc directory

[root@localhost ~]# vi /etc/profile

Add the following content at the end of the profile file:
export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-8.5.82
Please modify it according to the actual installation path and tomcat version

2.3 After the modification is completed, execute the following command to make the modification take effect

[root@localhost ~]# source /etc/profile

2.4 Configure Firewall

Open port 8080

[root@localhost /]# firewall-cmd --permanent --zone=public --add-port=8080/tcp 
success
2.4.1 Reload the firewall configuration to make the previous command take effect
[root@localhost /]# firewall-cmd --reload 
success
2.4.2 Test whether the port has been released

[root@localhost /]# firewall-cmd --zone=public --query-port=8080/tcp
yes
insert image description here

2.5 Enter the bin folder in the tomcat installation directory, and then execute the tomcat startup command

[root@localhost ~]# cd /usr/local/tomcat/apache-tomcat-8.5.82/bin/ ./startup.sh

If Tomcat started is displayed, it means that Tomcat has started successfully
. Finally, enter http://server public IP address: 8080 in the browser. If the page shown in the figure below appears, it means that Tomcat has been successfully installed.

2.6 Enter the Tomcat management page

After the installation of tomcat is completed, you can access the tomcat homepage through ip, you will find that the manager file of tomcat cannot be entered at this time, and an error 403 is reported. At this time, we need to do the following.

2.6.1 A tomcat-user.xm file in the conf folder of the tomcat directory, modify this file, and enter the following content in the tomcat-users tab. (You can define the user name and password by yourself, here the user name is tomcat, and the password is admin).

[root@localhost bin]# vi /usr/local/tomcat/apache-tomcat-8.5.82/conf/tomcat-users.xml
 <role rolename="manager-gui"/>   <user username="tomcat"
 password="s3cret" roles="manager-gui"/>

2.6.2 Specify the permissions of manager-gui. Open the context.xml file in the /webapps/manager/META-INF/ directory, and modify the allow attribute of the Value tag in it to the following:

[root@localhost apache-tomcat-8.5.82]# cd webapps/manager/META-INF/context.xml
<Valve className="org.apache.catalina.valves.RemoteAddrValve" 
 allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|\d+\.\d+\.\d+\.\d+" />

2.6.3 After the modification is completed, enter the bin directory and restart tomcat.

[root@localhost bin]# ./shutdown.sh
[root@localhost bin]# ./startup.sh

Enter the user name and password to log in to the tomcat management page.

insert image description here

Guess you like

Origin blog.csdn.net/qq_52716296/article/details/127074047