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

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

本快速入门介绍如何使用 Azure CLI 和服务连接器将 Azure Spring Apps 连接到其他云资源。 服务连接器简化了将计算服务链接到云服务的过程,同时管理身份验证和网络设置。

注释

基本计划、标准计划和企业计划于 2025 年 3 月 17 日进入停用期。 有关详细信息,请参阅 Azure Spring Apps 停用公告

标准消耗和专用计划于 2024 年 9 月 30 日进入停用期,并将在 2025 年 3 月底之前完全关闭。 有关详细信息,请参阅将 Azure Spring Apps 标准消耗和专用计划迁移到 Azure 容器应用

若要使用 Azure 门户连接资源,请参阅 使用 Azure 门户在 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 创建连接。

注释

若要使用托管标识,必须有权在 Microsoft Entra ID 中修改角色分配。 如有必要,请要求订阅所有者授予此权限。

  1. 运行 az spring connection create 命令,使用系统分配的托管标识将部署到 Azure Spring Apps 的应用程序连接到 Blob 存储资源。

  2. 按照 CLI 或 Cloud Shell 的请求提供以下信息:

    az spring connection create storage-blob --system-identity
    
    设置 说明
    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 --system-identity 来预配一个新的 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 的详细信息,请参阅以下指南。