1.关闭防火墙和selinux
setenforce 0
systemctl stop firewalld
2.下载jdk和Tomcat
cd /opt
wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.90/bin/apache-tomcat-8.5.90.tar.gz
wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.tar.gz
3.解压
tar -zxvf apache-tomcat-8.5.90.tar.gz
tar -zxvf jdk-21_linux-x64_bin.tar.gz
4.jdk编辑配置文件
cd jdk-21.0.2/
vim /etc/profile
unset -f pathmunge之后添加:
exportJAVA_HOME=/opt/jdk-21.0.2
export PATH=$JAVA_HOME/bin:$PATH
source /etc/profile(提示有问题不用管,直接进行下一步)
java(提示有问题不用管,直接进行下一步)
5.运行Tomcat脚本
cd ..
cd apache-tomcat-8.5.90/
cd bin/
./startup.sh 注意:这里手打不要复制
6.访问
192.168.233.132:8080
7.启动服务
没有tomcat.service时要新建
vi /etc/systemd/system/tomcat.service
添加以下内容:
[Unit]
Description=Tomcat
After=network.target
[Service]
Type=forking
ExecStart=/opt/apache-tomcat-8.5.90/bin/startup.sh
ExecStop=/opt/apache-tomcat-8.5.90/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重启生效:
systemctl daemon-reload
systemctl start tomcat
8.添加访问权限
1).允许manager app访问
vi /opt/apache-tomcat-8.5.90/webapps/manager/META-INF/context.xml
定位22行的allow字段进行修改:
改为:allow=”192\.168\.\d+\.\d+”
2).允许host-manager访问
vi /opt/apache-tomcat-8.5.90/webapps/host-manager/META-INF/context.xml
改为:allow=”192\.168\.\d+\.\d+”
3.systemctl restart tomcat
9.添加用户和角色信息
重启生效:
systemctl start tomcat