> For the complete documentation index, see [llms.txt](https://potoyang.gitbook.io/spring-in-action-v5/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://potoyang.gitbook.io/spring-in-action-v5/di-14-zhang-pei-zhi-guan-li/14.2-yun-hang-pei-zhi-fu-wu-qi.md).

# 14.2 运行配置服务器

Spring Cloud Config Server 为配置数据提供了一个集中存储的地方。像 Eureka 那样，Config Server 可以被认为只是一个微服务，它在更大的应用程序中扮演的角色是，为其他服务提供配置数据服务。

Config Server 公开了一个 REST API，客户端（也就是其他微服务）可以通过 API 使用配置服务。Config Server 提供的配置信息存储在服务外部，通常位于版本控制系统中，如 Git。图 14.1 说明了其工作原理。

![图14.1 Spring Cloud Config Server 支持使用 Git 的 Repository 或 Vault 加密存储到其他服务中。](https://867170852-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LrmLE3NwQoVJk02Q_BX%2Fsync%2F3efbaea9d6978e2d276b28e135ec7984a214eb92.png?generation=1618232665326945\&alt=media)

要注意图 14.1 有 Git 图标，但没有 `GitHub` 图标。这很重要，您可以使用 Git 的任何实现来存储配置，包括但不限于 `GitHub`、`GitLab`、`Microsoft’s Team Foundation Server` 或 `Gogs`，这些都是可以选择的。

> 请注意，尽管与 Config Server 一起配合的 Git 服务差别不大，但我用的是 Gogs (<http://gogs.io>)，一个轻量级、易于安装的 Git 服务。更具体地说，我在开发机器上使用运行在 Docker 中的 Gogs，可参考 Gogs 使用指南 [https://github.com/gogits/ gogs/tree/master/docker](https://github.com/gogits/gogs/tree/master/docker)。

通过将配置存储在代码版本控制系统（如 Git ）中，配置可以进行版本控制、分支、标记、还原和追责，就像管理应用程序源代码一样。通过把配置与使用它的服务分离，配置就可以独立于应用程序进行修改和版本控制。

您可能还注意到图 14.1 中包含 `HashiCorp Vault`。保险库 （Vault） 非常有用，特别是在您希望提供的配置属性完全保密，直到需要时才放开的情况。我们将 14.5 节进一步讨论，如何使 Config Server 与 Vault 一起工作。
