================================
©Copyright Sweet Potato Yao 2022-01-06
Sweet Potato Yao's Blog - CSDN Blog
1. Download tomcat9 and upload it to the server
download link:
官网下载地址:
https://tomcat.apache.org/download-90.cgi
官网tomcat9直接下载地址:
https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.56/bin/apache-tomcat-9.0.56.tar.gz
Upload the compressed package of tomcat (apache-tomcat-9.0.56.tar.gz) to the service folder, such as: /java
Second, tomcat9 installation configuration, boot up
1. Unzip the file
cd /java
tar -zxvf apache-tomcat-9.0.56.tar.gz
2. Rename the folder
The revision is shorter, and the update is easy to remember.
mv apache-tomcat-9.0.56 tomcat9
3. Modify the server.xml file and modify the tomcat port
cd /java/tomcat9/conf/
vi /java/tomcat9/conf/server.xml
Change the port from the default 8080 port to 9000: port="9000"
<Connector port="9000" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
4. Modify the context.xml file of tomcat to increase the cache size
Do not modify this configuration, because the cache is too small, the file cannot be loaded normally, and an error may be reported at startup
cd /java/tomcat9/conf
vi context.xml
The additions are as follows:
<Resources cacheMaxSize="512000" cachingAllowed="true"/>
details as follows:
<Context>
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<Resources cacheMaxSize="512000" cachingAllowed="true"/>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
</Context>
5. Centos open tomcat port
Open ports, such as: 9000:
sudo firewall-cmd --zone=public --add-port=9000/tcp --permanent
A common user is used, and sudo is added in front. If it is a root user, it is not required
Make the port valid:
sudo firewall-cmd --reload
View all open ports on the firewall
sudo firewall-cmd --zone=public --list-ports
6. Centos configures Tomcat's environment variables
Edit /etc/profile to use Tomcat commands anywhere
sudo vi /etc/profile
Add Tomcat variable configuration
CATALINA_HOME=/java/tomcat9
CATALINA_BASE=/java/tomcat9
PATH=$PATH:$CATALINA_BASE/bin
export CATALINA_HOME CATALINA_BASE PATH
Recompile to make the configuration take effect
source /etc/profile
7. Modify the jvm running by tomcat
setenv.sh is not available by default, just add it directly
vi /java/tomcat9/bin/setenv.sh
Added content:
#add tomcat pid
CATALINA_PID="$CATALINA_BASE/tomcat-9000.pid"
#add java opts
JAVA_OPTS="-server -XX:PermSize=1024m -XX:MaxPermSize=1024m -Xms512m -Xmx512m -XX:MaxNewSize=256m"
Add permissions to ensure the file setenv.sh is executable
chmod +x /java/tomcat9/bin/setenv.sh
8. Modify tomcat's setclasspath.sh and configure the Java path
Add the following configuration to the header of setclasspath.sh, otherwise an error will be reported (Neither the JAVA_HOME nor the JRE_HOME environment variable is defined):
vi /java/tomcat9/bin/setclasspath.sh
Add below the sentence Set JAVA_HOME or JRE_HOME, the added content:
# -----------------------------------------------------------------------------
# Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings
# are valid and consistent with the selected start-up options and set up the
# endorsed directory.
# -----------------------------------------------------------------------------
export JAVA_HOME=/java/jdk1.8
export JRE_HOME=/java/jdk1.8/jre
Third, tomcat starts and runs
1. Start tomcat
cd /java/tomcat9/bin
./startup.sh
2. Close the Tomcat service
./shutdown.sh
3, tomcat starts, tomcat starts automatically
Add tomat service startup file: tomcat.9000.service
cd /usr/lib/systemd/system
sudo vi /usr/lib/systemd/system/tomcat.9000.service
tomcat.9000.service file content:
[Unit]
Description=Tomcat-9000
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=oneshot
ExecStart=/java/tomcat9/bin/startup.sh
ExecStop=/java/tomcat9/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
The root user starts the tomcat startup service:
systemctl enable tomcat.9000.service
The root user starts the Tomcat service:
systemctl start tomcat.9000.service
The root user checks the service status:
systemctl status tomcat.9000.service
Other commands:
root用户关闭tomcat开机自启:
systemctl disable tomcat.9000.service
root用户停止服务:
systemctl stop tomcat.9000.service
root用户重启服务:
systemctl restart tomcat.9000.service
4. Restart the Centos server
Restart the Centos server and verify that tomcat is started
reboot -f
Fourth, some commands of the firewall
查看防火墙状态:
firewall-cmd --state
关闭防火墙
systemctl stop firewalld.service
禁止防火墙开机启动
systemctl disable firewalld.service
(Time is precious, sharing is not easy, donate and give back, ^_^)
================================
©Copyright Sweet Potato Yao 2022-01-06
Sweet Potato Yao's Blog - CSDN Blog