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

向 Azure Arc 连接现有 Windows 服务器实例

本文提供使用简单的 PowerShell 脚本将 Windows 计算机连接到 Azure Arc 的相关指导。

先决条件

  1. 将 Azure CLI 更新到 2.7 及更高版本或者直接安装该版本。 使用以下命令检查你当前安装的版本。

    az --version
    
  2. 创建 Azure 服务主体。

    要将服务器连接到 Azure Arc,需要使用获分配参与者角色的 Azure 服务主体。 要创建此角色,请登录你的 Azure 帐户并运行以下命令。 还可以在 Azure Cloud Shell 中运行此命令。

    az login
    az account set -s <Your Subscription ID>
    az ad sp create-for-rbac -n "<Unique SP Name>" --role contributor --scopes "/subscriptions/<Your Subscription ID>"
    

    例如:

    az ad sp create-for-rbac -n "http://AzureArcServers" --role contributor --scopes "/subscriptions/00000000-0000-0000-0000-000000000000"
    

    输出应如下所示:

    {
      "appId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "displayName": "http://AzureArcServers",
      "password": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "tenant": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    }
    

    注意

    我们强烈建议你将服务主体的范围限定为特定的 Azure 订阅和资源组

  3. 为计算机创建新的 Azure 资源组。

    A screenshot of an empty resource group in the Azure portal.

  4. 下载 az_connect_win.ps1PowerShell 脚本。

  5. 根据环境更改环境变量,并将该脚本复制到指定的计算机。

    A screenshot of the environment variables to be changed.

部署

在指定的计算机上,以管理员身份打开 PowerShell ISE 并运行脚本。 请注意,该脚本使用 $env:ProgramFiles 作为代理安装路径,因此请确保你使用的是 PowerShell ISE (x86)

A screenshot of the azcmagent connect command.

A screenshot of the az_connect_win.ps1 Windows script.

完成后,你可以将 Windows 服务器实例作为新的 Azure Arc 资源连接到资源组中。

A screenshot of the az_connect_win.ps1 Windows script running.

A screenshot of an Azure Arc-enabled resource in the Azure portal.

A screenshot of details from an Azure Arc-enabled resource in the Azure portal.

删除部署

要删除服务器,请选择服务器,然后从 Azure 门户删除它。

A screenshot of the option to delete a resource in the Azure portal.

要删除整个部署,请从 Azure 门户删除 Azure 资源组。

A screenshot of the option to delete a resource group via the Azure portal.