centOS7 tomcat 开机自启 自启动设置

时间:2021-10-18 15:38:17

1、编写配置文件

 1 // (1)修改tomcat.service
 2 vim /lib/systemd/system/tomcat.service
 3 
 4 // (2)复制以下代码,注意修改tomcat路径
 5 [Unit]
 6 Description=tomcat
 7 After=network.target
 8 
 9 [Service]
10 Type=oneshot
11 ExecStart=/usr/local/tomcat/apache-tomcat-9.0.16/bin/startup.sh   //自已的tomcat目录
12 ExecStop=/usr/local/tomcat/apache-tomcat-9.0.16/bin/shutdown.sh
13 ExecReload=/bin/kill -s HUP $MAINPID
14 RemainAfterExit=yes
15 
16 [Install]
17 WantedBy=multi-user.target

2、启动服务

1 systemctl start tomcat.service

3、查看服务状态

1 systemctl status tomcat.service

4、设置开机启动

1 systemctl enable tomcat.service

5、重启测试

1 reboot

 

引用地址:https://blog.csdn.net/JEYMING/article/details/83308068