spring cloud开发、部署注意

https://www.cnblogs.com/skyblog/p/7243979.html

一、开发时,配置服务的配置使用本地路径,不使用svn和git,因为后者每个开发人员都会修改配置,导致别人也拿到其他人修改的配置,本地配置示例如下:

1
2
3
4
5
6
7
8
9
10
11
spring:
   application:
     name: simple-config-server
   cloud:
     config:
       server:      
         default-label: trunk 
         native:
           searchLocations:  file : ///D :\works\smart\simple-config-repo                 
   profiles:
     active: native

 

二、对于生产环境部署到阿里云的,使用不了docker,因为docker文件通常有几百兆,部署时上传很慢。不但不能使用docker,打包时也没有必要包含所有的包,如果去掉依赖包,编译完后每个jar只有几百k,这样部署起来就方便多了。可以如下设置pom编译选项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
< build >
         < plugins >
             < plugin >
                 < groupId >org.springframework.boot</ groupId >
                 < artifactId >spring-boot-maven-plugin</ artifactId >
             </ plugin >
             < plugin >
                 < groupId >org.apache.maven.plugins</ groupId >
                 < artifactId >maven-jar-plugin</ artifactId >
                 < configuration >
                     < archive >
                         < manifest >
                             < addClasspath >true</ addClasspath >
                             < mainClass >ebtins.smart.proxy.SmartProxyApplication</ mainClass >
                             < classpathPrefix >lib/</ classpathPrefix >
                         </ manifest >
                     </ archive >
                 </ configuration >
             </ plugin >
         </ plugins >
         < defaultGoal >compile</ defaultGoal >
     </ build >
    

这样你生产环境的服务目录将如下,simple-service.jar只有几百K。

simple-service.jar simple-service.sh lib logs

三、使用脚本启动和关闭服务,centos下的脚本启动和关闭可以如下:

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
start(){ 
  now=` date  "+%Y%m%d%H%M%S"
  exec
  java -Xms64m -Xmx256m -jar . /simple-service-0 .0.1.jar --server.port=7085 --config.name=pro > logs /simple-service .log &
#停止方法 
stop(){ 
  ps  aux| grep  simple-service| grep  7085| grep  - v  grep | awk  '{print $2}' | while  read  pid 
  do 
     kill  -9 $pid
  done
   
case  "$1"  in 
start) 
start 
;; 
stop) 
stop 
;;   
restart) 
stop 
start 
;; 
*) 
printf  'Usage: %s {start|stop|restart}\n'  "$testg" 
exit 
;; 
esac


启动方式:sh simple-service.jar start
当然可以在脚本里启动本服务器所有服务,也可以使用自动部署机制,自动部署自动启动。
这是生产和开发环境的一点小小经验。


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值