为每个配置文件组配置 spring 云配置服务器
Configure spring cloud config server for each profile group
我的环境很少。有:
- 本地
- 发展
- 测试
- qa
- lod
- 产品
如果配置服务器连接到所有这些,一切都清楚了。
在我的例子中,我需要每组配置服务器:
- 在开发控制下
- 在质量控制下
- 接近 devops 控制
组连接到权限和不同的环境。
所以我需要为每个客户提供类似的东西:
bootstrap.yml
# default configs for local, dev, test profiles
spring:
application:
name: discovery-service
cloud:
config:
uri: http://local-dev-test-configuration-server:8888
---
# **bootstrap-qa.yml**
spring:
profiles: qa
application:
name: discovery-service
cloud:
config:
uri: http://qa-configuration-server:8888
---
# **bootstrap-prod.yml**
spring:
profiles: prod,lod
application:
name: discovery-service
cloud:
config:
uri: http://lod-prod-configuration-server:8888
在哪里
local-dev-test-configuration-server
可以访问 local
、dev
和 test
服务器配置;
qa-configuration-server
可以访问 qa
配置;
lod-prod-configuration-server
只能访问 prod
和 lod
配置。
问题:
我研究了 spring 引导文档,但我没有遇到 bootstrap.yml
分析。
- 我应该遵循哪种方式来满足我的需求(管理 3 个不同的配置服务器和相应的配置文件)?
- 我检测到可以 configure different git resources 用于相同的配置服务器。这种方法是否最适合我的情况(我还必须管理几个存储库以保留所需的配置)?我不这么认为。由于可见性不同,我需要为不同的环境配置很少的配置服务器。因此,我需要根据配置文件对每个消费者配置主机名进行配置。
为 spring-cloud-configuration-servers 配置客户端有两种可能的解决方案:
- spring-boot 支持
bootstrap.yml
中的配置文件,因此提供的配置可以用作解决方案
spring:
application:
name: discovery-service
cloud:
config:
uri: http://local-dev-test-configuration-server:8888
---
spring:
profiles: qa
application:
name: discovery-service
cloud:
config:
uri: http://qa-configuration-server:8888
---
spring:
profiles: prod,lod
application:
name: discovery-service
cloud:
config:
uri: http://lod-prod-configuration-server:8888
- 如果您想使
bootstrap.yml
配置尽可能简单:
spring:
application:
name: discovery-service
cloud:
config:
uri: http://local-dev-test-configuration-server:8888
在这种情况下,解决方案是使用 -Dspring.cloud.config.uri=http://localhost:8888
需要的参数覆盖 属性 例如:
java -Dspring.profiles.active=localhost -Dspring.cloud.config.uri=http://localhost:8888 -jar ./target/discovery-service-0.0.1-SNAPSHOT.jar
P.S.
方法可以混合使用。
我的环境很少。有:
- 本地
- 发展
- 测试
- qa
- lod
- 产品
如果配置服务器连接到所有这些,一切都清楚了。
在我的例子中,我需要每组配置服务器:
- 在开发控制下
- 在质量控制下
- 接近 devops 控制
组连接到权限和不同的环境。
所以我需要为每个客户提供类似的东西:
bootstrap.yml
# default configs for local, dev, test profiles
spring:
application:
name: discovery-service
cloud:
config:
uri: http://local-dev-test-configuration-server:8888
---
# **bootstrap-qa.yml**
spring:
profiles: qa
application:
name: discovery-service
cloud:
config:
uri: http://qa-configuration-server:8888
---
# **bootstrap-prod.yml**
spring:
profiles: prod,lod
application:
name: discovery-service
cloud:
config:
uri: http://lod-prod-configuration-server:8888
在哪里
local-dev-test-configuration-server
可以访问local
、dev
和test
服务器配置;qa-configuration-server
可以访问qa
配置;lod-prod-configuration-server
只能访问prod
和lod
配置。
问题:
我研究了 spring 引导文档,但我没有遇到 bootstrap.yml
分析。
- 我应该遵循哪种方式来满足我的需求(管理 3 个不同的配置服务器和相应的配置文件)?
- 我检测到可以 configure different git resources 用于相同的配置服务器。这种方法是否最适合我的情况(我还必须管理几个存储库以保留所需的配置)?我不这么认为。由于可见性不同,我需要为不同的环境配置很少的配置服务器。因此,我需要根据配置文件对每个消费者配置主机名进行配置。
为 spring-cloud-configuration-servers 配置客户端有两种可能的解决方案:
- spring-boot 支持
bootstrap.yml
中的配置文件,因此提供的配置可以用作解决方案
spring:
application:
name: discovery-service
cloud:
config:
uri: http://local-dev-test-configuration-server:8888
---
spring:
profiles: qa
application:
name: discovery-service
cloud:
config:
uri: http://qa-configuration-server:8888
---
spring:
profiles: prod,lod
application:
name: discovery-service
cloud:
config:
uri: http://lod-prod-configuration-server:8888
- 如果您想使
bootstrap.yml
配置尽可能简单:
spring:
application:
name: discovery-service
cloud:
config:
uri: http://local-dev-test-configuration-server:8888
在这种情况下,解决方案是使用 -Dspring.cloud.config.uri=http://localhost:8888
需要的参数覆盖 属性 例如:
java -Dspring.profiles.active=localhost -Dspring.cloud.config.uri=http://localhost:8888 -jar ./target/discovery-service-0.0.1-SNAPSHOT.jar
P.S.
方法可以混合使用。