- 需求背景
Linux重启后要手动执行"startup.sh"启动Tomcat,比较麻烦,想要Linux开机启动Tomcat。
- 开机启动
#---------------------------------------------------------- sudo tee /usr/bin/tomcat.sh <<-'EOF' #! /bin/bash nohup /opt/tomcat/bin/startup.sh > /opt/tomcat/nohup.log & EOF chmod +x /usr/bin/tomcat.sh #---------------------------------------------------------- sudo tee /etc/systemd/system/tomcat.service <<-'EOF' [Unit] Description=tomcat After=syslog.target network.target [Service] Environment="JAVA_HOME=/opt/jdk" Type=oneshot RemainAfterExit=yes ExecStart=/usr/bin/tomcat.sh [Install] WantedBy=multi-user.target EOF #---------------------------------------------------------- systemctl enable tomcat #----------------------------------------------------------
# 启动tomcat systemctl start tomcat # 停止tomcat systemctl stop tomcat # 重启tomcat systemctl restart tomcat # 查看tomcat状态 systemctl status tomcat
- 注意事项
#---------------------------------------------------------- "tomcat.service"不添加Environment="JAVA_HOME=/opt/jdk"报错如下 #---------------------------------------------------------- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program #---------------------------------------------------------- 解决方法:"startup.sh"首行添加"export JAVA_HOME=/opt/jdk"可解决 #----------------------------------------------------------
Linux开机启动Tomcat
最新推荐文章于 2024-06-17 19:37:01 发布