springboot2 生产部署注意事项及示例代码
程序员文章站
2023-12-16 23:57:46
注意事项
1. 去除不需要的 jar
开发工具 jar :springs-boot-devtools
2. 监控一定要做好权限制或者去除
控制 ja...
注意事项
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 [start|stop|restart] [dev|test|prod]" ;; esac
如果有条件,用jenkins自动构建比较好
总结
以上所述是小编给大家介绍的springboot2 生产部署注意事项及示例代码,希望对大家有所帮助