您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

预览版:使用 Azure PowerShell 将 Vm 部署到专用主机Preview: Deploy VMs to dedicated hosts using the Azure PowerShell

本文介绍如何创建 Azure专用主机来托管虚拟机(vm)。This article guides you through how to create an Azure dedicated host to host your virtual machines (VMs).

请确保已安装 Azure PowerShell 版本 2.4.2 sections 或更高版本,并且已使用Connect-AzAccount登录到 Azure 帐户。Make sure that you have installed Azure PowerShell version 2.4.2 or later, and you are signed in to an Azure account in with Connect-AzAccount. 若要安装版本 2.4.2 sections,请打开 PowerShell 提示符,然后键入:To install version 2.4.2, open a PowerShell prompt and type:

Install-Module -Name Az.Compute -Repository PSGallery -RequiredVersion 2.4.2-preview -AllowPrerelease

需要至少1.6.0 版本的 PowerShellGet 模块才能在 PowerShell 中启用预览模块功能。You will need at least version 1.6.0 of the PowerShellGet module to enable preview module functionality in PowerShell. 最新版本的 PowerShell Core 自动内置此项,但对于较早版本的 PowerShell,你可以运行以下命令以更新到最新版本:The latest versions of PowerShell Core have this automatically built in, but for older versions of PowerShell, you can run the following command to update to the latest version:

Install-Module -Name PowerShellGet -Repository PSGallery -Force

重要

Azure 专用主机目前为公共预览版。Azure Dedicated Hosts is currently in public preview. 此预览版在提供时没有附带服务级别协议,不建议将其用于生产工作负荷。This preview version is provided without a service level agreement, and it's not recommended for production workloads. 某些功能可能不受支持或者受限。Certain features might not be supported or might have constrained capabilities. 有关详细信息,请参阅 Microsoft Azure 预览版补充使用条款For more information, see Supplemental Terms of Use for Microsoft Azure Previews.

已知预览版限制Known preview limitations

  • 虚拟机规模集目前在专用主机上不受支持。Virtual machine scale sets are not currently supported on dedicated hosts.
  • 预览版初始版本支持以下 VM 系列:DSv3 和 ESv3。The preview initial release supports the following VM series: DSv3 and ESv3.

创建主机组Create a host group

主机组是代表专用主机集合的资源。A host group is a resource that represents a collection of dedicated hosts. 在区域和可用性区域中创建主机组,并向其添加主机。You create a host group in a region and an availability zone, and add hosts to it. 规划高可用性时,有其他选项可供选择。When planning for high availability, there are additional options. 你可以将以下一个或两个选项与专用主机一起使用:You can use one or both of the following options with your dedicated hosts:

  • 跨多个可用性区域。Span across multiple availability zones. 在这种情况下,你需要在要使用的每个区域中都有一个主机组。In this case, you are required to have a host group in each of the zones you wish to use.
  • 跨多个容错域,这些容错域映射到物理机架。Span across multiple fault domains which are mapped to physical racks.

在任一情况下,都需要提供主机组的容错域计数。In either case, you are need to provide the fault domain count for your host group. 如果你不希望跨组中的容错域,请使用容错域计数1。If you do not want to span fault domains in your group, use a fault domain count of 1.

您还可以决定使用可用性区域和容错域。You can also decide to use both availability zones and fault domains. 此示例将在区域1中创建具有2个容错域的主机组。This example creates a host group in zone 1, with 2 fault domains.

$rgName = "myDHResourceGroup"
$location = "East US"

