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,这里托管着应用的一些配置文 ...
随机推荐
- 学习Git的基本业务逻辑
1,基本业务逻辑(假设针对index.html文件中内容): 1,在init版本库之前已写好开头部分:index 对index进行git init版本库: 进入到文件夹中,git init git a ...
- golang拾遗:内置函数len的小知识
len是很常用的内置函数,可以测量字符串.slice.array.channel以及map的长度/元素个数. 不过你真的了解len吗?也许还有一些你不知道的小知识. 我们来看一道GO101的题目,这题 ...
- python开发,注意事项
提高python代码运行效率 1.使用生成器,节约内存.[一边循环一边计算的机制,称为生成器:generator] 例: .如何创建生成器 1.只要把一个列表生成式的[]改成(),就创建了一个gene ...
- 【原创】case、casez和casex谁是谁
在Verilog中case语句经常用于多分支表决的结构,case后的表达式会与各分支表达式"全等"那么对应的分支会被执行.其基本结构如下: case(expression) exp ...
- js学习笔记之日期倒计时(天,时,分,秒)
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- QT常用控件(一)——菜单栏和对话框
引言 QMainWindow 是一个为用户提供主窗口程序的类,包含一个菜单栏(menu bar).多个工具栏(tool bars).多个锚接部件(dock widgets).一个状态栏(status ...
- 关于C语言中对数字的扩展和缩短
关于对数字的扩展:如果需要在不改变他的类型的情况下去扩展一个数字 有符号数字: 如果最高位为0---向左按位复制0 如果最高位为1---向左按位复制1 无符号数字:向左按位复制0即可 对于数字的缩短: ...
- ASP.NET Core下FreeSql的仓储事务
ASP.NET Core下FreeSql的仓储事务 第一步:配置 Startup.cs 注入 引入包 dotnet add package FreeSql dotnet add package Fre ...
- Javas数组03——数组的使用
Javas数组--数组的使用 1.普通的for循环 2.for-each循环 3.数组做方法入参 4.数组做返回值 例子1--普通for循环 package array; public clas ...
- badboy如何录制jmetet脚本
网盘下载: https://pan.baidu.com/s/1mTOEeE47tmk29_wndID3iw 傻瓜式安装即可, 内附教程 1. 打开Badboy, 新建一个文件 2. 输入要录制的网址 ...