从托管映像创建 VMCreate a VM from a managed image

可以使用 Azure 门户或 PowerShell 基于 Azure 托管 VM 映像创建多台虚拟机 (VM)。You can create multiple virtual machines (VMs) from an Azure managed VM image using the Azure portal or PowerShell. 托管 VM 映像包含创建 VM 所需的信息,包括 OS 和数据磁盘。A managed VM image contains the information necessary to create a VM, including the OS and data disks. 构成映像的虚拟硬盘 (VHD)(包括 OS 磁盘和任何数据磁盘)均作为托管磁盘存储。The virtual hard disks (VHDs) that make up the image, including both the OS disks and any data disks, are stored as managed disks.

在创建新的 VM 之前,需要创建托管 VM 映像以用作源映像,并向应有权访问该映像的任何用户授予对该映像的读取权限。Before creating a new VM, you'll need to create a managed VM image to use as the source image and grant read access on the image to any user who should have access to the image.

一个托管映像最多支持 20 个同时部署。One managed image supports up to 20 simultaneous deployments. 如果尝试从同一托管映像同时创建超过 20 个 VM,则可能会由于单个 VHD 的存储性能限制而导致预配超时。Attempting to create more than 20 VMs concurrently, from the same managed image, may result in provisioning timeouts due to the storage performance limitations of a single VHD. 若要同时创建 20 个以上的 VM,请使用为每 20 个并发 VM 部署配置 1 个副本的共享映像库映像。To create more than 20 VMs concurrently, use a Shared Image Galleries image configured with 1 replica for every 20 concurrent VM deployments.

使用门户Use the portal

  1. 转到 Azure 门户查找托管映像。Go to the Azure portal to find a managed image. 搜索并选择“映像”。Search for and select Images.
  2. 从列表中选择需要使用的映像。Select the image you want to use from the list. 随即打开映像“概述”页。The image Overview page opens.
  3. 从菜单中选择“创建 VM”。Select Create VM from the menu.
  4. 输入虚拟机信息。Enter the virtual machine information. 在此处输入的用户名和密码将用来登录到虚拟机。The user name and password entered here will be used to log in to the virtual machine. 完成后选择“确定”。When complete, select OK. 可以在现有资源组中创建新的 VM,或者选择“新建”创建一个新的资源组用于存储 VM。You can create the new VM in an existing resource group, or choose Create new to create a new resource group to store the VM.
  5. 为 VM 选择大小。Select a size for the VM. 若要查看更多的大小,请选择“全部查看”或更改“支持的磁盘类型”筛选器。To see more sizes, select View all or change the Supported disk type filter.
  6. 在“设置”下,根据需要进行更改并选择“确定” 。Under Settings, make changes as necessary and select OK.
  7. 在摘要页上,应该可以看见你的映像名称作为“专用映像”列出。On the summary page, you should see your image name listed as a Private image. 选择“确定”以启动虚拟机部署。Select Ok to start the virtual machine deployment.

使用 PowerShellUse PowerShell

可以使用 PowerShell 通过使用 New-AzVm cmdlet 的简化参数集来基于映像创建 VM。You can use PowerShell to create a VM from an image by using the simplified parameter set for the New-AzVm cmdlet. 该映像需要位于你要在其中创建 VM 的同一资源组中。The image needs to be in the same resource group where you'll create the VM.

New-AzVm 的简化参数集仅要求提供名称、资源组和映像名称便可基于映像创建 VM。The simplified parameter set for New-AzVm only requires that you provide a name, resource group, and image name to create a VM from an image. New-AzVm 将使用 -Name 参数的值作为它自动创建的所有资源的名称。New-AzVm will use the value of the -Name parameter as the name of all of the resources that it creates automatically. 在此示例中,我们为每个资源提供更详细的名称,但让 cmdlet 自动创建这些资源。In this example, we provide more detailed names for each of the resources but let the cmdlet create them automatically. 你还可以提前创建资源(例如虚拟网络)并将名称传递给 cmdlet。You can also create resources beforehand, such as the virtual network, and pass the resource name into the cmdlet. 如果 New-AzVm 可以通过名称找到现有资源,就会使用现有资源。New-AzVm will use the existing resources if it can find them by their name.

以下示例在“myResourceGroup”资源组中从名为“myImage”的映像创建名为“myVMFromImage”的 VM。The following example creates a VM named myVMFromImage, in the myResourceGroup resource group, from the image named myImage.

New-AzVm `
    -ResourceGroupName "myResourceGroup" `
    -Name "myVMfromImage" `
    -ImageName "myImage" `
    -Location "China East" `
    -VirtualNetworkName "myImageVnet" `
    -SubnetName "myImageSubnet" `
    -SecurityGroupName "myImageNSG" `
    -PublicIpAddressName "myImagePIP" `
    -OpenPorts 3389

后续步骤Next steps

使用 Azure PowerShell 模块创建和管理 Windows VMCreate and manage Windows VMs with the Azure PowerShell module