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