使用共享映像库创建池Use the Shared Image Gallery to create a pool

使用虚拟机配置创建 Azure Batch 池时,需指定一个虚拟机 (VM) 映像,为池中每个计算节点提供操作系统。When you create an Azure Batch pool using the Virtual Machine Configuration, you specify a VM image that provides the operating system for each compute node in the pool. 可以使用受支持的 Azure 市场映像创建虚拟机池,也可以使用共享映像库创建自定义映像。You can create a pool of virtual machines either with a supported Azure Marketplace image or create a custom image with the Shared Image Gallery.

将共享映像库用于自定义映像时,可以控制操作系统类型和配置,以及数据磁盘的类型。When you use the Shared Image Gallery for your custom image, you have control over the operating system type and configuration, as well as the type of data disks. 共享映像可以包含应用程序和引用数据,Batch 池节点预配好后即可使用这些数据。Your Shared Image can include applications and reference data that become available on all the Batch pool nodes as soon as they are provisioned.

也可根据环境的需要创建多个映像版本。You can also have multiple versions of an image as needed for your environment. 在使用某个映像版本创建 VM 时,将使用该映像版本来创建 VM 的新磁盘。When you use an image version to create a VM, the image version is used to create new disks for the VM.

在准备池的计算节点以运行 Batch 工作负荷时,使用共享映像可以节省时间。Using a Shared Image saves time in preparing your pool's compute nodes to run your Batch workload. 可以在每个预配后的计算节点上使用 Azure 市场映像并安装软件,但通常情况下,使用共享映像会更加高效。It's possible to use an Azure Marketplace image and install software on each compute node after provisioning, but using a Shared Image is typically more efficient. 另外,可以为共享映像指定多个副本。这样,当你创建包含多个 VM(600 个 VM 以上)的池时,就会节省创建池的时间。Additionally, you can specify multiple replicas for the Shared Image so when you create pools with many VMs (more than 600 VMs), you'll save time on pool creation.

使用根据方案配置的共享映像有几个优点:Using a Shared Image configured for your scenario can provide several advantages:

  • 在不同的区域中使用相同的映像。Use the same images across the regions. 可以跨不同的区域创建共享映像副本,这样所有的池就可以利用同一映像。You can create Shared Image replicas across different regions so all your pools utilize the same image.
  • 配置操作系统 (OS)。Configure the operating system (OS). 可以自定义映像操作系统磁盘的配置。You can customize the configuration of the image's operating system disk.
  • 预安装应用程序。Pre-install applications. 在 OS 磁盘中预装应用程序,与使用启动任务预配计算节点后再安装应用程序相比,这种方法更加高效,且不容易出错。Pre-installing applications on the OS disk is more efficient and less error-prone than installing applications after provisioning the compute nodes with a start task.
  • 一次复制大量的数据。Copy large amounts of data once. 将静态数据复制到托管映像的数据磁盘,使这些数据成为托管的共享映像的一部分。Make static data part of the managed Shared Image by copying it to a managed image's data disks. 只需执行此操作一次,然后,数据可供池的每个节点使用。This only needs to be done once and makes data available to each node of the pool.
  • 扩大池的大小。Grow pools to larger sizes. 可以通过共享映像库创建更大的池,其中包含自定义映像和更多共享映像副本。With the Shared Image Gallery, you can create larger pools with your customized images along with more Shared Image replicas.
  • 性能优于自定义映像。Better Performance than custom image. 使用共享映像时,池达到稳定状态所需的时间最多可以缩短 25%,VM 空闲延迟最多可以缩短 30%。Using Shared Images, the time it takes for the pool to reach the steady state is up to 25% faster, and the VM idle latency is up to 30% shorter.
  • 进行映像版本控制和分组,以便于管理。Image versioning and grouping for easier management. 映像分组定义包含的信息涉及创建映像的原因、它适用于哪个 OS,以及映像的用法。The image grouping definition contains information about why the image was created, what OS it is for, and information about using the image. 对映像分组可以方便映像的管理。Grouping images allows for easier image management. 有关详细信息,请参阅映像定义For more information, see Image definitions.

先决条件Prerequisites

备注

共享映像必须与 Batch 帐户属于同一订阅。Your Shared Image must be in the same subscription as the Batch account. 共享映像可以位于不同的区域中,前提是它在 Batch 帐户所在的区域中有副本。Your Shared Image can be in different regions as long as it has replicas in the same region as your Batch account.

