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. mysql 间隙锁专题

    本文研究记录mysql间隙锁,涉及以下情况 唯一索引 非唯一索引 范围更新 等值更新 mysql8 mysql7 RR RC 数据准备 mysql> select * from vodb.tes ...

  2. Android 基础UI组件(二)

    1.Spinner 提供一个快速的方法来从一组值中选择一个值.在默认状态Spinner显示当前选择的值.触摸Spinner与所有其他可用值显示一个下拉菜单,可以选择一个新的值. /** * 写死内容: ...

  3. 开源低代码开发平台entfrm2.1.0更新

    开源低代码开发平台entfrm2.1.0更新 新功能 代码生成支持主子表,支持预览: 新增多应用顶部菜单与左侧菜单联动: element-ui升级到2.15.1: 新增表单管理,集成avue-from ...

  4. redis的总结笔记

    # Redis    1. 概念: redis是一款高性能的NOSQL系列的非关系型数据库        1.1.什么是NOSQL            NoSQL(NoSQL = Not Only ...

  5. 简单的Spring Boot项目——实现连接Mysql数据库

    一.创建Spring Boot项目 参考:使用IntelliJ IDEA创建简单的Spring Boot项目 二.数据库.表的创建 三.项目开发 3.1 pom.xml文件配置 <?xml ve ...

  6. myfs 操作系统课内实验 文件管理系统 Ext2

    To 学弟学妹们: 写这个随笔原意是记录一下这个很有趣的实验 ,记录一下写的时候的细节和思路. 要是光是抄这个代码,反而使得这个实验失去了意义. 加油,这个实验收获真的很大. 任务描述: 用一个空白文 ...

  7. rpm-build方式制作rpm包

    目录 一.简介 二.具体操作 一.简介 可以将编译完成的服务打成rpm包放到私有仓库了,用于自定义的各种软件进行安装部署配置. 二.具体操作 1.安装软件,这个命令将构建rpm包 yum -y ins ...

  8. [BUUCTF]REVERSE——[BJDCTF2020]easy

    [BJDCTF2020]easy 附件 例行检查,无壳,32位程序 32位ida载入,main函数和字符串理都没有找到有关flag的提示 根据main函数的提示,有关flag的函数应该被藏起来了,在左 ...

  9. Tornado WEB服务器框架 Epoll

    引言: 回想Django的部署方式 以Django为代表的python web应用部署时采用wsgi协议与服务器对接(被服务器托管),而这类服务器通常都是基于多线程的,也就是说每一个网络请求服务器都会 ...

  10. SpringBoot整合zimg图片服务器

    依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</arti ...