概述

Tomcat官网:https://tomcat.apache.org/

安装环境
部署ip部署软件开放端口
192.168.199.10jdk1.8/tomcat-8.5.618080

安装部署

依赖环境安装
tar zxf jdk-8u271-linux-x64.tar.gz
mv jdk1.8.0_271/ /data/
vi  /etc/profile
#根据实际情况修改JAVA_HOME
export JAVA_HOME=/data/jdk1.8.0_271
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

source /etc/profile
#测试
java -version
Tomcat安装
wget https://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.61/bin/apache-tomcat-8.5.61.tar.gz
tar -zxf tar zxf apache-tomcat-8.5.61.tar.gz
mv apache-tomcat-8.5.61 /data/tomcat-8.5.61
基础配置
vim bin/catalina.sh
#在第一行添加,-Xmx Java Heap最大值,默认值为物理内存的1/4;-Xmx和-Xms值相同,实际建议不大于4GB
JAVA_OPTS="-Xmx500m -XX:MetaspaceSize=500m -XX:MaxMetaspaceSize=768m -Xss2m"
CATALINA_OPTS="-Djava.awt.headless=true"
vim conf/server.xml
#在</Host>前插入,可以修改网站根目录:
<Context path="" docBase="/data/tomcat-8.5.61/webapps/" debug="0"/>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传img−BDoNKMYv−1610702503778Double subscripts: use braces to clarifyDouble subscripts: use braces to clarify]

配置启动脚本
# 在tomcat的bin目录下新建setenv.sh
vim /data/tomcat-8.5.61/bin/setenv.sh

CATALINA_PID="$CATALINA_BASE/tomcat.pid"

vim /usr/lib/systemd/system/tomcat.service

[Unit]
Description=tomcat service
After=tomcat.service
[Service]
Type=forking
User=root
Group=root
# 此处是tomcat安装路径
PIDFile=/data/tomcat-8.5.61/tomcat.pid
ExecStart=/data/tomcat-8.5.61/bin/startup.sh
ExecStop=/data/tomcat-8.5.61/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
开机自启设置
# 加入开机启动
systemctl daemon-reload
systemctl enable tomcat
# 查看开机是否启动成功
systemctl is-enabled tomcat
# 启动服务
systemctl start tomcat
# 停止服务
systemctl stop tomcat
防火墙开放端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
setenforce 0

分类: Linux