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

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

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

请确保已安装 Azure CLI 版本2.0.70 或更高版本,并使用 az login登录到 Azure 帐户。Make sure that you have installed Azure CLI version 2.0.70 or later, and signed in to an Azure account using az login.

重要

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 resource group

Azure 资源组是在其中部署和管理 Azure 资源的逻辑容器。An Azure resource group is a logical container into which Azure resources are deployed and managed. 用 az group create 创建资源组。Create the resource group with az group create. 以下示例在美国东部位置创建名为myDHResourceGroup的资源组。The following example creates a resource group named myDHResourceGroup in the East US location.

az group create --name myDHResourceGroup --location eastus 

创建主机组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.

在此示例中,我们将使用az vm host group create创建使用可用性区域和容错域的主机组。In this example, we will use az vm host group create to create a host group using both availability zones and fault domains.

az vm host group create \
   --name myHostGroup \
   -g myDHResourceGroup \
   -z 1 \
   --platform-fault-domain-count 2 

其他示例Other examples

你还可以使用az vm host group create在可用性区域1(而不是容错域)中创建主机组。You can also use az vm host group create to create a host group in availability zone 1 (and no fault domains).

az vm host group create \
   --name myAZHostGroup \
   -g myDHResourceGroup \
   -z 1 \
   --platform-fault-domain-count 1 

以下方法使用az vm host group create来通过仅使用容错域创建主机组(在不支持可用性区域的区域中使用)。The following uses az vm host group create to create a host group by using fault domains only (to be used in regions where availability zones are not supported).

az vm host group create \
   --name myFDHostGroup \
   -g myDHResourceGroup \
   --platform-fault-domain-count 2 

创建主机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.

使用az vm host create创建主机。Use az vm host create to create a host. 如果为主机组设置了容错域计数,系统会要求你为主机指定容错域。If you set a fault domain count for your host group, you will be asked to specify the fault domain for your host.

az vm host create \
   --host-group myHostGroup \
   --name myHost \
   --sku DSv3-Type1 \
   --platform-fault-domain 1 \
   -g myDHResourceGroup

创建虚拟机Create a virtual machine

使用az vm create创建专用主机中的虚拟机。Create a virtual machine within a dedicated host using az vm create. 如果在创建主机组时指定了可用性区域,则需要在创建虚拟机时使用同一区域。If you specified an availability zone when creating your host group, you are required to use the same zone when creating the virtual machine.

az vm create \
   -n myVM \
   --image debian \
   --generate-ssh-keys \
   --host-group myHostGroup \
   --host myHost \
   --generate-ssh-keys \
   --size Standard_D4s_v3 \
   -g myDHResourceGroup \
   --zone 1

警告

如果在没有足够资源的主机上创建虚拟机,则虚拟机将创建为失败状态。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

你可以使用az vm host get instance view 查看主机运行状况状态以及仍可部署到主机的虚拟机数。You can check the host health status and how many virtual machines you can still deploy to the host using az vm host get-instance-view.

az vm host get-instance-view \
   -g myDHResourceGroup \
   --host-group myHostGroup \
   --name myHost

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

