springCloud学习-高可用的分布式配置中心(Spring Cloud Config)
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)的更多相关文章
- SpringCloud学习(七)高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用 准备工作 ...
- 【SpringCloud】第七篇: 高可用的分布式配置中心(Spring Cloud Config)
前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用,架构图如 ...
- SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用,架构图如 ...
- SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 ,博主地址:http://blog.csdn.net/forezp. http://blog.csdn.net/forezp/art ...
- Spring Cloud(九)高可用的分布式配置中心 Spring Cloud Config 集成 Eureka 服务
上一篇文章,讲了SpringCloudConfig 集成Git仓库,这一篇我们讲一下SpringCloudConfig 配和 Eureka 注册中心一起使用 在分布式系统中,由于服务数量巨多,为了方便 ...
- Spring Cloud(八)高可用的分布式配置中心 Spring Cloud Config
在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config,它支持配 ...
- SpringCloud学习(六)分布式配置中心(Spring Cloud Config)(Finchley版本)
在上一篇文章讲述zuul的时候,已经提到过,使用配置服务来保存各个服务的配置文件.它就是Spring Cloud Config. 简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理, ...
- Spring Cloud(十)高可用的分布式配置中心 Spring Cloud Config 中使用 Refresh
上一篇文章讲了SpringCloudConfig 集成Git仓库,配和 Eureka 注册中心一起使用,但是我们会发现,修改了Git仓库的配置后,需要重启服务,才可以得到最新的配置,这一篇我们尝试使用 ...
随机推荐
- 利用SSL For Free工具3分钟获取Let's Encrypt免费SSL证书
https://www.sslforfree.com/
- Linux基础命令第二波
第1章 Linux启动过程 开机自检(BIOS)##硬件检查 MBR引导 GRUB菜单(选择不同的内核) 加载内核 运行init进程(Linux系统里面第一个进程) 读取/etc/inittab配置文 ...
- [Apple开发者帐户帮助]七、注册设备(1)注册一个设备
您需要已注册的设备来创建开发或临时配置文件.要使用开发人员帐户注册设备,您需要拥有设备名称和设备ID. 注意:如果您使用自动签名,Xcode会为您注册连接的设备.Xcode Server也可以配置为注 ...
- hihocode 编程练习赛17
1. f1 score 首先了解f1 score的计算方法, 我记得是学信息检索知道的, 然后简单处理就行. 由于我写的比较麻烦, 中间处理过程引入了一些除数为0的情况,导致错了很多次.其实是很简单的 ...
- Js打开QQ聊天对话窗口
function openQQ() { var qq = $(this).attr('data-qq');//获取qq号 window.open('http://wpa.qq.com/msgrd?v= ...
- C#学习-图片的处理
1.在图片上加防伪标记 private void btnAddString_Click(object sender, EventArgs e) { //以流的方式,获取一张图片 using (File ...
- DML和DQL语句
DML操作: a.插入单行数据: INSERT INTO 表名(列名,列名,...) VALUE(列值,列值,...); 表的字段名是可选的,如果省略,则一次插入所有字段 多个列表和多个值之 ...
- [ ZJOI 2006 ] Mahjong
\(\\\) \(Description\) 现有权值分别为\(1\text~100\)的\(100\)种牌,分别给出每种排的张数\(A_i\),试判断能否胡牌,胡牌需要将所有牌不重不漏地分成以下几类 ...
- VC socket api使用引入
1.在创建项目时勾上windows socket api的使用 2.头文件 #pragma comment(lib,"WS2_32.lib") 3.初始化 WSADATA dat ...
- CSS3 background-origin 属性
CSS3 background-origin 属性 padding-box 背景图像相对于内边距框来定位. border-box 背景图像相对于边框盒来定位. content-box 背景图像相对于内 ...