New-AzResourceGroup -Location $location -Name $rgName
$hostGroup = New-AzHostGroup `
   -Location $location `
   -Name myHostGroup `
   -PlatformFaultDomain 2 `
   -ResourceGroupName $rgName `
   -Zone 1

创建主机Create a host

现在,让我们在主机组中创建一个专用主机。Now let's create a dedicated host in the host group. 除了主机名称外,还需要提供主机的 SKU。In addition to a name for the host, you are required to provide the SKU for the host. 主机 SKU 捕获受支持的 VM 系列以及专用主机的硬件生成。Host SKU captures the supported VM series as well as the hardware generation for your dedicated host. 在预览期间,我们将支持以下主机 SKU 值:DSv3_Type1 和 ESv3_Type1。During the preview, we will support the following host SKU values: DSv3_Type1 and ESv3_Type1.

有关主机 Sku 和定价的详细信息,请参阅Azure 专用主机定价For more information about the host SKUs and pricing, see Azure Dedicated Host pricing.

如果为主机组设置了容错域计数,系统会要求你为主机指定容错域。If you set a fault domain count for your host group, you will be asked to specify the fault domain for your host. 在此示例中,我们将主机的容错域设置为1。In this example, we set the fault domain for the host to 1.

$dHost = New-AzHost `
   -HostGroupName $hostGroup.Name `
   -Location $location -Name myHost `
   -ResourceGroupName $rgName `
   -Sku DSv3-Type1 `
   -AutoReplaceOnFailure 1 `
   -PlatformFaultDomain 1

创建 VMCreate a VM

在专用主机上创建虚拟机。Create a virtual machine on the dedicated host.

如果在创建主机组时指定了可用性区域,则需要在创建虚拟机时使用同一区域。If you specified an availability zone when creating your host group, you are required to use the same zone when creating the virtual machine. 在此示例中,由于我们的主机组在区域1中,因此需要在区域1中创建 VM。For this example, because our host group is in zone 1, we need to create the VM in zone 1.

$cred = Get-Credential
New-AzVM `
   -Credential $cred `
   -ResourceGroupName $rgName `
   -Location $location `
   -Name myVM `
   -HostId $dhost.Id `
   -Image Win2016Datacenter `
   -Zone 1 `
   -Size Standard_D4s_v3

警告

如果在没有足够资源的主机上创建虚拟机,则虚拟机将创建为失败状态。If you create a virtual machine on a host which does not have enough resources, the virtual machine will be created in a FAILED state.

检查主机的状态Check the status of the host

你可以使用GetAzHost -InstanceView和参数检查主机运行状况状态,以及你仍可以将多个虚拟机部署到主机。You can check the host health status and how many virtual machines you can still deploy to the host using GetAzHost with the -InstanceView parameter.

Get-AzHost `
   -ResourceGroupName $rgName `
   -Name myHost `
   -HostGroupName $hostGroup.Name `
   -InstanceView

输出与此类似:The output will look similar to this:

ResourceGroupName      : myDHResourceGroup
PlatformFaultDomain    : 1
AutoReplaceOnFailure   : True
HostId                 : 12345678-1234-1234-abcd-abc123456789
ProvisioningTime       : 7/28/2019 5:31:01 PM
ProvisioningState      : Succeeded
InstanceView           : 
  AssetId              : abc45678-abcd-1234-abcd-123456789abc
  AvailableCapacity    : 
    AllocatableVMs[0]  : 
      VmSize           : Standard_D2s_v3
      Count            : 32
    AllocatableVMs[1]  : 
      VmSize           : Standard_D4s_v3
      Count            : 16
    AllocatableVMs[2]  : 
      VmSize           : Standard_D8s_v3
      Count            : 8
    AllocatableVMs[3]  : 
      VmSize           : Standard_D16s_v3
      Count            : 4
    AllocatableVMs[4]  : 
      VmSize           : Standard_D32-8s_v3
      Count            : 2
    AllocatableVMs[5]  : 
      VmSize           : Standard_D32-16s_v3
      Count            : 2
    AllocatableVMs[6]  : 
      VmSize           : Standard_D32s_v3
      Count            : 2
    AllocatableVMs[7]  : 
      VmSize           : Standard_D64-16s_v3
      Count            : 1
    AllocatableVMs[8]  : 
      VmSize           : Standard_D64-32s_v3
      Count            : 1
    AllocatableVMs[9]  : 
      VmSize           : Standard_D64s_v3
      Count            : 1
  Statuses[0]          : 
    Code               : ProvisioningState/succeeded
    Level              : Info
    DisplayStatus      : Provisioning succeeded
    Time               : 7/28/2019 5:31:01 PM
  Statuses[1]          : 
    Code               : HealthState/available
    Level              : Info
    DisplayStatus      : Host available
Sku                    : 
  Name                 : DSv3-Type1
Id                     : /subscriptions/10101010-1010-1010-1010-101010101010/re
sourceGroups/myDHResourceGroup/providers/Microsoft.Compute/hostGroups/myHostGroup/hosts
/myHost
Name                   : myHost
Location               : eastus
Tags                   : {}

清理Clean up

即使部署了虚拟机,也需要为你的专用主机付费。You are being charged for your dedicated hosts even when no virtual machines are deployed. 应删除当前未使用的任何主机以节省成本。You should delete any hosts you are currently not using to save costs.

只有在没有任何更长的虚拟机使用它时,才能删除该主机。You can only delete a host when there are no any longer virtual machines using it. 使用new-azvm删除 vm。Delete the VMs using Remove-AzVM.

Remove-AzVM -ResourceGroupName $rgName -Name myVM

删除 Vm 后,可以使用AzHost删除该主机。After deleting the VMs, you can delete the host using Remove-AzHost.

Remove-AzHost -ResourceGroupName $rgName -Name myHost

删除所有主机后,可以使用AzHostGroup删除该主机组。Once you have deleted all of your hosts, you may delete the host group using Remove-AzHostGroup.

Remove-AzHost -ResourceGroupName $rgName -Name myHost

还可以使用AzResourceGroup在单个命令中删除整个资源组。You can also delete the entire resource group in a single command using Remove-AzResourceGroup. 这会删除在组中创建的所有资源,包括所有 Vm、主机和主机组。This will delete all resources created in the group, including all of the VMs, hosts and host groups.

Remove-AzResourceGroup -Name $rgName

后续步骤Next steps

  • 这里有一个示例模板,它使用区域和容错域实现了区域中的最大复原能力。There is sample template, found here, that uses both zones and fault domains for maximum resiliency in a region.

  • 你还可以使用Azure 门户部署专用主机。You can also deploy dedicated hosts using the Azure portal.