1、简介

  高可用的分布式配置中心,即将配置中心做成一个微服务,将其集群化,从而达到高可用。config-server和config-client向eureka-server注册,且将config-server多实例集群化部署

2、改造config-server

   1、我们使用之前创建的eureka-server工程作为注册中心,端口8761

   2、我们将config-server工程,当作eureka-client,需要在pom.xml中引入spring-cloud-starter-netflix-eureka-client依赖,代码如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.lishun</groupId>
<artifactId>config-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>config-server</name>
<description>Demo project for Spring Boot</description> <parent>
<groupId>com.lishun</groupId>
<artifactId>cloud</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <dependencies>
<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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies> </project>

  3、在工程的启动类ConfigServerApplication上加上注解@EnableEurekaClient,开启eurekaclient的功能,代码如下

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

  4、在application.properties配置文件中,指定服务注册地址,代码如下

spring.application.name=config-server
server.port=8889 #spring.cloud.config.server.native.search-locations= classpath:/shared
#spring.profiles.active=native spring.cloud.config.server.git.uri=https://github.com/lis-ylfy/config-test/
spring.cloud.config.server.git.searchPaths=lis
spring.cloud.config.label=master
spring.cloud.config.server.git.username=
spring.cloud.config.server.git.password=
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/

3、改造config-client

  1、将config-client也作为eureka-client,在pom.xml文件中加入spring-cloud-starter-netflix-eureka-client依赖,在工程的启动类上加上注解@EnableEurekaClient,开启eurekaclient的功能

    2、在工程的配置文件bootstrap.properties中指定服务的注册地址为http://localhost:8761/eureka,指定向serviceId为config-server的配置服务读取配置文件,代码如下

spring.application.name=config-client
spring.cloud.config.uri= http://localhost:8888/
spring.cloud.config.fail-fast=true
spring.profiles.active=dev
server.port=8881 eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server

  3、依次启动 eureka-server、 config-server 和 config-client 工程,注意这里需要 config-server 启动成功井且向 eureka-server 注册完成后,才能启动 config-client,否则 config-client 找不到config-server 。

  4、访问http://localhost:8881/hi,浏览器显示:

config-test

  5、实现config-server的高可用

  用idea开启多个config-server实例,端口分别为8888和8889,然后再开启多个config-client实例,从控制可以看到它轮流从8888和8889两个config-server中读取了配置文件,并实现了负载均衡。

springCloud学习-高可用的分布式配置中心(Spring Cloud Config)的更多相关文章

  1. SpringCloud学习(七)高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)

    上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用 准备工作 ...

  2. 【SpringCloud】第七篇: 高可用的分布式配置中心(Spring Cloud Config)

    前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...

  3. 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)

    上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用,架构图如 ...

  4. SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)

    上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用,架构图如 ...

  5. SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)

    版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 ,博主地址:http://blog.csdn.net/forezp. http://blog.csdn.net/forezp/art ...

  6. Spring Cloud(九)高可用的分布式配置中心 Spring Cloud Config 集成 Eureka 服务

    上一篇文章,讲了SpringCloudConfig 集成Git仓库,这一篇我们讲一下SpringCloudConfig 配和 Eureka 注册中心一起使用 在分布式系统中,由于服务数量巨多,为了方便 ...

  7. Spring Cloud(八)高可用的分布式配置中心 Spring Cloud Config

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

  8. SpringCloud学习(六)分布式配置中心(Spring Cloud Config)(Finchley版本)

    在上一篇文章讲述zuul的时候,已经提到过,使用配置服务来保存各个服务的配置文件.它就是Spring Cloud Config. 简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理, ...

  9. Spring Cloud(十)高可用的分布式配置中心 Spring Cloud Config 中使用 Refresh

    上一篇文章讲了SpringCloudConfig 集成Git仓库,配和 Eureka 注册中心一起使用,但是我们会发现,修改了Git仓库的配置后,需要重启服务,才可以得到最新的配置,这一篇我们尝试使用 ...

随机推荐

  1. 【转载】同步与异步--阻塞与非阻塞型I/O

    同步阻塞IO 在这个模型中,应用程序(application)为了执行这个read操作,会调用相应的一个system call,将系统控制权交给kernel,然后就进行等待(这其实就是被阻塞了).ke ...

  2. linux下打开windows txt文件中文乱码问题 (转载)

    转自:http://blog.csdn.net/imyang2007/article/details/7448177 在linux操作系统下,我们有时打开在windows下的txt文件,发现在wind ...

  3. [Swift通天遁地]七、数据与安全-(14)使用单元测试进行邮箱格式的验证

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  4. C# 工厂单例

     public class BusinessFactory    {        private static BusinessFactory instance = null;        pri ...

  5. Centos7下安装python环境

    前言 centos7默认是装有pyhton的. #检查python版本 [root@oldboy_python ~ ::]#python -V Python 但是众所周知,python2版本到2020 ...

  6. docker容器如何安装vim

    mv /etc/apt/sources.list /etc/apt/sources.list.bak && \     echo "deb http://mirrors.16 ...

  7. [转] 64位Oracle 11g R2的客户端连接时报ORA-01019错误

    本文转自:http://blog.csdn.net/downmoon/article/details/8038583 在Win8企业版64位环境下,连接Oracle11g 服务端,搞了整整两天,特将过 ...

  8. vs2010 视图 aspx页面设计窗口创建控件时出错 未将对象引用设置到对象的实例

    第一步,首先关闭aspx页面 第二步,在单击项目右击,选择“清理” 第三步,然后在打开aspx页面,就可以看到正常的页面了. 注:一次不行的会,多做几次. 如果还是不行的话,你看看你.cs页面是否继承 ...

  9. conda python虚拟环境

    #查看已安装的python包 conda list #查看当前有哪些虚拟环境 conda env list 或者 conda info -e #更新conda conda update conda # ...

  10. html5——2D转换

    transform 属性 1.向元素应用 2D 或 3D 转换 2.该属性允许我们对元素进行旋转.缩放.移动或倾斜. 缩放与位移 transform: scale(, 0.5);//水平缩放,垂直缩放 ...