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

使用 VMware PowerCLI 将载入的 VMware vSphere Linux 虚拟机扩展到 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 PowerShell 脚本后:

    • 该脚本将使用用户的 Azure 环境变量自动生成一个 vars.sh shell 脚本。

    • 脚本执行将针对 vCenter 启动身份验证,并将扫描 Azure Arc 候选 VM 所在的目标 VM 文件夹,并将自动生成的 vars.shinstall_azure_arc_agent.sh shell 脚本复制到位于 /vmware/scaled-deploy/powercli/linux 中的 VM Linux OS 到该 VM 文件夹中的每个 VM。

  3. install_azure_arc_agent.sh shell 脚本将在 VM 来宾操作系统上运行,并将安装连接 Azure Arc 的机器代理,以便将 VM 载入 Azure Arc。

部署前

为了演示此方案的前后对比,以下屏幕截图显示了一个专用的空 Azure 资源组、一个包含候选 VM 的 vCenter VM 文件夹以及显示未安装代理的 /var/opt/ 目录。

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_azure_arc_agent.sh 脚本将使用的环境变量。 这些变量基于你刚刚创建的 Azure 服务主体、你的 Azure 订阅和租户,以及你的 VMware vSphere 凭据和数据。

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

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

    A screenshot of exporting environment variables.

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

    A screenshot of scale_deploy.ps1.

    A second screenshot of scale_deploy.ps1.

    A third screenshot of scale_deploy.ps1.

  • 完成后,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.