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. Advanced C++ | Conversion Operators

    In C++, the programmer abstracts real world objects using classes as concrete types. Sometimes it is ...

  2. Linux后台启动服务

    systemctl 启动/关闭/启用/禁用服务 总结 启动服务 systemctl start test.service 关闭服务 systemctl stop test.service 重启服务 s ...

  3. 【Python】【Module】random

    mport random print random.random() print random.randint(1,2) print random.randrange(1,10) 随机数 import ...

  4. spring security oauth2 搭建认证中心demo

    oauth2 介绍 ​ oauth2 协议应该是开发者们耳熟能详的协议了,这里就不做过多的介绍了,具体介绍如何在spring security中搭建oauth2的认证服务.Spring-Securit ...

  5. Redis单点到集群迁移

    目录 一.简介 一.简介 1.环境 源 192.168.1.185的6379 目标 192.168.1.91的7001,7002 192.168.1.92的7003,7004 192.168.1.94 ...

  6. Apache Log4j 远程代码执行漏洞源码级分析

    漏洞的前因后果 漏洞描述 漏洞评级 影响版本 安全建议 本地复现漏洞 本地打印 JVM 基础信息 本地获取服务器的打印信息 log4j 漏洞源码分析 扩展:JNDI 危害是什么? GitHub 项目 ...

  7. 前端浅谈-Js的组成

    这里主要想详细的分析一下浏览器渲染过程,但东西比较多.所以分成多个部分. JS由三个部分组成,分别为ECMAScript.BOM.DOM. 其中BOM是浏览器层面的东西,而DOM是页面层面的东西.简单 ...

  8. LuoguP7059 [NWRRC2015]Lucky Chances 题解

    Content 有一个名叫 Lucky chances 的游戏,游戏一开始给出一个 \(r\times c\) 的矩阵,你可以选定矩阵中任意一个元素以及上.下.左.右四个方向中的任意一个方向进行游戏. ...

  9. MLNX网卡驱动安装

    安装/升级MLNX驱动 1. 安装准备 驱动下载地址:https://www.mellanox.com/products/ethernet-drivers/linux/mlnx_en 选择和系统版本匹 ...

  10. 多进程 multiprocessing 模块进程并发Process;Pool ;Queue队列 、threading模块;

    multiprocessing 模块中的 Process类提供了跨平台的多进程功能,在windows和linux系统都可以使用. 1.首先要实例化一个类,传入要执行的函数. 实例名 = Process ...