1. Springboot project Maven configuration

<groupId>com.zxl</groupId>
<artifactId>myblog</artifactId>
<version>0.01.-SNAPSHOT</version>
<packaging>jar</packaging>
Copy the code

Packaging is packaged in jar packages

2. Use Maven to package Springboot projects. You can use commands or mouse clicks to operate as shown in the picture3. Double-click the package (there are some clean,compile and other operations on the Internet, I don’t have such complicated operations here, just double-click the package directly)

4. Look at the console outputMyblog. jar = myblog.jar = myblog.jar = jar = myblog.jar = jar = jar = jar = jar = jar = jar = jar = jar = jar = jar = jar = jar = jar = jar = jar = jar = jar = jar = jar5. Upload the generated JAR package to the Linux server (I put it in the developer folder)6. Create a myblog.service file using an automated script

[Unit] Description=myblog After=syslog.target [Service] ExecStart= /usr/bin/java -jar/developer/myblog.jar [Install] WantedBy=multi-user.targetCopy the code

7. Create the myblog.sh file

#! /bin/bash cd `dirname $0'CUR_SHELL_DIR=' PWD 'CUR_SHELL_NAME=' basename ${BASH_SOURCE} '#"myblog.jar" 
JAR_PATH=$CUR_SHELL_DIR/$JAR_NAME
#JAVA_MEM_OPTS=" -server -Xms1024m -Xmx1024m -XX:PermSize=128m"
JAVA_MEM_OPTS=""
#SPRING_PROFILES_ACTIV="-Dspring.profiles.active=eureka2"
SPRING_PROFILES_ACTIV=""
LOG_DIR=$CUR_SHELL_DIR/logs
LOG_PATH=$LOG_DIR/${JAR_NAME}.log
echo_help(a)
{
    echo -e "syntax: sh $CUR_SHELL_NAME start|stop"
}
if [ -z $1]; then echo_help exit1
fi
if [ ! -d "$LOG_DIR"]; then mkdir"$LOG_DIR"
fi
if [ ! -f "$LOG_PATH"]; then touch"$LOG_DIR"
fi
if [ "$1"= ="start"]; then # check server PIDS=`ps --no-heading -C java -f --width1000 | grep $JAR_NAME | awk '{print $2}'`
    if [ -n "$PIDS" ]; then
        echo -e "ERROR: The $JAR_NAME already started and the PID is ${PIDS}."
        exit 1
    fi
echo "Starting the $JAR_NAME..."
 
    # start
    nohup java $JAVA_MEM_OPTS -jar $SPRING_PROFILES_ACTIV $JAR_PATH >> $LOG_PATH 2> &1 &
 
    COUNT=0
    while [ $COUNT -lt 1 ]; do
        sleep 1
        COUNT=`ps  --no-heading -C java -f --width 1000 | grep "$JAR_NAME" | awk '{print $2}' | wc -l`
        if [ $COUNT -gt 0 ]; then
            break
        fi
    done
    PIDS=`ps  --no-heading -C java -f --width 1000 | grep "$JAR_NAME" | awk '{print $2}'`
    echo "${JAR_NAME} Started and the PID is ${PIDS}."
    echo "You can check the log file in ${LOG_PATH} for details."
 
elif [ "$1"= ="stop"]; then PIDS=`ps --no-heading -C java -f --width1000 | grep $JAR_NAME | awk '{print $2}'`
    if [ -z "$PIDS" ]; then
        echo "ERROR:The $JAR_NAME does not started!"
        exit 1
    fi
echo -e "Stopping the $JAR_NAME..."
 
    for PID in $PIDS; do
        kill $PID > /dev/null 2> &1
    done
 
    COUNT=0
    while [ $COUNT -lt 1 ]; do
        sleep 1
        COUNT=1
        for PID in $PIDS ; do
            PID_EXIST=`ps --no-heading -p $PID`
            if [ -n "$PID_EXIST" ]; then
                COUNT=0
                break
            fi
        done
    done
 
    echo -e "${JAR_NAME} Stopped and the PID is ${PIDS}."
else
    echo_help
    exit 1
fi

Copy the code

Open your browser and type in your web address (IP if you don’t have a domain name)

If no, the firewall port is not configured with server iptables and port 80 is enabled

iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save
Copy the code

To stop the operation, run the./myblog.sh stop command