1.Config Server对外提供的资源格式

配置中心的HTTP服务有5种资源格式:

/{application}/{profile}[/{label}]

/{application}-{profile}.yml
/{label}/{application}-{profile}.yml /{application}-{profile}.properties
/{label}/{application}-{profile}.properties

{application}对应spring.config.name,
通常在Spring Boot应用默认中默认是application,
{profile}是有效配置文件属性列表,
多个直接使用逗号分隔,例如(dev,test),
{label}是可选的git标签,默认值为master。

推荐使用格式:

/{label}/{application}-{profile}.yml

示例如下:

http://config-server.com:port/master/application-dev.yml

2.支持的数据来源获取配置

Git仓库,包括任何与JDBC兼容的数据库,
Subversion,Hashicorp Vault,Credhub和本地文件系统。
详细设置请参考SpringCloud创建Config读取本地配置

3.Config Client本地的配置会被覆盖

3.1.profile本地覆盖远程

bootstrap.yml中的spring.cloud.config.profile: test,
config-client-demo.yml中的spring.profiles.active: - dev,
测试结果为使用本地test配置。

3.2.name远程覆盖本地

bootstrap.yml中的spring.application.name: config-client
被config-client-demo.yml中test的spring.application.name:config-client-test,
测试结果为远程的config-client-test。
同样的server.port: 8001这类的属性也会被覆盖。

4.跳过SSL证书验证

可以通过将git.skipSslValidation属性设置为true,
来禁用配置服务器对Git服务器的SSL证书的验证,
该属性默认值为false。

spring:
cloud:
config:
server:
git:
uri: https://example.com/my/repo
skipSslValidation: true

5.设置HTTP连接超时

使用git.timeout属性,
配置服务器等待获取HTTP连接的时间,
单位为秒。

spring:
cloud:
config:
server:
git:
uri: https://example.com/my/repo
timeout: 4

如果要进一步配置超时阈值:
使用spring.cloud.config.request-read-timeout配置读取超时。
使用spring.cloud.config.request-connect-timeout配置连接超时。

6.存储库可以将配置文件存储在子目录中

用于搜索这些目录的模式可以指定为searchPaths,
以下示例在顶层显示了一个配置文件,
服务器在顶层和foo/子目录中以及名称以bar开头的任何子目录中搜索配置文件:

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
searchPaths: foo,bar*

7.服务器配置为在启动时克隆存储库

默认情况下,首次请求配置时,服务器会克隆远程存储库。
如以下顶级示例所示,
在前面的示例中,服务器在接受任何请求之前会在启动时克隆team-a的config-repo。
在请求从存储库进行配置之前,不会克隆所有其他存储库。

spring:
cloud:
config:
server:
git:
uri: https://git/common/config-repo.git
repos:
team-a:
pattern: team-a-*
cloneOnStart: true
uri: https://git/team-a/config-repo.git
team-b:
pattern: team-b-*
cloneOnStart: false
uri: https://git/team-b/config-repo.git
team-c:
pattern: team-c-*
uri: https://git/team-a/config-repo.git

8.服务器从远程存储库强制拉取

如果本地副本脏了,
设置force-pull属性设置为true,
可以使Config服务器从远程存储库强制拉取,
如下所示:

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
force-pull: true

9.Git刷新率

使用spring.cloud.config.server.git.refreshRate,
指定配置服务器多久从Git后端获取更新的配置数据。
单位为秒。
默认值为0,
即配置服务器将在每次请求时从Git存储库中获取更新的配置。

10.查看actuator和health健康指示器

http://localhost:9009/actuator

{
"_links": {
"self": {
"href": "http://localhost:9009/actuator",
"templated": false
},
"health": {
"href": "http://localhost:9009/actuator/health",
"templated": false
},
"health-path": {
"href": "http://localhost:9009/actuator/health/{*path}",
"templated": true
},
"info": {
"href": "http://localhost:9009/actuator/info",
"templated": false
}
}
}

配置中心检查远程仓库是否可以连通,
UP代表健康检查是可用的,
所以配置中心提供的服务是可用的。
http://localhost:9009/actuator/health

{
"status": "UP"
}

配置运行状况指示器可以检查更多应用程序,
以及自定义配置文件和自定义标签的检查。

若要禁用健康状态指示器,
可设置spring.cloud.config.server.health.enabled=false

11.HTTP基本安全认证

在服务器上使用HTTP Basic基本安全认证,
则客户端需要知道密码,
如果不是默认用户名,则需要用户名。
可以通过配置服务器URI
或通过单独的用户名和密码属性来指定用户名和密码:

spring:
cloud:
config:
uri: https://user:secret@myconfig.mycompany.com

或者

spring:
cloud:
config:
uri: https://myconfig.mycompany.com
username: user
password: secret

spring.cloud.config.password和spring.cloud.config.username值会覆盖URI中提供的任何内容。

12.指定配置文件检出目录

使用基于vcs的后端(git、svn),文件被检出或克隆到本地文件系统。
默认情况下,它们被放在带有config-repo-前缀的系统临时目录中。
可以通过设置 spring.cloud.config.server.git.basedir或者
spring.cloud.config.server.svn.basedir,
指定一个不位于系统临时结构中的目录。

spring:
cloud:
config:
server:
git:
uri: https://gitee.com/bugzeroman/spring-cloud-config.git
basedir: D:\Code\Learn\SpringCloud\config-dir
cloneOnStart: true

