如何将springboot注册到linux服务

原文地址:点我

一、使用maven构建springboot项目

pom文件:

xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <groupId>cn.itxslgroupId>
    <artifactId>springbootartifactId>
    <version>1.0-SNAPSHOTversion>

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.0.5.RELEASEversion>
    parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
    build>
project>

启动类:

package cn.itxsl;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @Author itxsl
 * @Description
 * @Date 2018/10/8 11:03
 */
@SpringBootApplication
public class Start {

    public static void main(String[] args) {
        SpringApplication.run(Start.class, args);
    }

}

 

打包该项目:

二、将springboot项目注册到linux服务

将打包后的文件上传到linux服务器中:

创建springboot.service文件:

vim /etc/systemd/system/springboot.service

文件内容如下:

[Unit]
Description=springboot service
After=syslog.target

[Service]
Type=simple
ExecStart= /root/app/jdk1.8.0_181/bin/java -jar /root/springboot/springboot-1.0-SNAPSHOT.jar

[Install]
WantedBy=multi-user.target

 

刷新服务配置文件:

systemctl daemon-reload

启动服务:

systemctl start springboot.service

停止服务:

systemctl stop springboot.service

查看服务状态:

systemctl status  springboot.service

查看日志:

journalctl -u springboot.service

你可能感兴趣的:(如何将springboot注册到linux服务)