Azure 虚拟机规模集和附加数据磁盘Azure virtual machine scale sets and attached data disks

为了扩展可用存储,Azure 虚拟机规模集支持包含附加数据磁盘的 VM 实例。To expand your available storage, Azure virtual machine scale sets support VM instances with attached data disks. 可以在创建规模集时附加数据磁盘,也可以将数据磁盘附加到现有规模集。You can attach data disks when the scale set is created, or to an existing scale set.

备注

创建包含附加数据磁盘的规模集时,需要在 VM 中装载并格式化这些磁盘,才能使用(就像标准 Azure VM 一样)。When you create a scale set with attached data disks, you need to mount and format the disks from within a VM to use them (just like for standalone Azure VMs). 若要完成此过程,可使用自定义脚本扩展来调用脚本,将 VM 中的所有数据磁盘分区和格式化,这是一种很方便的方法。A convenient way to complete this process is to use a Custom Script Extension that calls a script to partition and format all the data disks on a VM. 有关此方法的示例,请参阅 Azure CLI Azure PowerShellFor examples of this, see Azure CLI Azure PowerShell.

在规模集中创建和管理磁盘Create and manage disks in a scale set

有关如何创建包含附加数据磁盘的规模集、准备和格式化或添加和删除数据磁盘的详细信息,请参阅以下教程之一:For detailed information on how to create a scale set with attached data disks, prepare and format, or add and remove data disks, see one of the following tutorials:

本文的余下内容概述具体的用例,例如,需要数据磁盘的 Service Fabric 群集,或者将包含内容的现有数据磁盘附加到规模集。The rest of this article outlines specific use cases such as Service Fabric clusters that require data disks, or attaching existing data disks with content to a scale set.

使用附加的数据磁盘创建 Service Fabric 群集Create a Service Fabric cluster with attached data disks

在 Azure 中运行的 Service Fabric 群集中的每个节点类型都受虚拟机规模集的支持。Each node type in a Service Fabric cluster running in Azure is backed by a virtual machine scale set. 可以使用 Azure 资源管理器模板将数据磁盘附加到组成 Service Fabric 群集的规模集。Using an Azure Resource Manager template, you can attach data disks to the scale set(s) that make up the Service Fabric cluster. 可以使用现有模板作为起点。You can use an existing template as a starting point. 在模板中包括 Microsoft.Compute/virtualMachineScaleSets 资源的 storageProfile 中的 dataDisks 节,然后部署模板。In the template, include a dataDisks section in the storageProfile of the Microsoft.Compute/virtualMachineScaleSets resource(s) and deploy the template. 以下示例附加一个 128 GB 的数据磁盘:The following example attaches a 128 GB data disk:

"dataDisks": [
    {
    "diskSizeGB": 128,
    "lun": 0,
    "createOption": "Empty"
    }
]

可以在部署群集时自动对数据磁盘执行分区、格式化和装载操作。You can automatically partition, format, and mount the data disks when the cluster is deployed. 向规模集的 virtualMachineProfileextensionProfile 添加自定义脚本扩展。Add a custom script extension to the extensionProfile of the virtualMachineProfile of the scale set(s).

若要自动准备 Windows 群集中的数据磁盘,请添加以下代码:To automatically prepare the data disk(s) in a Windows cluster, add the following:

{
    "name": "customScript",
    "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.8",
        "autoUpgradeMinorVersion": true,
        "settings": {
        "fileUris": [
            "https://raw.githubusercontent.com/Azure-Samples/compute-automation-configurations/master/prepare_vm_disks.ps1"
        ],
        "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File prepare_vm_disks.ps1"
        }
    }
}

若要自动准备 Linux 群集中的数据磁盘,请添加以下代码:To automatically prepare the data disk(s) in a Linux cluster, add the following:

{
    "name": "lapextension",
    "properties": {
        "publisher": "Microsoft.Azure.Extensions",
        "type": "CustomScript",
        "typeHandlerVersion": "2.0",
        "autoUpgradeMinorVersion": true,
        "settings": {
        "fileUris": [
            "https://raw.githubusercontent.com/Azure-Samples/compute-automation-configurations/master/prepare_vm_disks.sh"
        ],
        "commandToExecute": "bash prepare_vm_disks.sh"
        }
    }
}

将预先填充的数据磁盘添加到现有规模集Adding pre-populated data disks to an existing scale set

规模集模型中指定的数据磁盘始终为空。Data disks specified in the scale set model are always empty. 但是,可以将现有数据磁盘附加到规模集中的特定 VM。However, you may attach an existing data disk to a specific VM in a scale set. 如果想要将数据传播到规模集中的所有 VM,可以复制数据磁盘并将其附加到规模集中的每个 VM,或者创建包含数据的自定义映像,并通过此自定义映像预配规模集,也可以使用 Azure 文件存储或类似的数据存储产品/服务。If you wish to propagate data across all VMs in the scale set, you may duplicate your data disk and attach it to each VM in the scale set, or create a custom image that contains the data and provision the scale set from this custom image, or you may use Azure Files or a similar data storage offering.

附加说明Additional notes

Microsoft.Compute API 2016-04-30-preview 或更高版本中提供了对 Azure 托管磁盘和规模集附加数据磁盘的支持。Support for Azure Managed disks and scale set attached data disks is available in API version 2016-04-30-preview or later of the Microsoft.Compute API.

Azure 门户对规模集中附加数据磁盘的支持是有限的。Azure portal support for attached data disks in scale sets is limited. 可以根据需要使用 Azure 模板、CLI、PowerShell、SDK 和 REST API 管理附加磁盘。Depending on your requirements you can use Azure templates, CLI, PowerShell, SDKs, and REST API to manage attached disks.