1. 程式人生 > >Spring Cloud Config的配置中心獲取不到最新配置資訊的問題

Spring Cloud Config的配置中心獲取不到最新配置資訊的問題

問題描述

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

參考:

關注我的公眾號,輕鬆瞭解和學習更多技術
這裡寫圖片描述