{
  "autoReplaceOnFailure": true,
  "hostId": "6de80643-0f45-4e94-9a4c-c49d5c777b62",
  "id": "/subscriptions/10101010-1010-1010-1010-101010101010/resourceGroups/myDHResourceGroup/providers/Microsoft.Compute/hostGroups/myHostGroup/hosts/myHost",
  "instanceView": {
    "assetId": "12345678-1234-1234-abcd-abc123456789",
    "availableCapacity": {
      "allocatableVms": [
        {
          "count": 31.0,
          "vmSize": "Standard_D2s_v3"
        },
        {
          "count": 15.0,
          "vmSize": "Standard_D4s_v3"
        },
        {
          "count": 7.0,
          "vmSize": "Standard_D8s_v3"
        },
        {
          "count": 3.0,
          "vmSize": "Standard_D16s_v3"
        },
        {
          "count": 1.0,
          "vmSize": "Standard_D32-8s_v3"
        },
        {
          "count": 1.0,
          "vmSize": "Standard_D32-16s_v3"
        },
        {
          "count": 1.0,
          "vmSize": "Standard_D32s_v3"
        },
        {
          "count": 1.0,
          "vmSize": "Standard_D48s_v3"
        },
        {
          "count": 0.0,
          "vmSize": "Standard_D64-16s_v3"
        },
        {
          "count": 0.0,
          "vmSize": "Standard_D64-32s_v3"
        },
        {
          "count": 0.0,
          "vmSize": "Standard_D64s_v3"
        }
      ]
    },
    "statuses": [
      {
        "code": "ProvisioningState/succeeded",
        "displayStatus": "Provisioning succeeded",
        "level": "Info",
        "message": null,
        "time": "2019-07-24T21:22:40.604754+00:00"
      },
      {
        "code": "HealthState/available",
        "displayStatus": "Host available",
        "level": "Info",
        "message": null,
        "time": null
      }
    ]
  },
  "licenseType": null,
  "location": "eastus2",
  "name": "myHost",
  "platformFaultDomain": 1,
  "provisioningState": "Succeeded",
  "provisioningTime": "2019-07-24T21:22:40.604754+00:00",
  "resourceGroup": "myDHResourceGroup",
  "sku": {
    "capacity": null,
    "name": "DSv3-Type1",
    "tier": null
  },
  "tags": null,
  "type": null,
  "virtualMachines": [
    {
      "id": "/subscriptions/10101010-1010-1010-1010-101010101010/resourceGroups/MYDHRESOURCEGROUP/providers/Microsoft.Compute/virtualMachines/MYVM",
      "resourceGroup": "MYDHRESOURCEGROUP"
    }
  ]
}

作为模板导出Export as a template

如果现在想要创建具有相同参数的其他开发环境或与其匹配的生产环境,则可以导出模板。You can export a template if you now want to create an additional development environment with the same parameters, or a production environment that matches it. Resource Manager 使用定义了所有环境参数的 JSON 模板。Resource Manager uses JSON templates that define all the parameters for your environment. 通过引用此 JSON 模板构建出整个环境。You build out entire environments by referencing this JSON template. 可以手动构建 JSON 模板,也可以导出现有的环境以创建 JSON 模板。You can build JSON templates manually or export an existing environment to create the JSON template for you. 使用az group export导出资源组。Use az group export to export your resource group.

az group export --name myDHResourceGroup > myDHResourceGroup.json 

此命令在当前工作目录中创建 myDHResourceGroup.json 文件。This command creates the myDHResourceGroup.json file in your current working directory. 从此模板创建环境时,系统会提示输入所有资源名称。When you create an environment from this template, you are prompted for all the resource names. 可以通过将 --include-parameter-default-value 参数添加到 az group export 命令在模板文件中填充这些名称。You can populate these names in your template file by adding the --include-parameter-default-value parameter to the az group export command. 编辑 JSON 模板以指定资源名称,或创建指定资源名称的 json 文件。Edit your JSON template to specify the resource names, or create a parameters.json file that specifies the resource names.

若要从模板创建环境,请使用az group deployment createTo create an environment from your template, use az group deployment create.

az group deployment create \ 
    --resource-group myNewResourceGroup \ 
    --template-file myDHResourceGroup.json 

清理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. 使用az vm delete删除 vm。Delete the VMs using az vm delete.

az vm delete -n myVM -g myDHResourceGroup

删除 Vm 后,你可以使用az vm host delete删除该主机。After deleting the VMs, you can delete the host using az vm host delete.

az vm host delete -g myDHResourceGroup --host-group myHostGroup --name myHost 

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

az vm host group delete -g myDHResourceGroup --host-group myHostGroup  

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

az group delete -n myDHResourceGroup 

后续步骤Next steps

  • 有关详细信息,请参阅专用主机概述。For more information, see the Dedicated hosts overview.

  • 你还可以使用Azure 门户创建专用主机。You can also create dedicated hosts using the Azure portal.

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