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

快速入门:使用 Azure CLI 在 Azure Spring Apps 中创建服务连接

本快速入门介绍如何使用 Azure CLI 和服务连接器将 Azure Spring Apps 连接到其他云资源。

使用服务连接器可以快速将计算服务连接到云服务,同时管理连接身份验证和网络设置。

先决条件

  • 2.37.0 或更高版本的 Azure CLI。 若要升级到最新版本,请运行 az upgrade。 如果使用 Azure Cloud Shell,则最新版本已安装。

  • Azure CLI 或 Cloud Shell 中必须安装 Azure Spring Apps 扩展。 若要安装该模块,请运行 az extension add --name spring

初始设置

  1. 如果是首次使用服务连接器,请首先运行命令 az provider register 以注册服务连接器资源提供程序。

    az provider register -n Microsoft.ServiceLinker
    

    提示

    可以通过运行命令 az provider show -n "Microsoft.ServiceLinker" --query registrationState 来检查资源提供程序是否已注册。 如果输出为 Registered,则已注册服务连接器。

  2. (可选) 运行命令“az spring connection list-support-types”以获取支持 Azure Spring Apps 的目标服务。

    az spring connection list-support-types --output table
    

    提示

    如果系统未识别 az spring 命令,请检查是否已通过运行 az extension add --name spring 安装了所需的扩展。

创建服务连接

使用访问密钥或托管标识从 Azure Spring Apps 创建连接。

  1. 运行 az spring connection create 命令,通过访问密钥创建 Azure Spring Apps 与 Azure Blob 存储之间的服务连接。

    az spring connection create storage-blob --secret
    
  2. 按照 CLI 或 Cloud Shell 的请求提供以下信息:

    设置 说明
    The resource group which contains the spring-cloud 包含 Azure Spring Apps 托管的应用的资源组的名称。
    Name of the spring-cloud service Azure Spring Apps 资源的名称。
    Name of the spring-cloud app 连接到目标服务的 Azure Spring Apps 托管的应用程序的名称。
    The resource group which contains the storage account 包含存储帐户的资源组的名称。
    Name of the storage account 要连接到的存储帐户的名称。 本指南使用 Blob 存储。

提示

如果没有 Blob 存储,可以运行 az spring connection create storage-blob --new --secret 来预配一个新的 Blob 存储,并使用连接字符串将其直接连接到 Azure Spring Apps 托管的应用程序。

查看连接

运行 az spring connection list 命令以列出所有 Azure Spring Apps 的预配连接。

将以下命令中的占位符 <azure-spring-apps-resource-group><azure-spring-apps-name><app-name> 替换为 Azure Spring Apps 资源组的名称、Azure Spring Apps 资源的名称和应用程序的名称。 还可以删除 --output table 选项,以查看有关连接的详细信息。

az spring connection list --resource-group <azure-spring-apps-resource-group> --service <azure-spring-apps-name> --app <app-name>--output table

输出还显示连接的预配状态:失败或成功。

后续步骤

有关服务连接器和 Azure Spring Apps 的详细信息,请参阅以下指南。