springboot2 生产部署注意事项及示例代码

时间:2021-10-20 18:07:57

注意事项

1. 去除不需要的 jar

  开发工具 jar :springs-boot-devtools

2. 监控一定要做好权限制或者去除

  控制 jar :spring-boot-starter-actuator 监控

  druid 的监控

  swagger的接口

3 打包的时候要跳过测试

  maven : clean package -dmaven.test.skip=true

打包脚本示例:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/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 [start|stop|restart] [dev|test|prod]"
    ;;
esac

 如果有条件,用jenkins自动构建比较好

总结

以上所述是小编给大家介绍的springboot2 生产部署注意事项及示例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

原文链接:https://www.cnblogs.com/zhenghongxin/archive/2019/04/08/10669271.html