如何使用启动诊断功能来排查 Azure 中虚拟机的问题How to use boot diagnostics to troubleshoot virtual machines in Azure

虚拟机进入非可启动状态的原因可能有很多。There can be many reasons that a virtual machine enters a non-bootable state. 若要解决使用资源管理器部署模型创建的虚拟机存在的问题,可以使用下面的调试功能:对 Azure 虚拟机的控制台输出和屏幕截图支持。To address issues with your virtual machines created using Resource Manager deployment model you can use the following debugging features: Console Output and Screenshot support for Azure virtual machines.

对于 Linux 虚拟机,可以在门户中查看控制台日志的输出。For Linux virtual machines, you can view the output of your console log from the Portal. 对于 Windows 和 Linux 虚拟机,Azure 允许你通过虚拟机监控程序查看 VM 的屏幕截图。For both Windows and Linux virtual machines, Azure enables you to see a screenshot of the VM from the hypervisor. 所有区域中的 Azure 虚拟机都支持这两项功能。Both features are supported for Azure virtual machines in all regions. 请注意,屏幕截图和输出可能需要长达 10 分钟的时间才能显示在存储帐户中。Note, screenshots, and output can take up to 10 minutes to appear in your storage account.

可以选择“启动诊断” 选项以查看日志和屏幕截图。You can select the Boot diagnostics option to view the log and the screenshot.

Resource Manager

常见的启动错误Common boot errors

在使用 Azure 门户创建的虚拟机上启用诊断Enable diagnostics on a virtual machine created using the Azure Portal

以下过程适用于使用资源管理器部署模型创建的虚拟机。The following procedure is for a virtual machine created using the Resource Manager deployment model.

在“管理”选项卡上的“监视”部分中 ,确保“启动诊断”处于打开状态 。On the Management tab, in Monitoring section, make sure that Boot diagnostics is turned on. 从“诊断存储帐户”下拉列表中 ,选择要将诊断文件放入到的存储帐户。From the Diagnostics storage account drop-down list, select a storage account in which to place the diagnostic files.

创建 VM

Note

启动诊断功能不支持高级存储帐户。The Boot diagnostics feature does not support premium storage account. 如果使用高级存储帐户进行启动诊断,则可能会在启动 VM 时收到 StorageAccountTypeNotSupported 错误。If you use the premium storage account for Boot diagnostics, you might receive the StorageAccountTypeNotSupported error when you start the VM.

通过 Azure 资源管理器模板部署Deploying from an Azure Resource Manager template

若要从 Azure 资源管理器模板进行部署,请导航到虚拟机资源,并追加诊断配置文件部分。If you are deploying from an Azure Resource Manager template, navigate to your virtual machine resource and append the diagnostics profile section. 将 API 版本标头设置为“2015-06-15”或更新版本。Set the API version header to "2015-06-15" or later. 最新版本是“2018-10-01”。The latest version is "2018-10-01".

{
  "apiVersion": "2018-10-01",
  "type": "Microsoft.Compute/virtualMachines",
  … 

可以通过诊断配置文件选择要在其中放置这些日志的存储帐户。The diagnostics profile enables you to select the storage account where you want to put these logs.

    "diagnosticsProfile": {
    "bootDiagnostics": {
    "enabled": true,
    "storageUri": "[concat('https://', parameters('newStorageAccountName'), '.blob.core.chinacloudapi.cn')]"
    }
    }
    }
}

有关使用模板部署资源的详细信息,请参阅快速入门:使用 Azure 门户创建和部署 Azure 资源管理器模板For more information on deploying resources using templates, see Quickstart: Create and deploy Azure Resource Manager templates by using the Azure portal.

在现有的虚拟机上启用启动诊断Enable boot diagnostics on existing virtual machine

若要在现有的虚拟机上启用启动诊断,请执行以下步骤:To enable Boot diagnostics on an existing virtual machine, follow these steps:

  1. 登录到 Azure 门户,然后选择虚拟机。Sign in to the Azure portal, and then select the virtual machine.

  2. 在“支持 + 故障排除”部分中选择“启动诊断”,然后选择“设置”选项卡 。In the Support + troubleshooting section, select Boot diagnostics, then select the Settings tab.

  3. 在“启动诊断”设置中 ,将状态更改为“开” ,然后从“存储帐户”下拉列表中选择所需的存储帐户 。In Boot diagnostics settings, change the status to On, and from the Storage account drop-down list select a storage account.

  4. 保存更改。Save the change.

    更新现有 VM

必须重新启动虚拟机才能使更改生效。You must restart the virtual machine for the change to take effect.

使用 Azure CLI 启用启动诊断Enable boot diagnostics using the Azure CLI

可以在现有的 Azure 虚拟机上使用 Azure CLI 启用启动诊断。You can use the Azure CLI to enable boot diagnostics on an existing Azure virtual machine. 有关详细信息,请参阅 az vm boot-diagnosticsFor more information, see az vm boot-diagnostics.