SpringCloud分布式配置中心Config
统一管理所有配置。

1、微服务下的分布式配置中心
简介:讲解什么是配置中心及使用前后的好处
什么是配置中心:
一句话:统一管理配置, 快速切换各个环境的配置
相关产品:
百度的disconf
地址:https://github.com/knightliao/disconf
阿里的diamand
地址:https://github.com/takeseem/diamond
springcloud的configs-server:
地址:http://cloud.spring.io/spring-cloud-config/
推荐干货文章:http://jm.taobao.org/2016/09/28/an-article-about-config-center/
2、SpringCloud的配置中心组件config-server
简介:讲解SpringCloud配置中心config-server
1、新建项目,创建config-server,pom依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
2、启动类增加注解
@EnableConfigServer
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication { public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
yml 配置:
#服务名称
spring:
application:
name: config-server #服务的端口号
server:
port: 9100 #指定注册中心地址
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
以上配置启动会出现错误 Caused by: java.lang.IllegalStateException: You need to configure a uri for the git repository, 还需制定url
3、使用git服务器结合Config搭建分布式配置中心
简介:讲解使用git服务器结合Config搭建分布式配置中心
1、默认使用git存储配置中心
使用git服务器,可以自己搭建gitlab服务器
或者使用github、开源中国git、阿里云git
xxxx@qq.com
xxx.net123
https://gitee.com/waitforxy/config_cloud.git
2、配置文件添加配置
spring:
application:
name: config-server
#git配置
cloud:
config:
server:
git:
uri: https://gitee.com/waitforxy/config_cloud
username: xxxx@qq.com
password: xxxx.net123
#超时时间
timeout: 5
#分支
default-label: master
3、访问方式(一定要注意语法,如果有问题,会出错)
多种访问路径,可以通过启动日志去查看
例子 http://localhost:9100/product-service.yml
/{name}-{profiles}.properties
/{name}-{profiles}.yml
/{name}-{profiles}.json
/{label}/{name}-{profiles}.yml
name 服务器名称
profile 环境名称,开发、测试、生产
lable 仓库分支、默认master分支
4、分布式配置中心客户端使用
简介:微服务里面客户端接入配置中心
官方文档:http://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html#_spring_cloud_config_client
1、加入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
2、修改对应服务的配置文件,把application.yml 改为 bootstrap.yml(优先级问题)
#指定注册中心地址
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
#服务的名称
spring:
application:
name: product-service
#指定从哪个配置中心读取
cloud:
config:
discovery:
service-id: CONFIG-SERVER
enabled: true
profile: test
#建议用lable,而不用profile去区分环境,默认是lable是master分支
#label: test
注意点:
1.配置文件要用bootstrap.yml
2.默认读取文件名是 服务名称
SpringCloud分布式配置中心Config的更多相关文章
- Spring-cloud微服务实战【九】:分布式配置中心config
回忆一下,在前面的文章中,我们使用了spring cloud eureka/ribbon/feign/hystrix/zuul搭建了一个完整的微服务系统,不管是队内还是对外都已经比较完善了,那我们 ...
- SpringCloud 分布式配置中心
SpringCloud 分布式配置中心 服务端 创建工程并完善结构 国际惯例,把maven工程创建完善 pom.xml <?xml version="1.0" encodin ...
- 七、springcloud之配置中心Config(二)之高可用集群
方案一:传统作法(不推荐) 服务端负载均衡 将所有的Config Server都指向同一个Git仓库,这样所有的配置内容就通过统一的共享文件系统来维护,而客户端在指定Config Server位置时, ...
- SpringCloud全家桶学习之分布式配置中心----Config(七)
一.概述 (1)背景 微服务意味着将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中出现大量的服务.由于每个服务都需要配置必要的配置信息才能运行,所以一套集中式的.动态的配置管理 ...
- Spring Cloud第十篇 | 分布式配置中心Config
本文是Spring Cloud专栏的第十篇文章,了解前九篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Clo ...
- SpringCloud分布式配置中心
一.什么是配置中心 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud c ...
- 六、springcloud之配置中心Config
一.配置中心提供的核心功能 Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持.配置服务器为各应用的所有环境提供了一个中心化的外部配置.它实现了对服务端和客户端对S ...
- SpringCloud-高可用的分布式配置中心(config)
当服务实例很多时,都从配置中心读取文件,这是可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用 新建一个注册中心 pom如下 <?xml version="1.0" ...
- springcloud(四):应用配置中心config的安全设置
springcloud应用配置中心config的安全设置 在springcloud应用开发中,为了方便在线管理我们的配置文件,通常会配一个配置中心config-server,这里托管着应用的一些配置文 ...
随机推荐
- Shiro精通学习——【第一集:入门】
入门: main方法直接执行:https://blog.csdn.net/a907691592/article/details/80559904 使用配置文件方式:https://blog.csdn. ...
- github在不同电脑上协同开发
当我换了电脑后,开发自己的github项目遇到了一些问题. 首先,git clone 'repository url'拉取下来项目,开始开发项目发.修改了一些文件后,当要git commit, git ...
- SpringBoot中时间格式化的5种方法!
在我们日常工作中,时间格式化是一件经常遇到的事儿,所以本文我们就来盘点一下 Spring Boot 中时间格式化的几种方法. 时间问题演示 为了方便演示,我写了一个简单 Spring Boot 项 ...
- Leetcode:1008. 先序遍历构造二叉树
Leetcode:1008. 先序遍历构造二叉树 Leetcode:1008. 先序遍历构造二叉树 思路 既然给了一个遍历结果让我们建树,那就是要需要前序中序建树咯~ 题目给的树是一颗BST树,说明中 ...
- HCNA Routing&Switching之OSPF度量值和基础配置命令总结
前文我们了解了OSPF的网络类型,OSPF中的DR和BDR的选举规则.作用等相关话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/15054938.html: ...
- 构建前端第9篇之(下)---vue3.0将template转化为render的过程
vue3.0将template转化为render的过程 这里是简单标记下,如何将.vue转换成js文件 具体的,先不研究了,太深,能力有限,达不到呢
- JS系统函数
1. parseInt--转为整型 2. parseFloat--转为浮点型 3. Number--转为数字型 4. isFinite()--检测一个值是否为有限值,如果是返回true,否则就是Inf ...
- Windows API 进程相关笔记
0. 前言 最近做了一个进程信息相关的项目,整理了一下自己做项目时的笔记,分享给大家 1. 相关概念 1.1 HANDLE 概念 HANDLE(句柄)是Windows操作系统中的一个概念. 在Wind ...
- 浅谈Java迭代器
迭代器Iterator 概述: 迭代器(Iterator):它不是一个容器,它是一种用于访问容器的方法,可用于迭代 List.Set和Map等容器. 迭代:一个一个的往外拿. 作用:帮我们遍历或者拿到 ...
- Dired Mode in Emacs
Start up Dired mode: C-x d; (List dirs: C-x C-d) Hide Dired mode window: q; Mark Mark (for group man ...