[springboot]微服务部署结构路径最佳实践
springboot 已经火了很多年了,现在又有很多应用使用springcloud进行开发。随着容器化技术的发展,单体的应用直接部署更是越来越少。
但是有些场景下,使用springboot 构建单体应用,直接部署也是非常方便的一种形式,特此记录。
### springboot jar包非容器化部署实践
!(data/attachment/forum/202207/08/174714yg1ccgo70a2aacix.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "image.png")
注意:
* 如果配置文件简单不复杂,可以考虑省略resources ,直接使用jar内部配置文件;
* 除非应用jar变动有场景需求,否则lib尽量不用;
所以核心其实是这三个:
```Jar``````bin/脚本``` ```logs```
配置文件conf
```bash
#jar包名称
jarpack="应用名称.jar"
#jar包路径
jarpath="/mnt/xxxx/test"
#java 的路径
path="/usr/local/java/jdk1.7.0_71/bin"
#虚拟机参数
JAVA_OPTS="--Xms4096m -Xmx4096m -XX:PermSize=128M -XX:PermSize=128M "
#应用程序参数
APP_OPTS="run.mode=daily --server.port=28180"
```
start.sh
```bash
#!/bin/bash
dir=$(cd `dirname $0`;pwd)
source $dir/conf
ret=`ps -ef | grep "$jarpath/$jarpack" | grep -v grep`
if [ "$ret"x == "x" ];then
cd $jarpath
nohup $path/java $JAVA_OPTS -jar $jarpath/$jarpack $APP_OPTS >/dev/null 2>&1 &
fi
ret=`ps -ef | grep "$jarpath/$jarpack" | grep -v grep`
if [ "$ret"x != "x" ];then
echo "you have start the your service $jarpack now!"
else
echo "Please check your conf! and re-excute the start.sh"
fi
```
stop.sh
```bash
#!/bin/bash
dir=$(cd `dirname $0`;pwd)
source $dir/conf
pid=`ps -ef| grep "$jarpath/$jarpack" | grep -v grep |awk '{print $2}'`
if [ "$pid"x != "x" ];then
kill$pid
fi
sleep 1s
ret=`ps -ef | grep "$jarpath/$jarpack" | grep -v grep`
sleep 10s
if [ "$ret"x = "x" ];then
echo "you have stop the your service $jarpack now!"
else
pid=`ps -ef| grep "$jarpath/$jarpack" | grep -v grep |awk '{print $2}'`
if [ "$pid"x != "x" ];then
echo "you service can't be stoped,so kill -9 your service! "
kill -9 $pid
fi
fi
```
循环kill形式的stop脚本
```bash
#!/bin/bash
dir=$(cd `dirname $0`;pwd)
source $dir/conf
pid=`ps -ef| grep "$jarpath/$jarpack" | grep -v grep |awk '{print $2}'`
#循环kill 形式,非kill -9
while [ ! -z $pid ]
do
echo "shutting down $jarpath/$jarpackwhich pid is $pid"
kill $pid
sleep 1
pid=`ps -ef| grep "$jarpath/$jarpack" | grep -v grep |awk '{print $2}'`
done
echo "you have stop the your service $jarpack now!"
```
!(data/attachment/forum/202206/16/141330jha7st9soow8772i.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "common_log.png")
`转载务必注明出处:程序员潇然,疯狂的字节X,https://crazybytex.com/thread-44-1-1.html `
页:
[1]