你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

快速入门:为 Azure Spring Apps 设置 Spring Cloud Config Server

注意

Azure Spring Apps 是 Azure Spring Cloud 服务的新名称。 虽然该服务有新名称,但一些地方仍会使用旧名称,我们仍在更新屏幕截图、视频和图形等资产。

本文适用于:✔️ 基本/标准层 ❌ Enterprise 层

Config Server 是分布式系统的一种集中式配置服务。 它使用当前支持本地存储、Git 和 Subversion 的可插入存储库层。 在此快速入门中,你将设置 Config Server 以从 Git 存储库获取数据。

先决条件

Config Server 过程

通过运行以下命令,使用项目的 Git 存储库的位置设置 Config Server。 将 服务实例名称> 替换为之前创建的服务的名称。 在前面的快速入门中设置的服务实例名称的默认值不适用于此命令。

az spring config-server git set -n <service instance name> --uri https://github.com/Azure-Samples/azure-spring-apps-samples --search-paths steeltoe-sample/config

此命令指示 Config Server 在示例应用存储库的 steeltoe-sample/config 文件夹中查找配置数据。 由于获取配置数据的应用名称为 planet-weather-provider,因此使用的文件是 planet-weather-provider.yml

先决条件

Config Server 过程

以下过程使用 Azure 门户设置 Config Server 来部署 PetClinic 示例

  1. 转到服务的“概览”页,选择“配置服务器”。

  2. 在“默认存储库”部分,将“URI”设置为 https://github.com/azure-samples/spring-petclinic-microservices-config

  3. 选择“验证”。 验证会检查 git 存储库的架构和可访问性,以确保其正确。

    Screenshot of Azure portal showing Config Server page.

  4. 完成验证后,选择“应用”以保存更改。

    Screenshot of Azure portal showing Config Server page with Apply button highlighted.

更新配置可能需要几分钟。 配置完成后,会收到通知。

提示

有关为 Config Server 使用专用存储库的信息,请参阅在 Azure Spring Apps 中配置托管的 Spring Cloud Config Server

Azure Spring Apps Config Server 的故障排除

以下过程说明如何对 Config Server 设置进行故障排除。

  1. 在 Azure 门户中,转到服务“概览”页,然后选择“日志” 。

  2. 在“显示包含‘错误’或‘异常’术语的应用程序日志”下的“查询”窗格中,选择“运行”。

    Screenshot of Azure portal showing Azure Spring Apps query.

    日志中的以下错误指示 Spring Apps 服务无法在 Config Server 中找到属性:java.lang.illegalStateException

  3. 转到服务“概述”页。

  4. 选择“诊断并解决问题”。

  5. 在“可用性和性能”下,选择“排除故障”。

    Screenshot of Azure portal showing Diagnose and solve problems page.

    Azure 门户显示“可用性和性能”页面,该页面提供有关 Config Server 运行状况的各种信息。

清理资源

如果打算继续使用后续的快速入门和教程,则可能需要保留这些资源。 如果不再需要该资源组,请将其删除,这将删除资源组中的资源。 若要删除资源组,请在 Azure CLI 中输入以下命令:

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

后续步骤