史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用,架构图如下:
一、改造config-server
在现有项目基础上,改造。
在其pom.xml文件加上Eureka的起步依赖spring-cloud-starter-eureka,代码如下:
<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> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
最后需要在启动类Application加上@EnableConfigServer,@EnableEurekaClient的注解。
@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
二、改造config-client
将其注册微到服务注册中心,作为Eureka客户端,需要pom文件加上起步依赖spring-cloud-starter-netflix-eureka-server,代码如下:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
配置文件bootstrap.properties,注意是bootstrap。注解一行,不使用ip注册到服务中,使用服务名"config-server"。
server.port=8881
spring.application.name=config-client #开启配置服务发现,从配置中心读取文件
spring.cloud.config.discovery.enabled=true
#配置服务实例名称
spring.cloud.config.discovery.serviceId=config-server
spring.cloud.config.label=master #目前可选值有[dev,prod]
spring.cloud.config.profile=dev #注释掉下面这行,使用"config-server"服务名来注册
#spring.cloud.config.uri= http://localhost:8888/
- spring.cloud.config.discovery.enabled 是从配置中心读取文件。
- spring.cloud.config.discovery.serviceId 配置中心的servieId,即服务名。
这时发现,在读取配置文件不再写ip地址,而是服务名,这时如果配置服务部署多份,通过负载均衡,从而高可用。
依次启动eureka-servr,config-server,config-client
访问网址:http://localhost:8888
访问http://localhost:8881/test,浏览器显示:
我的名字是:devEnv,年龄是11
本文源码下载:
https://github.com/forezp/SpringCloudLearning/tree/master/chapter7
史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)的更多相关文章
- SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用,架构图如 ...
- SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 ,博主地址:http://blog.csdn.net/forezp. http://blog.csdn.net/forezp/art ...
- 【SpringCloud】第七篇: 高可用的分布式配置中心(Spring Cloud Config)
前言: 必需学会SpringBoot基础知识 简介: spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选. ...
- SpringCloud学习(七)高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用 准备工作 ...
- 史上最简单的SpringCloud教程 | 第十篇: 高可用的服务注册中心(Finchley版本)
转载请标明出处: 原文首发于 https://www.fangzhipeng.com/springcloud/2018/08/30/sc-f10-eureka/ 本文出自方志朋的博客 文章 史上最简单 ...
- springCloud学习-高可用的分布式配置中心(Spring Cloud Config)
1.简介 高可用的分布式配置中心,即将配置中心做成一个微服务,将其集群化,从而达到高可用.config-server和config-client向eureka-server注册,且将config-se ...
- 史上最简单的SpringCloud教程 | 第三篇: 服务消费者(Feign)
转载请标明出处: https://www.fangzhipeng.com/springcloud/2017/07/12/sc03-feign/ 本文出自方志朋的博客 最新Finchley版本请访问: ...
- 史上最简单的 SpringCloud 教程
史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)史上最简单的SpringCloud教程 | 第二篇: 服务消费者(rest+ribbon)史上最简单的Spri ...
- 史上最简单的 SpringCloud 教程 | 终章
https://blog.csdn.net/forezp/article/details/70148833转载请标明出处:http://blog.csdn.net/forezp/article/det ...
随机推荐
- MySQL触发器trigger的使用
https://www.cnblogs.com/geaozhang/p/6819648.html 触发器的触发 语句的错误 和 触发器里面 错误 都不会运行 NEW与OLD详解 MySQL 中定义了 ...
- 【Ubuntu】如何修改IP
前几天有幸捣鼓了一下Ubuntu系统,和Linux系统差不多,在这里说说如何修改IP 1,首先使用命令ifconfig查看当前IP,如图 2,编辑文件,输入命令 ...
- Linux后门权限维持手法
0x01 Linux 1. 预加载型动态链接库后门 inux操作系统的动态链接库在加载过程中,动态链接器会先读取LD_PRELOAD环境变量和默认配置文件/etc/ld.so.preload,并将读取 ...
- C++设计模式之工厂模式(1)
关于设计模式的作用: “帮助我们将应用组织成容易了解,容易维护,具有弹性的架构,建立可维护的OO系统,要诀在于随时想到系统以后可能需要的变化以及应付变化的原则.” 具体可参考:https://www. ...
- FAT文件系统规范v1.03学习笔记---3.根目录区之FAT目录项结构
1.前言 本文主要是对Microsoft Extensible Firmware Initiative FAT32 File System Specification中文翻译版的学习笔记. 每个FAT ...
- Linux 文件系统IO性能优化【转】
转自:https://blog.csdn.net/doitsjz/article/details/50837569 对于LINUX SA来说,服务器性能是需要我们特别关注的,包括CPU.IO.内存等等 ...
- awk输出单引号,双引号【转】
双引号: awk '{print "\""}' #放大:awk '{print " \" "}' 使用“”双引号把一个双引 ...
- HTTP协议02-请求和响应的报文构成
HTTP协议和TCP/IP协议族内的其他众多协议相同,用于客户端与服务器之间的通信,请求访问文本或图像等资源的一端+称为客户端,而提供资源响应的一端称为服务端. 应用HTTP协议时,请求必定是客户端发 ...
- python3+selenium入门05-元素操作及常用方法
学习了元素定位之后,来看一些元素的操作,还有一些常用的方法 clear()清空输入框内容 click()点击 send_keys()键盘输入 import time from selenium imp ...
- salt使用技巧
实时截获任务输出 __salt__['event.send']("module_send_event", {'message': message, 'jid': jid}, ...