问题描述

1、 Spring Cloud Config的配置中心,修改了配置信息,微服务没有及时更新。git远程仓库设有密码
2、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-. 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

来指定一个不会被定期清理的目录。

解决

spring:
  cloud:
    config:
      enabled: true
      server:
        git:
          uri: https://github.com/xxxx
          search-paths: config  #设置路径
          basedir: config-repo  
          username: 2016xxxx@qq.com #账号
          password: 888888  #密码
        bootstrap: true

参考:

史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
Spring Cloud Config的配置中心获取不到最新配置信息的问题
Spring Cloud Config

关注我的公众号,轻松了解和学习更多技术
这里写图片描述

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