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. Android 图片框架

    1.图片框架:Picasso.Glide.Fresco 2.介绍: picasso:和Square的网络库能发挥最大作用,因为Picasso可以选择将网络请求的缓存部分交给了okhttp实现 Glid ...

  2. shell awk命令字符串拼接

    本节内容:awk命令实现字符串的拼接 输入文件的内容: TMALL_INVENTORY_30_GROUP my163149.cm6 3506 5683506 mysql-bin.000013 3273 ...

  3. 【Java基础】Java中如何获取一个类中泛型的实际类型

    泛型的术语 <>: 念做typeof List<E>: E称为类型参数变量 ArrayList<Integer>: Integer称为实际类型参数 ArrayLis ...

  4. MFC入门示例之组合框(CComboBox)、列表框(CListBox)

    1 //添加按钮点击事件 2 void CMFCApplication4Dlg::OnBnClickedButton1() 3 { 4 CString strText; 5 //获取文本框的值 6 G ...

  5. AOP中环绕通知的写法

    package com.hope.utils;import org.aspectj.lang.ProceedingJoinPoint;/** * @author newcityman * @date ...

  6. SQL->Python->PySpark计算KS,AUC及PSI

    KS,AUC 和 PSI 是风控算法中最常计算的几个指标,本文记录了多种工具计算这些指标的方法. 生成本文的测试数据: import pandas as pd import numpy as np i ...

  7. 转:KVC 与 KVO 理解

    KVC 与 KVO 理解 On 2012 年 6 月 7 日, in iPhone, by donly KVC 与 KVO 是 Objective C 的关键概念,个人认为必须理解的东西,下面是实例讲 ...

  8. 【web】sqli-labs学习

    第一页 1~4预备知识(基于错误的注入)   几个常用函数: 1. version()--MySQL 版本 2. user()--数据库用户名 3. database()--数据库名 4. @@dat ...

  9. 【死磕Java并发】-----内存模型之happens-before

    在上篇博客([死磕Java并发]-----深入分析volatile的实现原理)LZ提到过由于存在线程本地内存和主内存的原因,再加上重排序,会导致多线程环境下存在可见性的问题.那么我们正确使用同步.锁的 ...

  10. 一篇文章讲明白vue3的script setup,拥抱组合式API!

    引言 vue3除了Composition API是一个亮点之外,尤大大又给我们带来了一个全新的玩意 -- script setup,对于setup大家相信都不陌生,而对于script setup有些同 ...