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仓库的配置后,需要重启服务,才可以得到最新的配置,这一篇我们尝试使用 ...
随机推荐
- 【RAID在数据库存储上的应用 】
随着单块磁盘在数据安全.性能.容量上呈现出的局限,磁盘阵列(Redundant Arrays of Inexpensive/Independent Disks,RAID)出现了,RAID把多块独立的磁 ...
- PCB 规则引擎之脚本语言JavaScript应用评测
世界上没有好做的软件,觉得好做,只是你的系统简单而已,而不是哪个行业简单,特别像我们PCB制造企业务逻辑的很复杂的,仅仅靠决策树中的每个节点布置决策逻辑是不能满足要求的,所以我们在制作PCB规则引擎必 ...
- [Swift通天遁地]八、媒体与动画-(5)使用开源类库绘制文字、图形、图像、图表、SVG(可缩放矢量图形)
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Django day32 跨域问题,创建vue项目,axios的使用
一:跨域问题 1.同源策略(浏览器的安全策略) 只允许当前页面朝当前域下发请求,如果向其他域发请求,请求可以正常发送,数据也可以拿回,但是被浏览器拦截了 2.cors:只要服务器实现了CORS,就可以 ...
- 微信小程序图片选择,预览和删除
这里均用的是小程序原生api 废话不多说直接上栗子: <view class="addImv"> <!--这个是已经选好的图片--> <view wx ...
- Springboot2.0部署阿里云服务器(nginx+域名+SSL)供Http和Https访问
总算是弄出来了,先写下来供自己以后查阅. 1)首先你要有一个阿里云服务器,我用的是Centos7学生认证,10元/月,很便宜也很好用. 2)购买了域名,首年9元,很划算.域名买来之后经历了拍照备案,前 ...
- WP8开发常用解决方案收集
我其实不怎么做wp的东西.但是偶尔还是会用到, 但是wp8开发的资料确实难找.特开此贴,记录一些常见的解决方案 1.水平滑动动画(比如app首次使用说明就可以用这个做) http://www.cnbl ...
- JavaScript--控制类名(className 属性)
className 属性设置或返回元素的class 属性. 语法: object.className = classname 作用: 1.获取元素的class 属性 2. 为网页内的某个元素指定一个c ...
- ACM_小G的循环
小G的循环 Time Limit: 2000/1000ms (Java/Others) Problem Description: 一回生,二回熟,三回就腻,小G用for,while循环用得太多了,累觉 ...
- ACM_最短网络(最小生成树)
Problem Description: Farmer John has been elected mayor of his town! One of his campaign promises wa ...