方案一:传统作法(不推荐)

  服务端负载均衡

    将所有的Config Server都指向同一个Git仓库,这样所有的配置内容就通过统一的共享文件系统来维护,而客户端在指定Config Server位置时,只要配置Config Server外的均衡负载即可。

    注:服务器端负载均衡和客户端负载均衡的区别

  存在的问题:

    客户端都是直接调用配置中心的server端来获取配置文件信息。这样就存在了一个问题,客户端和服务端的耦合性太高,如果server端要做集群,客户端只能通过原始的方式来路由,server端改变IP地址的时候,客户端也需要修改配置,不符合springcloud服务治理的理念。

方案二:把config-server注册为服务(推荐)

  将server端当做一个服务注册到eureka中,client端去eureka中去获取配置中心server端的服务既可。

一、config-server配置

  1.添加依赖

  加入了spring-cloud-starter-eureka,用来注册服务

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>

  2.配置文件

  在配置文件中添加eureka.client.serviceUrl.defaultZone以指定服务注册中心的位置

server:
port: 8001
spring:
application:
name: spring-cloud-config-server
cloud:
config:
server:
git:
uri: # 配置git仓库的地址
search-paths: # git仓库地址下的相对地址,可以配置多个,用,分割。
username: # git仓库的账号
password: # git仓库的密码
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8000/eureka/ ## 注册中心eurka地址

  高可用:复制一份配置,把端口为8003

  3.启动类

  启动类添加@EnableDiscoveryClient激活对配置中心的支持,用来将config-server注册到上面配置的服务注册中心上去。

@EnableDiscoveryClient
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication { public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}

  测试是否成功,参考上一篇:六、springcloud之配置中心Config

二、config-client配置

  1.添加依赖

    添加spring-cloud-starter-eureka依赖,用来注册服务:

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

  2.配置文件

  application.yml如下:

spring:
application:
name: spring-cloud-config-client
server:
port: 8002

  bootstrap.properties如下:

spring:
cloud:
config:
        name: "config-test"
lab: master
profile: dev
discovery:
  enabled: true
  service-id: spring-cloud-config-server
eureka:
   client:
   serviceUrl:
           defaultZone: http://localhost/8000/eureka/

  主要是去掉了spring.cloud.config.uri直接指向server端地址的配置,增加了最后的三个配置:

  • spring.cloud.config.discovery.enabled :开启Config服务发现支持
  • spring.cloud.config.discovery.serviceId :指定server端的name,也就是server端spring.application.name的值
  • eureka.client.serviceUrl.defaultZone :指向配置中心的地址

  这三个配置文件都需要放到bootstrap.yml的配置中

  3.启动类

    启动类添加@EnableDiscoveryClient激活对配置中心的支持

@EnableDiscoveryClient
@SpringBootApplication
public class ConfigClientApplication { public static void main(String[] args) {
SpringApplication.run(ConfigClientApplication.class, args);
}
}

    启动client端,在浏览器中访问:http://localhost:8000/ 就会看到server端和client端都已经注册了到注册中心了。

    停掉一个server,还可以访问,说明高可用集群搭建成功

参考:http://blog.didispace.com/springcloud4-2/

   http://www.ityouknow.com/springcloud/2017/05/25/springcloud-config-eureka.html

