分布式配置中心

分布式配置中心

一分钟学会分布式配置中心spring cloud config

1. 简介

Spring Cloud Config为服务端和客户端提供了分布式系统的外部化配置支持。配置服务器为各应用的所有环境提供了一个中心化的外部配置。它实现了对服务端和客户端对Spring Environment和PropertySource抽象的映射,所以它除了适用于Spring构建的应用程序,也可以在任何其他语言运行的应用程序中使用SpringCloud是个集大成的东西


举一反三:

百度开发的 分布式配置中心:disconf支持配置(配置项+配置文件)的分布式化管理】。包括滴滴出行、银联、网易、拉勾网、苏宁易购、等知名互联网公司正在使用。

· 文档: http://disconf.readthedocs.io

淘宝分布式配置 管理服务 Diamond   携程 :apollo(阿波罗)

2. 微服务中雪崩效应

 

解决方案:断路器

3. 什么是分布式

不同模块,部署在不同的机器上。解决办法是高并发问题。

所有的服务部署在N多个tomcat上。

4. 如何配置

 

To run your own server use the spring-cloud-config-server dependency and @EnableConfigServer.

要运行您自己的服务器,请使用spring -cloud-config- server依赖项和@ enableconfigserver

 

Maven的配置  代码文档:https://projects.spring.io/spring-cloud/

 

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
</parent>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Dalston.SR4</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>
</dependencies>

 

Springboot的程序怎么运行?

Main方法加个注解@EnableConfigServer @SpringBootApplication

 实例:

package cn.et;

 

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.config.server.EnableConfigServer;

@EnableConfigServer

@SpringBootApplication

public class Main {

public static void main(String[] args) {

SpringApplication.run(Main.class, args);

}

}

(二)

配置仓库的内容 application.properties

spring.cloud.config.server.git.uri=https://github.com/dalong1029/cs.git

一般不需要后缀,所以去掉.git

当我一启动这个项目的时候,相当于启动分布式配置中心。

 

 

application.properties

spring.jpa.show-sql=true

server.port=80

server.context-path=/sb

spring.devtools.restart.enabled=true

#debug=true

bootstrap.properties:

spring.cloud.config.uri=http://localhost:8089

spring.application.name=jdbc

spring.profiles.active=dev

 

总结:分布式配置中心以后在公司,铁定会用到的,搭建一个分布式配置中的的服务一点都不复杂。

无非就是一个@EnableConfigServer,然后在github建一个仓库,

application.properties配置文件中,把这个仓库关联起来,就OK

在任何一个程序中加一个bootstrap.properties,完成如上图配置,通过@value抓取过来,其它操作自己玩。

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值