创建systemd服务文件:
sudo nano /etc/systemd/system/tomcat.service
添加以下内容:
[Unit]Description=Apache Tomcat 9After=network.target[Service]Type=forkingUser=rootEnvironment="CATALINA_HOME=/opt/tomcat"ExecStart=/opt/tomcat/bin/startup.shExecStop=/opt/tomcat/bin/shutdown.sh[Install]WantedBy=multi-user.target
启动并设置开机自启:
sudo systemctl daemon-reloadsudo systemctl start tomcatsudo systemctl enable tomcat