本文通过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-centerprofiles:active: config-center1cloud:config:server:git:uri: ${git.uri}searchPaths: ${git.searchPaths}username: ${git.username}password: ${git.password}basedir: ${git.basedir}clone-on-start: trueforce-pull: trueeureka: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-center1server:port: ${config-center1.server.port}---
spring:profiles: config-center2server: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

SpringCloud配置中心高可用搭建相关推荐

  1. java B2B2C源码电子商务平台 -SpringCloud配置中心高可用搭建

    本文通过config server连接git仓库来实现配置中心,除了git还可以使用svn或者系统本地目录都行.需要JAVA Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台 ...

  2. SpringCloud注册中心高可用搭建

    转载自 SpringCloud注册中心高可用搭建 Spring Cloud的注册中心可以由Eureka.Consul.Zookeeper.ETCD等来实现,这里推荐使用Spring Cloud Eur ...

  3. spring boot配置ip_Spring Cloud 配置中心高可用搭建

    本文通过config server连接git仓库来实现配置中心,除了git还可以使用svn或者系统本地目录都行. 引入依赖 <dependencies><dependency> ...

  4. MySQL高可用群集------配置MMM高可用架构

    MMM简介: MMM(Master-Master replication manager for Mysql,Mysql 主主复制管理器)是一套支持双主故障切换和双主日常管理的脚本程序.MMM使用Pe ...

  5. HADOOP 高可用搭建

    首先先说一下大概的步骤,就用四台为例,简单适合新手操作. 流程是:创建虚拟机,配置好:搭建linux系统:安装jdk(因为后面好多都依赖jkd):免密登录ssh:安装zookeeper:最后就是搭建高 ...

  6. Nginx反向代理,负载均衡,Redis集群 Twemproxy,redis session共享,keepalived高可用-搭建千万级网站系统

    Nginx反向代理,负载均衡,redis session共享,keepalived高可用-搭建千万级系统架构 1.安装Nginx 安装机器IP地址为: 192.168.91.129 (主) 192.1 ...

  7. SpringCloud配置中心内容加密

    转载自 SpringCloud配置中心内容加密 从配置获取的配置默认是明文的,有些像数据源这样的配置需要加密的话,需要对配置中心进行加密处理. 下面使用对称性加密来加密配置,需要配置一个密钥,当然也可 ...

  8. SpringCloud配置中心客户端读取配置

    转载自 SpringCloud配置中心客户端读取配置 微服务连接配置中心来实现外部配置的读取. 引入依赖 <dependencies><dependency><group ...

  9. 在CentOS7上安装配置Corosync高可用集群过程全记录

    在CentOS7上安装配置Corosync高可用集群过程全记录 一.环境.拓朴及其他准备工作: 1-1:准备网络YUM源环境: All Nodes OS CentOS 7.3 x86_64: # wg ...

最新文章

  1. Redhat、centos安装配置postgresql
  2. 我的第二故乡 – 广州
  3. 从纸钱包,带你走进贴心的BCH!
  4. java rootpath_Java 获取webapp,Root,classpath,项目等路径工具类
  5. android读取网络配置文件,Android 中保存、读取设置配置数据、记录登录状态
  6. 34.35.热图(heatmap)、创建带注释的热图、使用辅助函数的代码样式、图像显示、图像插值、将图像数据导入Numpy数组、将numpy数组绘制为图像
  7. 【Android-NCNN-Vulkan】记录一次ncnn-vulkan在低性能开发板上出现的native内存溢出的问题
  8. [转载] Python基础之类型转换与算术运算符
  9. 朗文3000词汇表带音标_SBS朗文国际英语教程第二册单词表(带音标)
  10. 汇编指令:CLD STD MOVS LODS STOS
  11. 搭建AutoCAD License服务器
  12. java课程 数独 文库_一次数独生成及求解方案的剖析(Java实现)
  13. 二分图匹配Hopcroft-Carp算法介绍
  14. 网络安全与攻防-常见网络安全攻防
  15. 【操作系统】文件管理
  16. python Django Rest_Framework框架 视图集与路由Routers详解(图文并茂版)
  17. 机器学习系列(一)—— 绪言
  18. 谁说QTP不能多线程 - 当Python遇上QTP
  19. STM32F4深入学习【RCC】
  20. 思科德Exynos4412(2G内存)四核平板电脑方案

热门文章

  1. Windows 10 Creators Update 4 月 11 日开始推送
  2. Linux 进程、端口、IP、连接数等查询脚本
  3. 让软件版本信息自动引用SVN修订版本号
  4. Math.Round默认采用的不是四舍五入法, 而是四舍六入的银行家算法, 如何找回四舍五入法?...
  5. tensorflow版本问题导致的错误AttributeError: module ‘tensorflow‘ has no attribute ‘***‘
  6. AAC音频文件时长计算
  7. Mediasoup简介及其基本概念
  8. 开始使用Nuxt.js
  9. Linux 常用命令与设置
  10. linux如何查tomcat是否安装,如何检测linux机器上是否安装了tomcat和ant