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,这里托管着应用的一些配置文 ...
随机推荐
- 在HTML中使用JavaScript(浏览器对js的加载机制分析)
前言: 向HTML页面中插入JavaScrip的主要方法,就是使用<script>标签.主要探讨<script>标签的在HTML页面的渲染机制.对应的业务场景:从js的加载机制 ...
- mysql jdbc8.0连接mysql
- odoo源生打印【web report】
https://www.odoo.com/documentation/12.0/reference/reports.html 具体的看官方文档 一.纸张格式设置: <record id= ...
- 在Python中执行普通除法
如果希望Python只执行普通的除法,那么可以在程序前加上以下语句: 1 from _future_ import division 如果通过命令行(比如在Linux系统上)运行Python,可以使用 ...
- Spring最简单构建一个后台{msg:"登录成功",code:200,data:null}
一.简介 {msg:"登录成功",code:200,data:null} 二.两种请求 如果严格msg code data也带"" @RestControlle ...
- Django GIS SQL注入漏洞(CVE-2020-9402)
影响版本 Django 1.11.29之前的1.11.x版本.2.2.11之前的2.2.x版本和3.0.4之前的3.0.x版本中存在SQL注入漏洞 提示有admin.vuln.vuln2,3个页面,存 ...
- FastAPI:一个测试人员视角的教程
前言 教程肯定谈不上了,主要还是就自己的理解分享内容而已 内容是连官方文档的基础教程都没涵盖起的 建议直接看官方文档 以个人视角来分享,希望各位通过这个可以写接口了 需要自取 完整视频链接:https ...
- Python小白的数学建模课-12.非线性规划
非线性规划是指目标函数或约束条件中包含非线性函数的规划问题,实际就是非线性最优化问题. 从线性规划到非线性规划,不仅是数学方法的差异,更是解决问题的思想方法的转变. 非线性规划问题没有统一的通用方法, ...
- 在nodejs中利用 Proxy监听对象值的获取
1 window = new Proxy(global, { 2 get: function (target, key, receiver) { 3 console.log("window. ...
- shell的编程规范和变量
目录 一.Shell脚本概述 1.shell脚本的概念 2.shell脚本应用场景 3.shell的作用--命令翻译器,"翻译官" 二.用户的登录shell 三.shell脚本的构 ...