Spring Cloud Config的配置中心获取不到最新配置信息的问题

企业动态
本篇源于Spring Cloud Config的一个问题,但这个问题并非所有人都会遇到。如果您遇到了,那必须得看看这篇,如果没有遇到您也应该看看,防患于未然!

[[208203]]

本篇源于Spring Cloud Config的一个问题,但这个问题并非所有人都会遇到。如果您遇到了,那必须得看看这篇,如果没有遇到您也应该看看,防患于未然!

问题描述

之前有朋友提出Spring Cloud Config的配置中心在运行一段时间之后,发现修改了配置信息,但是微服务应用并拿不到新的配置内容。同时,发现配置中心存储配置的目录/tmp的配置内容被清空了。

原因与解决

首先,分析一下上面的问题,其实已经有一定的线索。表面现象是微服务从配置中心获取配置信息的时候获取不到***的配置,而其根本原因就是在/tmp目录下的缓存仓库已经被清空了,所以导致无法正常的通过Git获取到***配置,那么自然各个微服务应用就无法获取***配置了。

其实该问题在Spring Cloud的官方文档中也有对应的说明,原文如下:

With VCS based backends (git, svn) files are checked out or cloned to the local filesystem. By default they are put in the system temporary directory with a prefix of config-repo-. On linux, for example it could be /tmp/config-repo-<randomid>. Some operating systems routinely clean out temporary directories. This can lead to unexpected behaviour such as missing properties. To avoid this problem, change the directory Config Server uses, by setting spring.cloud.config.server.git.basedir or spring.cloud.config.server.svn.basedir to a directory that does not reside in the system temp structure.

根据上面的内容,我们可以知道在某些系统中,对于/tmp目录进行周期性的清理,所以也就有了上面所说的问题。

从文档中我们也已经知道如果去解决该问题,无非就是通过spring.cloud.config.server.git.basedir或spring.cloud.config.server.svn.basedir参数来指定一个不会被定期清理的目录。比如,我们可以设置:

  1. spring.cloud.config.server.git.basedir=config-repo 

其他问题

这里需要注意一下,该参数的设置依然有一定的问题。按理解,如上配置的话,应该是在配置中心程序所在的目录下创建一个config-repo目录来进行存储。但是,在测试了Dalston SR1和SR2版本之后,发现该配置只会将内容存储到配置中心程序的同一级目录下,并不会创建一个config-repo目录。

但是,如果我们这样设置,就可以将配置的缓存内容存储在配置中心所在目录下的config-repo目录中了:

  1. spring.cloud.config.server.git.basedir=config-repo/config-repo 

【本文为51CTO专栏作者“翟永超”的原创稿件,转载请通过51CTO联系作者获取授权】

戳这里,看该作者更多好文

责任编辑:武晓燕 来源: 51CTO专栏
相关推荐

2021-11-16 11:45:00

SpringSpring ClouJava

2018-07-10 14:55:32

Git存储配置

2010-08-06 14:53:35

思科路由器配置信息

2018-07-27 15:43:24

Spring Clou管理架构

2018-06-22 15:46:45

Spring Clou加密处理

2018-05-16 15:45:19

SpringCloudConfig

2017-07-28 16:41:53

Spring Clou微服务架构

2009-12-17 10:08:06

Cisco路由器配置信

2019-09-24 16:15:03

架构配置代码

2010-02-04 16:57:40

Android配置信息

2023-06-12 00:20:42

Go配置管理库

2018-07-19 14:58:14

Spring Clou微服务架构

2018-05-23 15:58:27

Spring Clou微服务架构

2009-12-21 13:27:45

WCF服务配置信息

2023-05-04 08:09:33

serviceId路径谓词中心注册

2009-03-02 10:00:00

口令路由器交换机

2023-09-12 13:12:23

服务器系统

2018-10-09 11:27:24

阿里云ACM

2009-11-17 17:00:47

宽带路由器配置

2019-01-09 08:00:30

数据中心配置物理服务器
点赞
收藏

51CTO技术栈公众号