Installation of Tomcat 7 in Linux CentOS 7 and solutions to problems encountered

linux The column contains this content
33 articles 0 subscription

preface: I recently bought an alicloud server to install Tomcat as a web container. Previously, installing Tomcat was so easy, but this installation encountered many pitfalls. To sum up again, avoid the same mistakes in the future.

1、 Install Tomcat

1 download Tomcat

Download addressTomcat7 installation package download address

Official download addressTomcat7 official download address
Write a picture description here

*Before installing tomcat, we need to install JDK
Tutorial documentation:Installing jdk1.7 in Linux CentOS 7

2. Install Tomcat

After installing the JDK, download the Tomcat installation package at the same time, and use the FTP function to put the installation package into the specified directory, for example: / usr / local

(1) Enter directory

cd/usr/local

(2) Create directory

mkdirtomcat

(3) View directory

Ll orls

(4) Unzip the Tomcat installation package

tar -zxvf apache-tomcat-seven.68.tar.gz

(5) Remove the Tomcat installation package (if required)

rm -rf apache-tomcat-seven.68.tar.gz

(6) Modify the file name (the unzipped file name is too long, so you can consider modifying it short)

mv  apache-tomcat-seven.68tomcat7

(7) Enter the Tomcat directory (according to your own installation directory)

cd/usr/local/tomcat/tomcat7

Write a picture description here

3. Execute Tomcat

(1) Enter the Tomcat execution directory

cd/usr/local/tomcat/tomcat7/bin

(2) View the running status of Tomcat

ps -ef |grep tomcat

(3) Start Tomcat

./startup.sh

Write a picture description here
Execute Tomcat started, and Tomcat is executed successfully

(4) Close Tomcat

./shutdown.sh

Write a picture description here

(5) Access server IP address
Write a picture description here

2、 Solve problems encountered in Tomcat execution

1 server firewall interception

Problem description: when Tomcat is started successfully, it accesses the web server and the request fails. One of the reasons for the failure may be that the firewall intercepts port 8080 or other ports. We need to reopen port 8080 or other ports. It is not recommended to close the firewall.

Iptables firewall settings reference article addressCentOS - installing iptables firewall in centos7

(1) View firewall status

service iptables status

(2) Add 8080 port to allow Internet access

/sbin/iptables -IINPUT -ptcp --dport eight thousand and eighty -jACCEPT

(3) Save rule settings

service iptables save

(4) Restart firewall

service iptables restart

2. Starting Tomcat is very slow

Problem description: starting Tomcat will take several minutes or even more than ten minutes, which means that the startup of Tomcat is stuck by some mechanism. Later, according to the data, it is stuck when generating the secret key through random numbers, resulting in slow or failed startup of Tomcat. In tomcat8, Tomcat's session ID is calculated by SHA1 algorithm. There must be a secret key when calculating the session ID. in order to improve security, Tomcat generates a secret key by random number when starting. But my version is Tomcat 7.0.68, which also encountered similar problems. The solution is to increase the entropy pool (what affects the strength of random numbers is the entropy used for generation).

(1) Solution 1: use rngd software to increase entropy pool (recommended)

CPU support required (optional)

greprdrand /proc/cpuinfo

Install rngd service (entropy service, increase entropy pool)

yum installrng-tools

Start service

systemctl startrngd

(2) Modifying configuration file in Java environment

vim $JAVA_ HOME/jre/lib/security/java.security 
securerandom.source=file:/dev/random
Change to
securerandom.source=file:/dev/urandom

Write a picture description here

(3) Non blocking entropy source (not verified) can be used by configuring JRE

vim $TOMCAT_ HOME/bin/catalina.sh 
if [[ "$JAVA_ OPTS" !=*- Djava.security.egd=* ]]; then
JAVA_ OPTS="$JAVA_ OPTS -Djava.security.egd=file:/dev/urandom"
fi

The system attribute EGD represents the entropy gathering daemon

Summary:
Tomcat starts slowly. Maybe we won't notice it at first. When we test, it is normal to open Tomcat. An error occurs when we close tomcat, indicating that the process is not closed (8005 process by default). We usually kill the process with the kill - 9 process number. If the problem of Tomcat closing exception often occurs, it may be caused by our slow startup of Tomcat.

3. The Tomcat firewall and are started normally and cannot access Tomcat

Problem description: This is the biggest pit I encountered. The firewall is normal and Tomcat starts normally, but it has been inaccessible. Because I use an alicloud server, I set up a security group, resulting in my port being blocked from the alicloud server. Here, you need to reset your security group rules. Reset the security group and open 8080 or other ports for normal access.

Alicloud add security group rule documentAdd security group rule

Reference articles

Optimization method of slow startup speed of Tomcat
How to open port 8080 for external access and port 8000 for external access in Linux
CentOS - installing iptables firewall in centos7
The startup process of centos7 Tomcat is very slow

emoticon
Insert expression
Relevant recommendations More similar content
©️ 2020 CSDN Skin theme: programming studio Designer: CSDN official blog Return to home page
Paid inelement
Payment with balance
Click retrieve
Code scanning payment
Wallet balance 0

Deduction Description:

1. The balance is the virtual currency of wallet recharge, and the payment amount is deducted according to the ratio of 1:1.
2. The balance cannot be purchased and downloaded directly. You can buy VIP, c-coin package, paid column and courses.

Balance recharge