统一管理所有配置。

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. [刘阳Java]_处理并发有哪些方法

    1.HTML静态化 ,将活动页面上的所有可以静态的元素全部静态化,并尽量减少动态元素2.禁止重复提交:用户提交之后按钮置灰,禁止重复提交3.用户限流:在某一时间段内只允许用户提交一次请求,比如可以采取 ...

  2. PAT乙级:1072开学寄语(20分)

    PAT乙级:1072开学寄语(20分) 题干 下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面 ...

  3. WLS中Linux与Windows间的环境共享

    Reference 更多cmd.exe帮助参考 (cmd_helps)[https://ss64.com/nt/cmd.html] (WSL备份,windows Docker安装)[https://w ...

  4. synchronized锁机制(六)

    前言 1.理解同步关键词synchronized 2.同步方法与同步代码块的区别 3.理解锁的对象this 脏读 一个常见的概念.在多线程中,难免会出现在多个线程中对同一个对象的实例变量进行并发访问的 ...

  5. Discuz 7.x/6.x 全局变量防御绕过导致代码执行

    地址 http://192.168.49.2:8080/viewthread.php?tid=13&extra=page%3D1 安装成功后,找一个已存在的帖子,向其发送数据包,并在Cooki ...

  6. 不想用Spring全家桶?试试这个国产JFinal框架

    前言 逃离北上广从广州回老家南宁,入职这家公司用的技术是JFinal,借此机会得以学习这个国产的MVC框架,经过一段时间的学习,基于之前的经验搭建一个通用项目jfinal-demo jfinal-de ...

  7. MVC从客户端中检测到有潜在危险的Request.Form值的解决方法

    1.ASPX页面 在页面头部的page中加入ValidateRequest="false" 2.web.config中配置validateRequest="false&q ...

  8. Centos忘记密码怎么修改

    使用Centos系统忘记密码 在我们日常使用Centos系统时,有些人不免会出现一个共同的问题:忘记登录密码! 我们总不能再重装一遍吧! 接下来我们就分两种情况来看看: Centos系统在云服务器 C ...

  9. Android无障碍宝典-talkback

    http://geek.csdn.net/news/detail/93269 http://geek.csdn.net/news/detail/135867

  10. connect()函数阻塞问题

    方法一:采用select 在学习嵌入式Linux网络编程中,很多同学都发现了一个问题,那就是调用connect函数时,如果服务端关闭,客户 端调用connect()函数时,发现阻塞在那里,而且利用ct ...