centos7安装tomcat10

centos7安装tomcat10

tomcat 10 特性

tomcat10.0.x版本实现了Servlet 5.0, JSP 3.0, EL 4.0, WebSocket 2.0Authentication 2.0

安装步骤

关闭selinux

setenforce 0
sed -i 's/ELINUX=enforcing/ELINUX=disabled/g' /etc/selinux/config

tomcat10后,只支持安装openjdk11及以上版本

yum install java-11-openjdk-devel

安装完成后,查看java版本

[root@localhost ~]# java --version
openjdk 11.0.12 2021-07-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7-LTS, mixed mode, sharing)

假如是其他版本,则需要使用下面的命令切换版本

alternatives --config java

新建tomcat用户

useradd -d /opt/tomcat -s /bin/nologin tomcat

下载tomcat10包

yum install -y wget
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.0.10/bin/apache-tomcat-10.0.10.tar.gz
tar zxf apache-tomcat-10.0.10.tar.gz
cd apache-tomcat-10.0.10
cp -r * /opt/tomcat

赋予tomcat权限

chown -R tomcat:tomcat /opt/tomcat/

添加systemd服务,配置服务需要修改JAVA_HOME变量,可以通过alternatives --list | grep ^java查看

vi /etc/systemd/system/tomcat.service

Unit]
Description=Apache Tomcat Web Application Container
Wants=network.target
After=network.target

[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.12.0.7-0.el7_9.x86_64
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1G -Djava.net.preferIPv4Stack=true'
Environment='JAVA_OPTS=-Djava.awt.headless=true'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
SuccessExitStatus=143
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

启用服务

systemctl start tomcat
systemctl enable tomcat

开启防火墙

firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload

配置tomcat admin-gui和manager-gui的认证

vi /usr/share/tomcat/conf/tomcat-users.xml
......
  <role rolename="admin-gui"/>
  <role rolename="manager-gui"/>
  <user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>
</tomcat-users>
上一篇:powershell命令仅输出目录列表


下一篇:Guice框架-DI(依赖注入属性注入)