统一配置中心

为什么需要统一配置中心?

统一配置中心顾名思义,就是将配置统一管理,配置统一管理的好处是在日后大规模集群部署服务应用时相同的服务配置一致,日后再修改配置只需要统一修改全部同步,不需要一个一个服务手动维护

统一配置中心的架构图:

服务者消费者集群,路由集群Zuul的配置文件可以全部交由config管理,Eureka Server配置是绝对不行的,因为Config配置中心也是作为一个Client服务注册到Eureka Server的,先有Server。

1.配置中心服务器的开发

1.添加依赖
      <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-config-server</artifactId></dependency>
2.添加注解支持@EnableConfigServer
@EnableEurekaClient
@EnableConfigServer
@SpringBootApplication
public class EurekaApplication {public static void main(String[] args) {SpringApplication.run(EurekaApplication.class, args);}
}
3.在远程的仓库创建配置文件(yml,properties,yaml)

在这里我对两个服务者的配置文件进行管理

规则说明:加入你在github仓库添加了一个名为product.properties的配置文件,并且开启了配置中心服务器(假设端口为9999),使用浏览器测试访问:http://localhost:8766/product.properties 是访问不到任何内容的,访问http://localhost:8766/product-xxxxx.properties(xxx随便写)是可以访问到的,这是Config配置中心的规则,下面会说到,另一方面配置文件合并规则,在学习springboot时我们可以将配置文件拆分:主配置文件 application.yml存放公共配置 测试环境:testapp.yml 生产环境:product.yml 使用时根据情况主配置引入不同的副配置文件,这里Config配置中心规则与springboot是相似的。

如下仓库文件:

[product.properties]

eureka.client.service-url.defaultZone=http://peer:8761/eureka,http://peer1:8765/eureka
spring.application.name=eureka-provider

[product-8763.properties]

server.port=8763

[product-8764.properties]

server.port=8764

访问: http://localhost:9999/product-xxxxx.properties 得到公共配置文件

访问: http://localhost:9999/product-8763.properties 公共配置与8763私有配置的合并

访问: http://localhost:9999/product-8764.properties 公共配置与8764私有配置的合并

.properties后缀是可以修改为yml,yaml,json 以对应的格式返回在浏览器上。

4.配置相关的配置文件
#注册到注册中心
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
#默认端口号 8888
server.port=9999
# 实例名
spring.application.name=config
#配置git的远程仓库   https 暂时不支持ssh
spring.cloud.config.server.git.uri=https:xxxxxxx
5.启动配置中心服务

http://localhost:9999/order-a.yml

http://localhost:9999/order-a.yaml

http://localhost:9999/order-a.properties

http://localhost:9999/order-a.json

以上四种访问方式都可以

{name}/{profiles:.[^-].}

{name}-{profiles}.json

{label}/{name}-{profiles}.yml

{name}/{profiles}/{label:.*}

{label}/{name}-{profiles}.properties

{label}/{name}-{profiles}.json

