tomcat tutorial for Linux Installation and error points during installation

Check to see if it has been installed

First, check whether Tomcat is installed, started, file path and process PID under Linux

1. Detect if Tomcat is installed:

rpm -qa|grep tomcat

2. View Tomcat's process ID:

ps -ef|grep tomcat

3. View Tomcat Directory:

find / -name tomcat

install

Download website: https://tomcat.apache.org/download-80.cgi

[the external link image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-bQAXi0ES-1613534223711)(/Users/hidisan/Desktop / Notes / summary / tomcat installation. assets/image-20210217115615532.png)]

Transfer to Linux

/Create a tomcat clip under usr/local / and enter it

cd /usr/local/

mkdir tomcat

cd tomcat

2. Unzip the Tomcat installation package into / usr/local/tomcat

[root@localhost tomcat]# tar -zxvf /root/apache-tomcat-8.5.55.tar.gz 

After decompression, / usr/local/tomcat (record will appear in apache-tomcat-8.5.55)

Start TOMCAT

Directly enter apache-tomcat-8.5.55 and execute the startup script recorded by bin

[root@localhost apache-tomcat-8.5.55]# cd bin/

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

[the external link image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-IEHw5Gi8-1613534223712)(/Users/hidisan/Desktop / Notes / summary / tomcat installation. assets/image-20210217105413809.png)]

You can visit it at this time

IP:8080

If your Tomcat starts successfully, but you can't access the interface, here's the solution

It is possible that your firewall does not open port 8080, or port 8080 is occupied

Here are the solutions:

Firewalls and ports

firewall

Check the firewall status. If it is dead, the firewall is not turned on

systemctl status firewalld		 			#View firewall status
firewall-cmd --list-ports					#View firewall open ports
systemctl start firewalld.service			#Open firewall
systemctl stop firewalld.service			#Turn off firewall
systemctl restart firewalld.service		#Restart firewal l
systemctl disable firewalld.service			#Disable firewall startup  
systemctl enable firewalld.service		#Set startup and self startup
systemctl is-enabled firewalld.service;echo $?	#Check whether the firewall is set to start automatically

#Close port command:
firewall-cmd --zone= public --remove-port=80/tcp --permanent

#Check whether the port is open
firewall-cmd --zone= public --query-port=80/tcp

#To open the firewall port, restart the firewall to take effect
#Open a single port
firewall-cmd --zone=public --add-port=80/tcp --permanent

#Open multiple ports
firewall-cmd --zone=public --add-port=20000-29999/tcp --permanent

Command meaning:
–zone #Scope
–add-port=80/tcp #Add a port in the format of port / communication protocol
–permanent #It will take effect permanently. It will become invalid after restart without this parameter

Turn off the firewall

systemctl stop firewalld.service

Turn on or restart the firewall

systemctl start firewalld.service
systemctl restart firewalld.service

But it's best not to close the firewall, it's not safe!!!

Check the port occupancy first:

#View port commands
lsof -i:Port number

#View all current tcp ports
netstat -ntlp   
# Used to view the process of the specified port number
netstat -tunlp |grep 8080

#Kill port command
(sudo) kill -9 PID

Open 8080 port separately

firewall-cmd --permanent --zone=public --add-port=8080/tcp

firewall-cmd --reload

firewall-cmd --zone=public --query-port=8080/tcp

Port number

1: Enter the linux system. Then enter the tomcat/conf / folder

2: vi server.xml edit xml file.

3: Press the i key to start editing: find and modify the port to the port number you want.

4: Save exit: wq

5: Restart Tomcat/ shutdown. sh ./ startup. sh

 <Connector port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="8443" />

At this time, the Tomcat page can be accessed, but the Manager interface is 403. Let's continue~

Unable to enter the manager management page

1,conf/tomcat-users.xml add the following

<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/>
<role rolename="manager-script"/>
<role rolename="manager-status"/>
<user username="root" password="root" roles="admin-gui,manager-gui,manager-jmx, manager-script,manager-status"/>
123456

2. Modify webapps / Manager / meta-inf / context XML replace with the following

<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"     allow="^.*$" />
</Context>

3. Restart Tomcat

The login password and account are set in the first step: root and root

Tags: Linux Spring CentOS Tomcat

Posted by Imtehbegginer on Mon, 18 Apr 2022 19:06:37 +0930