使用 Azure CLI 从共享映像创建池Create a pool from a Shared Image using the Azure CLI

若要使用 Azure CLI 从共享映像创建池,请使用 az batch pool create 命令。To create a pool from your Shared Image using the Azure CLI, use the az batch pool create command. --image 字段中指定共享映像 ID。Specify the Shared Image ID in the --image field. 确保 OS 类型和 SKU 与通过 --node-agent-sku-id 指定的版本匹配Make sure the OS type and SKU matches the versions specified by --node-agent-sku-id

az batch pool create \
    --id mypool --vm-size Standard_A1_v2 \
    --target-dedicated-nodes 2 \
    --image "/subscriptions/{sub id}/resourceGroups/{resource group name}/providers/Microsoft.Compute/galleries/{gallery name}/images/{image definition name}/versions/{version id}" \
    --node-agent-sku-id "batch.node.ubuntu 16.04"

使用 C# 从共享映像创建池Create a pool from a Shared Image using C#

也可使用 C# SDK 从共享映像创建池。Alternatively, you can create a pool from a Shared Image using the C# SDK.

private static VirtualMachineConfiguration CreateVirtualMachineConfiguration(ImageReference imageReference)
{
    return new VirtualMachineConfiguration(
        imageReference: imageReference,
        nodeAgentSkuId: "batch.node.windows amd64");
}

private static ImageReference CreateImageReference()
{
    return new ImageReference(
        virtualMachineImageId: "/subscriptions/{sub id}/resourceGroups/{resource group name}/providers/Microsoft.Compute/galleries/{gallery name}/images/{image definition name}/versions/{version id}");
}

private static void CreateBatchPool(BatchClient batchClient, VirtualMachineConfiguration vmConfiguration)
{
    try
    {
        CloudPool pool = batchClient.PoolOperations.CreatePool(
            poolId: PoolId,
            targetDedicatedComputeNodes: PoolNodeCount,
            virtualMachineSize: PoolVMSize,
            virtualMachineConfiguration: vmConfiguration);

        pool.Commit();
    }
    ...
}

使用 Azure 门户从共享映像创建池Create a pool from a Shared Image using the Azure portal

在 Azure 门户中,使用以下步骤从共享映像创建池。Use the following steps to create a pool from a Shared Image in the Azure portal.

  1. 打开 Azure 门户Open the Azure portal.
  2. 转到“Batch 帐户” ,然后选择你的帐户。Go to Batch accounts and select your account.
  3. 选择“池”,然后选择“添加”,以便创建新池。 Select Pools and then Add to create a new pool.
  4. 在“映像类型”部分,选择“共享映像库”。 In the Image Type section, select Shared Image Gallery.
  5. 使用托管映像的相关信息完成剩余部分。Complete the remaining sections with information about your managed image.
  6. 选择“确定” 。Select OK.

通过门户使用共享映像创建池。

大型池的注意事项Considerations for large pools

如果打算使用共享映像创建包含数百或数千 VM 或更多 VM 的池,请按以下指南操作。If you plan to create a pool with hundreds or thousands of VMs or more using a Shared Image, use the following guidance.

  • 共享映像库副本数目。Shared Image Gallery replica numbers. 对于实例数多达 600 的每个池,我们建议至少保留一个副本。For every pool with up to 600 instances, we recommend you keep at least one replica. 例如,如果创建的池包含 3000 个 VM,则应保留至少 5 个映像副本。For example, if you are creating a pool with 3000 VMs, you should keep at least 5 replicas of your image. 我们始终建议保留超出最低要求的副本数,以便获取更佳性能。We always suggest keeping more replicas than minimum requirements for better performance.

  • 重设大小超时 如果池包含固定数目的节点(如果池不会自动缩放),请根据池大小增大池的 resizeTimeout 属性的值。Resize timeout If your pool contains a fixed number of nodes (if it doesn't autoscale), increase the resizeTimeout property of the pool depending on the pool size. 建议将每 1000 个 VM 的重设大小超时设置为至少 15 分钟。For every 1000 VMs, the recommended resize timeout is at least 15 minutes. 例如,如果池包含 2000 个 VM,建议将重设大小超时设置为至少 30 分钟。For example, the recommended resize timeout for a pool with 2000 VMs is at least 30 minutes.

后续步骤Next steps