1. 下载Tomcat
mkdir /usr/local/software
wget -O /usr/local/software/tomcat.tar.gz http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.12/bin/apache-tomcat-9.0.12.tar.gz
tar -zxvf /usr/local/software/tomcat.tar.gz -C /usr/local
mv /usr/local/apache-tomcat-* /usr/local/tomcat
2. 配置Tomcat
#vim /usr/local/tomcat/bin/setenv.sh
vim /etc/profile
CATALINA_HOME=/usr/local/tomcat
CATALINA_BASE=/usr/local/tomcat
PATH=$PATH:$CATALINA_BASE/bin
export PATH CATALINA_HOME CATALINA_BASE
source /etc/profile
firewall-cmd --zone=public --add-port=8080/tcp –permanent
firewall-cmd –reload
配置访问TOMCAT管理界面
vim /usr/local/tomcat/conf/tomcat-users.xml
<role rolename="manager"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<role rolename="manager-script" />
<user username="admin" password="937827" roles="manager-gui,manager-script" />
</tomcat-users>
vim /usr/local/tomcat/webapps/manager/META-INF/context.xml
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|\d+\.\d+\.\d+\.\d+" />
配置SYSTEMD管理TOMCAT服务
vim /usr/local/tomcat/bin/catalina.sh
JAVA_HOME=/usr/local/jdk
CATALINA_BASE=/usr/local/tomcat
echo "/usr/local/tomcat/bin/catalina.sh start" >> /etc/rc.local
chmod +x /etc/rc.local
vim /usr/local/tomcat/bin/setenv.sh
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"
chmod 777 /usr/local/tomcat/bin/setenv.sh
vim /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Tomcat8
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/tomcat/tomcat.pid
ExecStart=/usr/local/tomcat/bin/daemon.sh start
ExecStop=/bin/kill -s QUIT $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl enable tomcat
systemctl start tomcat
systemctl stop tomcat
systemctl restart tomcat
systemctl daemon-reload