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协议主动的拉取服务的的配置信息,完成配置获取. 下面我们对 ...
随机推荐
- 垃圾循环li
function hezhu() { // var lis= $("#aaa").find("treeview"); ////var lis= document ...
- HDU 5159 Card( 计数 期望 )
Card Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 面试题。线程pingpong的输出问题
第一种情况:public class Main { public static void main(String args[]) { Thread t = new Thread() { public ...
- WPF自适应问题
引用水哥同事的文章 点击跳转
- Flask-Login的实现
Flask-Login Flask-Login 为 Flask 提供用户 session 的管理机制.它可以处理 Login.Logout 和 session 等服务. 作用: 将用户的 id 储存在 ...
- phpredis中incr以及decr等自增命令出现的问题
在做项目中使用redis的incr以及hincrby自增时,出现自增失败,set之后的数据,无法自增,当redis中不存在该key时,直接用incr是成功的.查找了原因,是因为phpredis初始化的 ...
- oldlinux
http://oldlinux.org/Linux.old/ http://oldlinux.org/Book-Lite/
- 如何在YouTube上下载视频
1,首先要有科学上网的工具 2,详细说明:https://en.savefrom.net/1-how-to-download-youtube-video/
- linux 出现 -bash-4.2# 问题的解决方法
1.在根目录创建 /root 目录 mkdir /root 2. 复制 .bashrc 以及 .bash_profile俩个文件到root目录下 cp /etc/skel/.bashrc /root ...
- BZOJ 2238: Mst DFS序+KDtree
明明可以用二维数点来做啊,网上为什么都是树剖+线段树呢 ? code: #include <cstdio> #include <cstring> #include <al ...