Linux下搭建springboot服务(不借助tomcat启动)

1.新建一个.service文件(我这边命名为test.service,其中test为服务名)

内容如下

[Unit]
Description=test
After=syslog.target

[Service]
ExecStart=/home/java/jdk/jdk1.8.0_144/bin/java -jar /root/project/test.jar --server.port=9185
SuccessExitStatus=143
Restart=on-failure

[Install]
WantedBy=multi-user.target

注意:/home/java/jdk/jdk1.8.0_144/bin/ 为Linux的java安装路径,可通过whereis java指令查看

2.进入 /etc/systemd/system/    目录

将上面新建的test.service文件放在该目录下

3.将打包好的test.jar包放在test.service文件中配置的/root/project/ 路径下,路径可定义指定

4.上述操作完成后进入/root/project/ 目录下执行  systemctl restart test  指令重启该springboot服务

大功告成

然后就可以浏览器访问springboot项目了,告别传统tomcat部署项目

 注意一个小点,如果service文件有修改 需要使用 systemctl daemon-reload    指令 加载一下,告诉systemd系统。

5.systemctl start springboot-test
或systemctl start springboot-test.service
//设置开机自启
systemctl status springboot-test
或systemctl status springboot-test.service
//设置开机自启
systemctl enable springboot-test
或systemctl enable springboot-test.service
//查看日志
journalctl -u springboot-test
或 journalctl -u tespringboot-test.service
 

猜你喜欢

转载自blog.csdn.net/qq_34701945/article/details/91798649