springboot2 生产部署注意事项及示例代码
注意事项1. 去除不需要的 jar
开发工具 jar :springs-boot-devtools
2. 监控一定要做好权限制或者去除
控制 jar :spring-boot-starter-actuator 监控
druid 的监控
swagger的接口
3 打包的时候要跳过测试
maven : clean package -dmaven.test.skip=true
打包脚本示例:
#!/bin/sh
## chang here
service_dir=/roncoo/spring-boot-demo
service_name=spring-boot-demo-31-1-0.0.1-snapshot
spring_profiles_active=dev
## java env
export java_home=/opt/jdk1.7.0_79
export jre_home=${java_home}/jre
case "$1" in
start)
procedure=`ps -ef | grep -w "${service_name}" |grep -w "java"| grep -v "grep" | awk '{print $2}'`
if [ "${procedure}" = "" ];
then
echo "start ..."
if [ "$2" != "" ];
then
spring_profiles_active=$2
fi
echo "spring.profiles.active=${spring_profiles_active}"
exec nohup ${jre_home}/bin/java -xms128m -xmx512m -jar ${service_dir}/${service_name}\.jar --spring.profiles.active=${spring_profiles_active} >/dev/null 2>&1 &
echo "start success"
else
echo "${service_name} is start"
fi
;;
stop)
procedure=`ps -ef | grep -w "${service_name}" |grep -w "java"| grep -v "grep" | awk '{print $2}'`
if [ "${procedure}" = "" ];
then
echo "${service_name} is stop"
else
kill -9 ${procedure}
sleep 1
argprocedure=`ps -ef | grep -w "${service_name}" |grep -w "java"| grep -v "grep" | awk '{print $2}'`
if [ "${argprocedure}" = "" ];
then
echo "${service_name} stop success"
else
kill -9 ${argprocedure}
echo "${service_name} stop error"
fi
fi
;;
restart)
$0 stop
sleep 1
$0 start $2
;;
*)
echo "usage: $0 "
;;
esac
如果有条件,用jenkins自动构建比较好
总结
以上所述是小编给大家介绍的springboot2 生产部署注意事项及示例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
原文链接:https://www.cnblogs.com/zhenghongxin/archive/2019/04/08/10669271.html
文档来源:http://www.zzvips.com/article/179936.html
页:
[1]