{name}/{profile}/{label}/**

{name}/{profile}/{label}/**

说明:

label: 分支名称 默认是master分支

name:文件的服务的名称(自定义的名称)

profiles:不同环境

2.配置中心客户端使用

凡是交由配置中心管理的Client,想要获取配置文件需要添加以下依赖

1.导入相关依赖
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-config-client</artifactId>
</dependency>
2.添加配置
#开启配置中心
spring.cloud.config.enabled=true
#找到配置中心实例
spring.cloud.config.discovery.service-id=CONFIG
#指定名字
spring.cloud.config.name=product
#指定环境 8763或8764 由客户端的不同而改变
spring.cloud.config.profile=8763
#指定分支
spring.cloud.config.label=master
#指定配置中心的uri
spring.cloud.config.uri=http://localhost:9999

注意:spring.cloud.config.uri=xxx必须指定Config配置中心的地址,如果不指定默认则从8888端口fetch配置是不成功的,除非你的配置中心端口就是8888。

3.注意将配置文件名修改为 bootstrap.yml 表示从云端获取配置文件

转载于:https://www.cnblogs.com/mzc1997/p/10262071.html

springcloud-spring cloud config统一配置中心相关推荐

  1. 第十二章 Spring Cloud Config 统一配置中心详解

    目录 一.配置问题分析及解决方案 1.问题分析 2.解决方案 二.Spring Cloud Config 介绍 1.Spring Cloud Config特性 2.Spring Cloud Confi ...

  2. Spring Cloud Config的配置中心获取不到最新配置信息的问题

    本篇源于Spring Cloud Config的一个问题,但这个问题并非所有人都会遇到.如果您遇到了,那必须得看看这篇,如果没有遇到您也应该看看,防患于未然! 问题描述 之前有朋友提出Spring C ...

  3. Spring cloud config 分布式配置中心(一) 服务端

    作用: 为分布式系统中的基础设施和微服务应用提供外部集中化的配置支持,分客户端和服务端 服务端: 即分布式配置中心,是一个独立的微服务应用,连接配置仓库,为客户端提供一些访问接口,如加密 / 解密信息 ...

  4. spring cloud config将配置存储在数据库中

    点击上方"方志朋",选择"置顶或者星标" 你的关注意义重大! Spring Cloud Config Server最常见是将配置文件放在本地或者远程Git仓库, ...

  5. spring cloud config将配置存储在数据库中 1

    转载请标明出处: https://blog.csdn.net/forezp/... 本文出自方志朋的博客 Spring Cloud Config Server最常见是将配置文件放在本地或者远程Git仓 ...

  6. spring cloud -- 5.分布式配置中心(Spring Cloud Config)

    此文章是看了方志朋老师的教材自己写的框架demo: 学习spring cloud推荐大家看下方志朋老师的史上最简单的 SpringCloud 教程 | 终章,地址如下: https://blog.cs ...

  7. Spring Cloud Config 和Spring Cloud Bus实现配置中心

    2019独角兽企业重金招聘Python工程师标准>>> Spring Cloud是很多组件的集合,Spring将常用的技术框架进行包装和整合,如mybatis zookeeper r ...

  8. Spring Cloud Config统一管理微服务配置

    一Spring Cloud Config背景及简介 # 集中管理的需求:一个使用微服务架构的应用系统可能会包括成百上千个微服务,因此集中管理很有必要 # 不同环境不同配置:例如数据源在不同的环境(开发 ...

  9. python自助电影售票机_Spring Cloud版——电影售票系统六使用 Spring Cloud Config 统一管理微服务配置...

    一. 为什么要统一管理微服务配置 在传统的单体应用,常使用配置文件管理所有配置.比如,一个 Spring Boot 开发的单体应用,可将配置内容放在 application.yml 文件中.如果需要切 ...

最新文章

  1. Git tag 打标签
  2. java nio 读取图片_给大忙人们看的 Java NIO 极简教程
  3. bzoj5039:[Jsoi2014]序列维护
  4. Codeforce-Ozon Tech Challenge 2020-C. Kuroni and Impossible Calculation(鸽笼原理)
  5. Asp.Net Boilerplate微服务实战(二)架构解析
  6. run as date怎么用_熟词僻义 | date是一种什么水果?
  7. socket编程简单Demo讲解及源码分享(C# Winform 内网)
  8. python requests_一起看看Python之Requests库
  9. Android解压boot.img
  10. 【CodeVS】 p1696 奇怪的函数
  11. 6亿债务年底还完,老罗“真还传”即将完结
  12. java猜数字1到100_Java实现简单猜数字小游戏
  13. 《Adobe Photoshop CS5中文版经典教程(全彩版)》目录—导读
  14. Mybatis-Plus eq、ne、gt、lt、ge、le....分别代表含义
  15. 大话设计模式C++实现-第7章-代理模式
  16. python-selenium学习笔记:利用ec模块的定位方法,登陆百度并验证是否登陆成功
  17. NVIDIA、CUDA、CUDNN、PyTorch安装吐血整理!!!
  18. COERCE_DOUBLE的含义
  19. Google退出Android有影响吗?
  20. JAVA12_12学习总结(JavaScript)

热门文章

  1. WebBrowserProgramming - Python Wiki
  2. 业界对生成图片缩略图的做法归纳
  3. HTML5十五大新特性
  4. C examples
  5. Linux设备文件简介。
  6. 人的一生有三件事不能等
  7. next.js_Next.js手册
  8. php文件夹列表,php获取文件夹下面的文件列表和文件夹列表
  9. 关于get和post两种提交方式
  10. java培训:什么是抽象类?怎么定义?