了解 Azure VM 规模集 VM 的实例 IDUnderstand instance IDs for Azure VM scale set VMs

本文介绍规模集的实例 ID 和显示这些 ID 的各种方法。This article describes instance IDs for scale sets and the various ways they surface.

规模集实例 IDScale set instance IDs

规模集中的每个 VM 均获得唯一标识它的实例 ID。Each VM in a scale set gets an instance ID that uniquely identifies it. 可在规模集 API 中使用此实例 ID 对规模集中的特定 VM 执行操作。This instance ID is used in the scale set APIs to do operations on a specific VM in the scale set. 例如,使用重置映像 API 时,可以指定特定实例 ID 以重置映像:For instance, you can specify a specific instance ID to reimage when using the reimage API:

REST API:POST https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/virtualmachines/{instanceId}/reimage?api-version={apiVersion}(有关详细信息,请参阅 REST API 文档REST API: POST https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/virtualmachines/{instanceId}/reimage?api-version={apiVersion} (for more information, see the REST API documentation)

PowerShell:Set-AzVmssVM -ResourceGroupName {resourceGroupName} -VMScaleSetName {vmScaleSetName} -InstanceId {instanceId} -Reimage(有关详细信息,请参阅 PowerShell 文档Powershell: Set-AzVmssVM -ResourceGroupName {resourceGroupName} -VMScaleSetName {vmScaleSetName} -InstanceId {instanceId} -Reimage (for more information, see the Powershell documentation)

CLI:az vmss reimage -g {resourceGroupName} -n {vmScaleSetName} --instance-id {instanceId}(有关详细信息,请参阅 CLI 文档)。CLI: az vmss reimage -g {resourceGroupName} -n {vmScaleSetName} --instance-id {instanceId} (for more information, see the CLI documentation).

可以通过列出规模集中的所有实例来获取实例 ID 的列表:You can get the list of instance IDs by listing all instances in a scale set:

REST API:GET https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/virtualMachines?api-version={apiVersion}(有关详细信息,请参阅 REST API 文档REST API: GET https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/virtualMachines?api-version={apiVersion} (for more information, see the REST API documentation)

PowerShell:Get-AzVmssVM -ResourceGroupName {resourceGroupName} -VMScaleSetName {vmScaleSetName}(有关详细信息,请参阅 PowerShell 文档Powershell: Get-AzVmssVM -ResourceGroupName {resourceGroupName} -VMScaleSetName {vmScaleSetName} (for more information, see the Powershell documentation)

CLI:az vmss list-instances -g {resourceGroupName} -n {vmScaleSetName}(有关详细信息,请参阅 CLI 文档)。CLI: az vmss list-instances -g {resourceGroupName} -n {vmScaleSetName} (for more information, see the CLI documentation).

也可使用 Azure SDK 列出规模集中的 VM。You can also use the Azure SDKs to list the VMs in a scale set.

下面是 CLI 的某个示例输出,但输出的具体呈现取决于提供给命令的选项:The exact presentation of the output depends on the options you provide to the command, but here is some sample output from the CLI:

az vmss show -g {resourceGroupName} -n {vmScaleSetName}
[
  {
    "instanceId": "85",
    "latestModelApplied": true,
    "location": "chinanorth",
    "name": "nsgvmss_85",
    .
    .
    .

如你所见,“instanceId”属性只是一个十进制数。As you can see, the "instanceId" property is just a decimal number. 删除旧实例后,实例 ID 可以重新用于新实例。The instance IDs may be reused for new instances once old instances are deleted.

备注

对于将实例 ID 分配给规模集中的 VM 的方式 没有保证There is no guarantee on the way instance IDs are assigned to the VMs in the scale set. 有时它们可能会按顺序递增,但并非总是这种情况。They might seem sequentially increasing at times, but this is not always the case. 不要依赖于将实例 ID 分配给 VM 的特定方式。Do not take a dependency on the specific way in which instance IDs are assigned to the VMs.

规模集 VM 名称Scale set VM names

在上面的示例输出中,也有 VM 的“名称”。In the sample output above, there is also a "name" for the VM. 此名称采用“{scale-set-name}{instance-id}”格式。This name takes the form "{scale-set-name}{instance-id}". 在 Azure 门户中列出规模集中的实例时会看到此名称:This name is the one that you see in the Azure portal when you list instances in a scale set:

显示 Azure 门户中虚拟机规模集的实例列表的屏幕截图。

名称的 {instance-id} 部分是与前面所述的“instanceId”属性相同的十进制数。The {instance-id} part of the name is the same decimal number as the "instanceId" property discussed previously.

实例元数据 VM 名称Instance Metadata VM name

如果从规模集 VM 中查询实例元数据,会在输出中看到“名称”:If you query the instance metadata from within a scale set VM, you see a "name" in the output:

{
  "compute": {
    "location": "chinanorth",
    "name": "nsgvmss_85",
    .
    .
    .

此名称与前面所述的名称相同。This name is the same as the name discussed previously.

规模集 VM 的计算机名Scale set VM computer name

规模集中的每个 VM 还会获得一个分配给它的计算机名称。Each VM in a scale set also gets a computer name assigned to it. 此计算机名在虚拟网络中 Azure 提供的 DNS 名称解析中是 VM 的主机名。This computer name is the hostname of the VM in the Azure-provided DNS name resolution within the virtual network. 此计算机名的格式为“{computer-name-prefix}{base-36-instance-id}”。This computer name is of the form "{computer-name-prefix}{base-36-instance-id}".

{base-36-instance-id} 以 36 为基数并且长度始终为六位。The {base-36-instance-id} is in base 36 and is always six digits in length. 如果数字的基于 36 的表示形式采用的位数少于六位,{base-36-instance-id} 将使用零进行填充以使其长度为六位。If the base 36 representation of the number takes fewer than six digits, the {base-36-instance-id} is padded with zeros to make it six digits in length. 例如,{computer-name-prefix} 为“nsgvmss”且实例 ID 为 85 的实例将具有计算机名称“nsgvmss00002D”。For example, an instance with {computer-name-prefix} "nsgvmss" and instance ID 85 will have computer name "nsgvmss00002D".

备注

计算机名称前缀是规模集模型中可以设置的属性,因此它可以与规模集名称本身不同。The computer name prefix is a property of the scale set model that you can set, so it can be different from the scale set name itself.