普通用户启动tomcat
避免直接使用root用户启动服务
创建普通用户
禁止该用户登入
useradd -M -r -d /dev/null -s /sbin/nologin tomcat
安装tomcat及jdk
jDK版本推荐8,不建议过高
wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.87/bin/apache-tomcat-8.5.87.tar.gz
wget https://download.oracle.com/java/19/latest/jdk-19_linux-x64_bin.tar.gz
解压
tar xf apache-tomcat-8.5.87.tar.gz -C /opt/
tar xf jdk-19_linux-x64_bin.tar.gz -C /usr/local/
JDK 设置环境变量
vim /etc/profile
JAVA_HOME=/usr/local/java
PATH=${JAVA_HOME}/bin:$PATH
刷新环境变量
source /etc/profile
Tomcat 设置systemd管理
vim /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Tomcat.Service
After=network.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/jdk-19.0.2"
User=tomcat
PIDFile=/opt/apache-tomcat-8.5.87/bin/tomcat.pid
ExecStart=/opt/apache-tomcat-8.5.87/bin/startup.sh
#ExecReload=/usr/local/tomcat/bin/catalina.sh restart
#ExecStop=/usr/local/tomcat/bin/catalina.sh stop
ExecStop=/opt/apache-tomcat-8.5.87/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start tomcat
systemctl status tomcat