- 需求背景
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"可解决 #----------------------------------------------------------
文章来源地址https://www.toymoban.com/news/detail-685552.html
文章来源:https://www.toymoban.com/news/detail-685552.html
到了这里,关于Linux开机启动Tomcat的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!