春季云配置服务器多个存储库的备用方案

huangapple go评论136阅读模式
英文:

Spring Cloud Config Server fallback for multiple repositories

问题

我们正在使用由Bitbucket支持的Spring Cloud配置服务器来管理配置文件。我们已经在配置服务器的application.yml中配置了多个代码仓库。我们希望即使Bitbucket不可用,配置服务器的配置信息仍然可用。我们正在寻找一种解决方案,可以缓存配置代码仓库,以防Bitbucket不可访问时仍然能够提供不同代码仓库的属性。\n以下是我的application.yml配置:\n
```yaml
spring:
  cloud:
    config:
      server:
        git:
          uri: git@bitbucket.org:config1.git
          ignoreLocalSshSettings: true
          privateKey: ${PEM}
          repos:
            service1:
              uri: git@bitbucket.org:config2.git
              ignoreLocalSshSettings: true
              privateKey: ${PEM}
            service2:
              uri: git@bitbucket.org:config3.git
              ignoreLocalSshSettings: true
              privateKey: ${PEM}

我已经尝试设置spring.cloud.config.server.git.basedir,但它只克隆基本配置代码仓库。我们如何使配置服务器在Bitbucket不可用时能够从本地提供配置信息呢?


<details>
<summary>英文:</summary>

We are using spring cloud config server backed by bitbucket for config files. We have configured multiple repositories in application.yml of config server. We want to make it available even if bitbucket is down. We are looking for a solution that can cache config repositories and in case bitbucket is down it can still be able to serve properties of different repositories.
Below is my application.yml

spring:
cloud:
config:
server:
git:
uri: git@bitbucket.org:config1.git
ignoreLocalSshSettings: true
privateKey: ${PEM}
repos:
service1:
uri: git@bitbucket.org:config2.git
ignoreLocalSshSettings: true
privateKey: ${PEM}
service2:
uri: git@bitbucket.org:config3.git
ignoreLocalSshSettings: true
privateKey: ${PEM}

I have tried setting up ```spring.cloud.config.server.git.basedir``` but it clones only the base config repo. How can we make config server to serve from local if bitbucket is down.

</details>


# 答案1
**得分**: 1

使用 `basedir` 属性是唯一的解决办法。以下是我们如何使用它:

```yaml
spring:
  cloud:
    config:
      server:
        git:
          uri: git@bitbucket.org:config1.git
          ignoreLocalSshSettings: true
          privateKey: ${PEM}
          basedir: /home/user/config1-repo
          repos:
            service1:
              uri: git@bitbucket.org:config2.git
              ignoreLocalSshSettings: true
              privateKey: ${PEM}
              basedir: /home/user/config2-repo
            service2:
              uri: git@bitbucket.org:config3.git
              ignoreLocalSshSettings: true
              privateKey: ${PEM}
              basedir: /home/user/config3-repo

你是如何尝试重现 Git 不可用的场景,并强制配置服务器从本地服务器路径获取属性的?我建议你创建本地路径。并且使用 Git Bash 将配置仓库克隆到本地仓库目录中。例如,在这种情况下,进入 /home/user/localRepo,然后在那里克隆你的配置 Git 仓库。确保所有文件和文件夹都被正确克隆。

然后尝试重现 Git 不可用的场景,并检查你的配置服务器微服务是否能够从本地目录获取属性。这是唯一的备选方案。

英文:

Using basedir property is the only way out. This is how we use that :

spring:
  cloud:
    config:
      server:
        git:
          uri: git@bitbucket.org:config1.git
          ignoreLocalSshSettings: true
          privateKey: ${PEM}
          basedir: /home/user/config1-repo
          repos:
            service1:
              uri: git@bitbucket.org:config2.git
              ignoreLocalSshSettings: true
              privateKey: ${PEM}
              basedir: /home/user/config2-repo
            service2:
              uri: git@bitbucket.org:config3.git
              ignoreLocalSshSettings: true
              privateKey: ${PEM}
              basedir: /home/user/config3-repo

How did you try to reproduce the scenario where git is not available and forcing the config server to fetch the properties from local server path. I suggest you create the local path. And using git-bash clone the config repo inside your local repo directory. For example in this case go inside /home/user/localRepo and clone your config git repo there. Ensure to have all the files and folder be cloned properly.

Then try to reproduce the git not available scenario and check if your config server MS is able to fetch properties from local dir. This is the only way out for fallback.

huangapple
  • 本文由 发表于 2020年7月23日 21:08:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/63055051.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定