Spring Cloud配置中心高可用搭建
本文通过config server连接git仓库来实现配置中心,除了git还可以使用svn或者系统本地目录都行。
引入依赖
<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>
spring-cloud-config-server这个就是配置中心server的依赖。
配置中心做到高可用本身也需要向注册中心注册自己的实例,所以需求引用spring-cloud-starter-eureka依赖。
添加启动类,开启Config Server功能
@EnableDiscoveryClient
@EnableConfigServer
@SpringBootApplication
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
@EnableConfigServer:即开启配置服务器的功能。
@EnableDiscoveryClient:开启自动注册客户端,默认情况下,ServiceRegistry实现将自动注册正在运行的服务。如注册中心使用是Eureka,这里也可以使用的@EnableEurekaClient注解。
添加Config配置
spring:
application:
name: config-center
profiles:
active: config-center1
cloud:
config:
server:
git:
uri: ${git.uri}
searchPaths: ${git.searchPaths}
username: ${git.username}
password: ${git.password}
basedir: ${git.basedir}
clone-on-start: true
force-pull: true
eureka:
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ipAddress}:${server.port}
lease-expiration-duration-in-seconds: ${lease-expiration-duration-in-seconds}
lease-renewal-interval-in-seconds: ${lease-renewal-interval-in-seconds}
client:
serviceUrl:
defaultZone: ${register-center.urls}
---
spring:
profiles: config-center1
server:
port: ${config-center1.server.port}
---
spring:
profiles: config-center2
server:
port: ${config-center2.server.port}
这里配置了两台Config Server,都注册到了两台注册中心上。
Maven filter配置
#git
git.uri=http://gitlab.example.com/test/config.git
git.username=root
git.password=root
git.searchPaths=config-center
git.basedir=f:/config/config-center/git
Spring Cloud Git配置详解
spring.cloud.config.server.git.uri:git仓库地址。
spring.cloud.config.server.git.searchPaths:git仓库搜索目录。
spring.cloud.config.server.git.username:连接git的用户名。
spring.cloud.config.server.git.password:连接git的用户名密码。
spring.cloud.config.server.git.basedir:配置中心在本地缓存配置的目录。
spring.cloud.config.server.git.clone-on-start:配置为true表示启动时就克隆配置缓存到本地。
spring.cloud.config.server.git.force-pull:配置为true表示如果本地副本是脏的,将使Spring Cloud Config Server强制从远程存储库拉取配置。
启动配置中心
分别启动以下配置中心,使用不同的Profile指定端口。
spring-boot:run -Drun.profiles=config-center1 -P dev
spring-boot:run -Drun.profiles=config-center2 -P dev
推荐阅读
分享Java干货,高并发编程,热门技术教程,微服务及分布式技术,架构设计,区块链技术,人工智能,大数据,Java面试题,以及前沿热门资讯等。
Spring Cloud配置中心高可用搭建的更多相关文章
- Spring Cloud注册中心高可用搭建
Spring Cloud的注册中心可以由Eureka.Consul.Zookeeper.ETCD等来实现,这里推荐使用Spring Cloud Eureka来实现注册中心,它基于Netfilix的Eu ...
- Spring Cloud第十一篇 | 分布式配置中心高可用
本文是Spring Cloud专栏的第十一篇文章,了解前十篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Cl ...
- 跟我学SpringCloud | 第七篇:Spring Cloud Config 配置中心高可用和refresh
SpringCloud系列教程 | 第七篇:Spring Cloud Config 配置中心高可用和refresh Springboot: 2.1.6.RELEASE SpringCloud: Gre ...
- Spring Cloud配置中心(Config)
Spring Cloud配置中心(Config) Spring Cloud是现在流行的分布式服务框架,它提供了很多有用的组件.比如:配置中心.Eureka服务发现. 消息总线.熔断机制等. 配置中心在 ...
- spring cloud 配置中心
1. spring cloud配置中心server 1.1 创建git仓库 首先在github上搭建一个存储配置中心的仓库,需要创建两个分支,一个是master,一个是dev分支.自己学习可以用公开库 ...
- 记录一个 spring cloud 配置中心的坑,命令行端口参数无效,被覆盖,编码集问题无法读取文件等.
spring cloud 配置中心 结合GIT , 可以运行时更新配置文件.发送指令让应用重新读取配置文件. 最近在测试服务器实现了一套,结果CPU 实用率暴增,使用docker compose启动 ...
- springcloud(五):Spring Cloud 配置中心的基本用法
Spring Cloud 配置中心的基本用法 1. 概述 本文介绍了Spring Cloud的配置中心,介绍配置中心的如何配置服务端及配置参数,也介绍客户端如何和配置中心交互和配置参数说明. 配置中心 ...
- springcloud(六):Spring Cloud 配置中心采用数据库存储配置内容
Spring Cloud 配置中心采用数据库存储配置内容 转自:Spring Cloud Config采用数据库存储配置内容[Edgware+] Spring Cloud Server配置中心采用了G ...
- (七)Spring Cloud 配置中心config
spring cloud config是一个基于http协议的远程配置实现方式. 通过统一的配置管理服务器进行配置管理,客户端通过http协议主动的拉取服务的的配置信息,完成配置获取. 下面我们对 ...
随机推荐
- SSD如何设置预留空间OP(Over-Provision)
Over-Provision操作指南 SSD OP全称是(Over-Provision), 中文名预留空间, 指用户不可操作的容量,大小为SSD实际容量减去用户可用容量.简单来说over-provis ...
- C语言|博客作业3
问题 答案 这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 https://i.cnblogs.com/EditPosts.aspx?postid=11661995&update ...
- javaIO流(四)--输入与输出支持
一.打印流 如果现在要想通过程序实现内容的输出,核心的本质一定要依靠OutputStream类来支持但是OutputStream类有一个最大的缺点,这个类的数据输出操作功能有限,所有的数据一定要转为字 ...
- Apache Shiro 认证+授权(一)
1.核心依赖 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-co ...
- Eclipse插件pydev编辑.py文件时报错:unresolved import error.解决办法
在同一个包中import还报unresolved import error.感觉很奇怪,原来需要把当前的包也要添加到System libs中
- 案例:使用xml存储数据
HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- 更改mysql最大连接数
方法一: 打开cmd,用"mysql -u root -p;"命令进入mysql, 输入命令:show variables like "max_connections&q ...
- linux起源及centos安装
第1章 Linux介绍 1.1 什么是操作系统 是一个人与计算机硬件的中介 Linux:内核+shell+扩展软件 操作系统,英文名称Operating System,简称OS,是计算机系统中必不可 ...
- Dev常用控件
GridControl TreeView DEV GridControl小结.. https://blog.csdn.net/happy09li/article/details/7186829 Dev ...
- js对象的深度拷贝
//判断对象的类型 Array Object Function String Number ..... function getObjType(obj){ return Object.prototyp ...