13.关闭配置中心

配置中心默认是开启的true,
关闭配置中心需要设置为false:

spring.cloud.config.enabled=false

14.Config客户端使用公共配置

首先规划各个微服务:
Config Server不注册到Eureka Server;
Eureka Server通过URL连接到Config Server,获取自己微服务配置;
Config Client通过URL连接到Config Server,获取自己微服务配置;
Eureka Client通过URL连接到Config Server,获取连接Eureka Server的配置;

Config Server连接的git仓库有如下文件:

eureka-server-dev.yml
config-client-dev.yml
eureka-client-dev.yml

Config Server本地有文件application.yml,
其他微服务本地有这个文件bootstrap.yml。

SpringCloud使用汇总Config的更多相关文章

  1. springcloud系列12 config的使用

    config组件分为server端和client端 config的原理: 就是当我们将配置文件放置在git上面,那么configserver就会去拉取相关配置文件至本地: 可以看到我本地是拉去了配置文 ...

  2. SpringCloud学习之Config分布式配置中心(八)

    统一配置中心概述 如果微服务架构中没有使用统一配置中心时,所存在的问题: 配置文件分散在各个项目里,不方便维护 配置内容安全与权限,实际开发中,开发人员是不知道线上环境的配置的 更新配置后,项目需要重 ...

  3. SpringCloud配置中心config

    1,配置中心可以用zookeeper来实现,也可以用apllo 来实现,springcloud 也自带了配置中心config Apollo 实现分布式配置中心 zookeeper:实现分布式配置中心, ...

  4. springcloud微服务config的使用

    首先需要建立一个server端: pom依赖中加入 <dependency> <groupId>org.springframework.cloud</groupId> ...

  5. springcloud系列13 config的客户端使用

    config客户端的使用: 也是首先要引入依赖: <dependency> <groupId>org.springframework.cloud</groupId> ...

  6. 从零搭建一个SpringCloud项目之Config(五)

    配置中心 一.配置中心服务端 新建项目study-config-server 引入依赖 <dependency> <groupId>org.springframework.cl ...

  7. Spring-Cloud之Config配置中心-7

    一.我们前面基本上都是讲解的Spring Cloud Netflix的组件,下面我们会重点说Spring Cloud Config分布式配置中心.为什么需要这个组件来管理配置呢?在分布式应用开发过程中 ...

  8. SpringCloud服务消费有哪几种方式?

    一.使用LoadBalancerClient LoadBalancerClient接口的命名中,可以看出这是一个负载均衡客户端的抽象定义,spring提供了一个实现 org.springframewo ...

  9. SpringCloud之Security

    Spring Security是Spring提供的一个安全框架,提供认证和授权功能,最主要的是它提供了简单的使用方式,同时又有很高的灵活性,简单,灵活,强大. 我个人博客系统采用的权限框架就是Spri ...

随机推荐

  1. Python @函数装饰器及用法(超级详细)

    函数装饰器的工作原理是怎样的呢?假设用 funA() 函数装饰器去装饰 funB() 函数,如下所示: #funA 作为装饰器函数 def funA(fn): #... fn() # 执行传入的fn参 ...

  2. OceanBase 2.x体验:推荐用DBeaver工具连接数据库

    Original MQ4096 [OceanBase技术闲谈](javascript:void(0) 2020-01-15 OceanBase 2.x体验:推荐用DBeaver工具连接数据库 Ocea ...

  3. web端 - 返回上一步,点击返回,跳转上个页面 JS

    1.方法一: <script language="javascript" type="text/javascript"> window.locati ...

  4. matplotlib 画图中图和次坐标轴

    一: fig.add_axes 画图中图 fig = plt.figure() x = np.arange(1, 9, 1) y = np.linspace(1, 10, 8) left, botto ...

  5. 【Windows】github无法访问/hosts文件只能另存为txt

    因为我的github访问不了了,搜索解决方案为修改host文件 https://blog.csdn.net/curry10086/article/details/106800184/ 在hosts文件 ...

  6. 快速上手ANTLR

    回顾前文: ANTLR 简单介绍 ANTLR 相关术语 ANTLR 环境准备 下面通过两个实例来快速上手ANTLR. 使用Listener转换数组 完整源码见:https://github.com/b ...

  7. .gitignore文件作用

    目录 一.简介 二.常用规则 三.详细 一.简介 一般来说每个Git项目中都需要一个.gitignore文件,这个文件的作用就是告诉Git哪些文件不需要添加到版本管理中. 意思就是本地修改完项目后,上 ...

  8. tableau添加参考线

    一.将数据窗口切换至分析窗口-点击自定义-参考线 二.出现编辑参考线和参考区间的界面(整个表指的是整个视图,每区指的是如下2018就是一个区,每单元格指的是横轴的最小值) 三.我们分别为每区添加最大值 ...

  9. .NET静态代码织入——肉夹馍(Rougamo)

    肉夹馍是什么 肉夹馍通过静态代码织入方式实现AOP的组件..NET常用的AOP有Castle DynamicProxy.AspectCore等,以上两种AOP组件都是通过运行时生成一个代理类执行AOP ...

  10. CF812A Sagheer and Crossroads 题解

    Content 有一个十字路口,从最下面的部分开始,逆时针依次标号为 \(1,2,3,4\).每个部分有四个灯,分别为左转的灯.直行的灯.右转的灯以及人行通道灯(只有可能为红灯和绿灯).如果某个部分的 ...