美文网首页
spring boot 发布到centos7服务器

spring boot 发布到centos7服务器

作者: 碧波之心 | 来源:发表于2017-03-28 11:22 被阅读364次

一、服务打包

为了创建可执行的jar,需要将spring-boot-maven-plugin添加到我们的pom.xml中。在dependencies节点下插入以下内容:
<build>
   <plugins>
       <plugin>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-maven-plugin</artifactId>
       </plugin>
   </plugins>
</build>
假设打包后的文件为:demo.jar

二、服务器上部署

  1. 上传demo.jar到服务器,如:上传到/home/demo/demo.jar
  2. 设置权限:
    chmod 500 demo.jar
  3. 编辑服务文件:demo.service,并把文件上传到/etc/systemd/system/目录中
[Unit]
Description=eber
After=syslog.target
[Service]
User=root
ExecStart=/home/demo/demo.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
  1. 设置服务开机自动启动
    systemctl enable demo.service
  2. 查看服务运行状态
    systemctl status demo -l
  3. 重启服务
    systemctl restart demo
  4. 如果修改了.service文件需要执行如下命令
    systemctl daemon-reload

相关文章

网友评论

      本文标题:spring boot 发布到centos7服务器

      本文链接:https://www.haomeiwen.com/subject/dbqjottx.html