统一管理所有配置。

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的更多相关文章

  1. Spring-cloud微服务实战【九】:分布式配置中心config

      回忆一下,在前面的文章中,我们使用了spring cloud eureka/ribbon/feign/hystrix/zuul搭建了一个完整的微服务系统,不管是队内还是对外都已经比较完善了,那我们 ...

  2. SpringCloud 分布式配置中心

    SpringCloud 分布式配置中心 服务端 创建工程并完善结构 国际惯例,把maven工程创建完善 pom.xml <?xml version="1.0" encodin ...

  3. 七、springcloud之配置中心Config(二)之高可用集群

    方案一:传统作法(不推荐) 服务端负载均衡 将所有的Config Server都指向同一个Git仓库,这样所有的配置内容就通过统一的共享文件系统来维护,而客户端在指定Config Server位置时, ...

  4. SpringCloud全家桶学习之分布式配置中心----Config(七)

    一.概述 (1)背景 微服务意味着将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中出现大量的服务.由于每个服务都需要配置必要的配置信息才能运行,所以一套集中式的.动态的配置管理 ...

  5. Spring Cloud第十篇 | 分布式配置中心Config

    ​ 本文是Spring Cloud专栏的第十篇文章,了解前九篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Clo ...

  6. SpringCloud分布式配置中心

    一.什么是配置中心 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud c ...

  7. 六、springcloud之配置中心Config

    一.配置中心提供的核心功能 Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持.配置服务器为各应用的所有环境提供了一个中心化的外部配置.它实现了对服务端和客户端对S ...

  8. SpringCloud-高可用的分布式配置中心(config)

    当服务实例很多时,都从配置中心读取文件,这是可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用 新建一个注册中心 pom如下 <?xml version="1.0" ...

  9. springcloud(四):应用配置中心config的安全设置

    springcloud应用配置中心config的安全设置 在springcloud应用开发中,为了方便在线管理我们的配置文件,通常会配一个配置中心config-server,这里托管着应用的一些配置文 ...

随机推荐

  1. 理解并掌握Promise的用法

    前沿:  Promise在处理异步操作非常有用.项目中,与后端进行数据请求的时候经常要用到Promise.我们可以用promise + xhr进行ajax的封装.也可以使用基于promise封装的请求 ...

  2. python -- 程序异常与调试(程序调试)

    一.程序调试 A.使用assert语句检测程序代码中的错误. assert 表达式[, 参数] 如果表达式为True,则继续往下运行:如果为False,则抛出一个AssertionError异常,并且 ...

  3. 解析ArrayList的底层实现(上)

    private static final long serialVersionUID = 8683452581122892189L;//唯一序列号ID private static final int ...

  4. CentOS 永久修改系统时间

    1.查看当前系统时间 date       2.修改当前系统时间 date -s "2018-2-22 19:10:30       3.查看硬件时间 hwclock --show      ...

  5. Java 在Word中创建多级项目符号列表和编号列表

    本文分享通过Java程序代码在Word中创建多级项目符号列表和编号列表的方法.程序运行环境如下: IntelliJ IDEA 2018(JDK 1.8.0) Word 2013 Word Jar包:F ...

  6. CSS实现隐藏滚动条并可以滚动内容

    方法一: 计算滚动条宽度并隐藏起来,其实我只是把滚动条通过定位把它隐藏了起来,下面给一个简化版的代码: <div class="outer-container"> &l ...

  7. Golang中如何正确的使用sarama包操作Kafka?

    Golang中如何正确的使用sarama包操作Kafka? 一.背景 在一些业务系统中,模块之间通过引入Kafka解藕,拿IM举例(图来源): 用户A给B发送消息,msg_gateway收到消息后,投 ...

  8. Redis是不是真的变慢了?

    大家好,今天我们来学习一下如何确定Redis是不是真的变慢了. 我们在使用redis时一定会遇到变慢的时候,那我们如何来判断Redis是否真的变慢了呢, 一个最直接的方法就是查看Redis的响应延迟, ...

  9. let 及const

    ES5中的块级作用域 ES5中只有全局作用域和函数作用域,这样带来了很多的不便利,会出现内层变量被外层变量覆盖,循环体中的变量会暴露在全局,很多情况下需要自执行函数来私有化变量. ES6块级的作用域 ...

  10. Java基础技术-Java其他主题【面试】

    Java基础技术-Java其他主题[面试] Java基础技术IO与队列 Java BIO.NIO.AIO Java 中 BIO.NIO.AIO 的区别是什么? 含义不同: BIO(Blocking I ...