spring cloud开发、部署注意
一、开发时,配置服务的配置使用本地路径,不使用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
当然可以在脚本里启动本服务器所有服务,也可以使用自动部署机制,自动部署自动启动。
这是生产和开发环境的一点小小经验。
分类:
spring cloud
, 微服务架构
标签:
spring cloud、微服务
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?