springboot2 linux上jar部署

一、把项目打成jar包
mvn clean package -DskipTests

二、上传Jar包到服务器
小的文件上传可以用 rz小工具 大的最好用 FTP工具上传(winscp xftp)
在这里插入图片描述

三、上传配置文件以及优雅启动脚本
Application.yml

server:
  port: 8080
......

优雅启动脚本.sh

#!/bin/bash

SpringBoot=$2

if [ "$1" = "" ];
then
    echo -e "\033[0;31m 未输入操作名 \033[0m  \033[0;34m {start|stop|restart|status} \033[0m"
    exit 1
fi

if [ "$SpringBoot" = "" ];
then
    echo -e "\033[0;31m 未输入应用名 \033[0m"
    exit 1
fi

function start()
{
	count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
	if [ $count != 0 ];then
		echo "$SpringBoot is running..."
	else
		echo "Start $SpringBoot success..."
		nohup java -jar -Dspring.config.location=/home/j/share/config/Application.yml  $SpringBoot > nohup.log 2>&1 &
	fi
}

function stop()
{
	echo "Stop $SpringBoot"
	boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
	count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`

	if [ $count != 0 ];then
	    kill $boot_id
    	count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`

		boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
		kill -9 $boot_id
	fi
}

function restart()
{
	stop
	sleep 2
	start
}

function status()
{
    count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
    if [ $count != 0 ];then
        echo "$SpringBoot is running..."
    else
        echo "$SpringBoot is not running..."
    fi
}

case $1 in
	start)
	start;;
	stop)
	stop;;
	restart)
	restart;;
	status)
	status;;
	*)
esac

四、优雅启动脚本修改
修改成自己yml文件路径
在这里插入图片描述
四、优雅启动脚本启动项目
./启动脚本.sh 操作({start|stop|restart|status}) jar包位置
e.g: run.sh start xxx.jar

五、检查项目是否启动
ps -ef | grep 项目名称
在这里插入图片描述

六、打开浏览器访问
https://www.jlshare.top/ 这个是我自己的网站
在这里插入图片描述


分享一个原先我自己在部署时候遇到的一个问题,我记录在我的简书里面
springboot2 linux上jar部署 @value Could not resolve placeholder的问题
https://www.jianshu.com/p/7d9625cacae6

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值