七、springcloud之配置中心Config(二)之高可用集群的更多相关文章

  1. (七) Docker 部署 MySql8.0 一主一从 高可用集群

    参考并感谢 官方文档 https://hub.docker.com/_/mysql y0ngb1n https://www.jianshu.com/p/0439206e1f28 vito0319 ht ...

  2. 基于 kubeadm 搭建高可用的kubernetes 1.18.2 (k8s)集群二 搭建高可用集群

    1. 部署keepalived - apiserver高可用(任选两个master节点) 1.1 安装keepalived # 在两个主节点上安装keepalived(一主一备) $ yum inst ...

  3. Spring Cloud(八):配置中心(服务化与高可用)【Finchley 版】

    Spring Cloud(八):配置中心(服务化与高可用)[Finchley 版]  发表于 2018-04-19 |  更新于 2018-04-26 |  本文接之前的<Spring Clou ...

  4. SpringCloud全家桶学习之服务注册与发现及Eureka高可用集群搭建(二)

    一.Eureka服务注册与发现 (1)Eureka是什么? Eureka是NetFlix的一个子模块,也是核心模块之一.Eureka是一个基于REST的服务,用于定位服务,以实现云端中间层服务发现和故 ...

  5. Eureka注册中心高可用集群配置

    Eureka高可用集群配置 当注册中心扛不住高并发的时候,这时候 要用集群来扛: 我们再新建两个module  microservice-eureka-server-2002  microservic ...

  6. SpringCloud(四):服务注册中心Eureka Eureka高可用集群搭建 Eureka自我保护机制

    第四章:服务注册中心 Eureka 4-1. Eureka 注册中心高可用集群概述在微服务架构的这种分布式系统中,我们要充分考虑各个微服务组件的高可用性 问题,不能有单点故障,由于注册中心 eurek ...

  7. Redis安装、主从配置及两种高可用集群搭建

    Redis安装.主从配置及两种高可用集群搭建 一.            准备 Kali Linux虚拟机 三台:192.168.154.129.192.168.154.130.192.168.154 ...

  8. spring cloud 服务注册中心eureka高可用集群搭建

    spring cloud 服务注册中心eureka高可用集群搭建 一,准备工作 eureka可以类比zookeeper,本文用三台机器搭建集群,也就是说要启动三个eureka注册中心 1 本文三台eu ...

  9. MongoDB 3.4 高可用集群搭建(二)replica set 副本集

    转自:http://www.lanceyan.com/tech/mongodb/mongodb_repset1.html 在上一篇文章<MongoDB 3.4 高可用集群搭建(一):主从模式&g ...

随机推荐

  1. 【CF472G】Design Tutorial: Increase the Constraints

    Description 给出两个01序列\(A\)和\(B\) 要求回答\(q\)个询问每次询问\(A\)和\(B\)中两个长度为\(len\)的子串的哈明距离 ​ 哈明距离的值即有多少个位置不相等 ...

  2. JavaScript匿名函数知多少

    在一些Javascript库中可以看见这种写法: function(){ //所有库代码代码 }(); 这样写的一个目的是——封装. JavaScript并不是面向对象的,所以它不支持封装.但是在不支 ...

  3. E - Down or Right Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    http://codeforces.com/contest/1023/problem/E 交互题 #include <cstdio> #include <cstdlib> #i ...

  4. c++ 宏多态 动态多态和静态多态(转载)

    转载出处:通道 多态(polymorphism)一词最初来源于希腊语polumorphos,含义是具有多种形式或形态的情形.在程序设计领域,一个广泛认可的定义是“一种将不同的特殊行为和单个泛化记号相关 ...

  5. 一、初识java

    理论性的东西就不在笔记中作为纪录了. 先来解释下java安装过程中的一些问题,java安装和环境配置不多做强调,可以参考http://www.cnblogs.com/JianXu/p/5158404. ...

  6. Ansible9:条件语句

    目录 一.when 1.基本用法 2.在when中使用jinja2的语法 3.使用bool值作为when的判断条件 4.在when中使用defined关键字 5.when在循环语句中的使用方法 6.在 ...

  7. Ansible7:Playbook常用模块

    目录 template set_fact pause wait_for assemble add_host group_by debug fail playbook的模块与在ansible命令行下使用 ...

  8. Docker简介和安装(一)

    Docker简介 Docker 是 Docker.Inc 公司开源的一个基于 LXC技术之上构建的Container容器引擎, 源代码托管在 GitHub 上, 基于Go语言并遵从Apache2.0协 ...

  9. day17 包装类、日期类

    包装类 作用:1.丰富了基本数据类型只能存放值的问题,还提供了大量的方法或常量. 2.包装类充当了基本数据类型和引用数据类型转换的桥梁. 应用层面:包装类.String.基本数据类型的互相转换. 1. ...

  10. jQuery中使用attribute,prop获取,设置input的checked值

    1.prop方法获取.设置checked属性 当input控件checkbox设置了checked属性时,无论checked=”“或 checked=”checked”,$(obj).prop(“ch ...