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

使用 VMware PowerCLI 将加入的 VMware vSphere Windows Server 虚拟机扩展到 Azure Arc

本文指导你如何使用提供的 VMware PowerCLI 脚本,以便你可以在多个 VMware vSphere 虚拟机中执行连接 Azure Arc 的机器代理的自动扩展部署,从而将这些 VM 作为支持 Azure Arc 的服务器载入。

本指南假定你已经拥有 VMware 虚拟机的现有清单,并将使用 PowerCLI PowerShell 模块自动完成将 VM 载入 Azure Arc 的过程。

先决条件

  1. 克隆 Azure Arc 快速入门存储库。

    git clone https://github.com/microsoft/azure_arc.git
    
  2. Azure CLI 更新到 2.7 或更高版本,或者直接安装该版本。 使用以下命令检查你当前安装的版本:

    az --version

  3. 安装 VMware PowerCLI。

    注意

    本指南已使用截至目前最新版本 PowerCLI (12.0.0) 进行了测试,但早期版本预计也能正常工作

    • 支持的 PowerShell 版本: VMware PowerCLI 12.0.0 与以下 PowerShell 版本兼容:
      • Windows PowerShell 5.1

      • PowerShell 7

      • 可在安装 PowerCLI 中找到详细的安装说明,但最简单的方法是通过以下命令使用 PowerShell 库中的 VMware.PowerCLI 模块。

        Install-Module -Name VMware.PowerCLI
        
  4. 为了能够从 vCenter 读取虚拟机清单以及在虚拟机操作系统级别调用脚本,需要以下权限:

  5. 创建 Azure 服务主体。

    要将 VMware vSphere 虚拟机连接到 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 订阅和资源组

自动化流程

可在下面找到此方案的自动化流程:

  1. 用户编辑 vars.ps1 PowerCLI 脚本。

  2. scale_deploy.ps1 脚本执行将针对 vCenter 启动身份验证,扫描 Azure Arc 候选 VM 所在的目标 VM 文件夹,并将 vars.ps1install_azure_arc_agent.ps1 PowerCLI 脚本复制到位于 azure-arc GitHub 存储库中的 VM Windows 操作系统上,供该 VM 文件夹中的每个 VM 使用。

  3. install-azure_arc_agent.ps1 PowerCLI 脚本将在 VM 来宾操作系统上运行,并将安装连接 Azure Arc 的机器代理,来将 VM 加入到 Azure Arc 中。

部署前

为了演示此方案的前后,以下屏幕截图显示了专用的空 Azure 资源组、具有候选 VM 的 vCenter VM 文件夹和 Windows 中的应用和功能 视图,其中未安装代理。

Screenshot of an empty Azure resource group.

A screenshot of a vanilla VMware vSphere virtual machine without an Azure Arc agent.

Another screenshot of a vanilla VMware vSphere virtual machine without an Azure Arc agent.

部署

在运行 PowerCLI 脚本之前,你必须设置 install_arc_agent.ps1 脚本将使用的环境变量。 这些变量基于你刚刚创建的 Azure 服务主体、你的 Azure 订阅和租户,以及你的 VMware vSphere 凭据和数据。

  1. 使用 az account list 命令检索你的 Azure 订阅 ID 和租户 ID

  2. 使用在先决条件部分创建的 Azure 服务主体 ID 和密码:

    A screenshot of exporting environment variables.

  3. azure_arc_servers_jumpstart\vmware\scaled-deploy\powercli\windows 文件夹中,以管理员身份打开 PowerShell 会话并运行 scale-deploy.ps1 脚本。

    A screenshot of how to scale-deploy with a PowerShell script.

    A second screenshot of how to scale-deploy with a PowerShell script.

    A third screenshot of how to scale-deploy with a PowerShell script.

  4. 完成后,VM 将安装连接 Azure Arc 的计算机代理,并使用新的支持 Azure Arc 的服务器填充 Azure 资源组。

    A screenshot of a machine with an Azure Arc agent installed.

    A screenshot of new Azure Arc-enabled servers in an Azure resource group.

    Another screenshot of new Azure Arc-enabled servers in an Azure resource group.