方法一:
1. 添加文件
vi /etc/systemd/system/tomcat.service
添加内容
[unit] description=tomcat8 after=syslog.target network.target remote-fs.target nss-lookup.target [service] type=oneshot execstart=/usr/local/apache-tomcat-8.5.40/bin/startup.sh execstop=/usr/local/apache-tomcat-8.5.40/bin/shutdown.sh execreload=/bin/kill -s hup $mainpid remainafterexit=yes [install] wantedby=multi-user.target
2. 进入目录
cd /etc/systemd/system/
3. 设置开机启动
systemctl enable tomcat.service
4. 查看当前tomcat状态
systemctl status tomcat.service
5. 关闭开机自启动
systemctl disable tomcat.service
6. tomcat添加jdk路径,否则自启动会报错 neither the java_home nor the jre_home environment variable is defined
vi /usr/local/apache-tomcat-8.5.40/bin/catalina.sh export java_home=/usr/local/jdk8 export jre_home=/usr/local/jdk8/jre
方法二:
1. 编辑启动脚本: vim /usr/local/auto_run.sh
/usr/local/apache-tomcat-8.5.40/bin/startup.sh
2. 添加 crontab 任务
crontab -e
@reboot /usr/local/auto_run.sh
保存即可
重启服务器,测试
reboot
到此这篇关于linux设置tomcat开机启动的两种方式的文章就介绍到这了,更多相关tomcat开机启动内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论