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

Azure 现在提供对两种调试功能的支持:控制台输出和屏幕截图支持,适用于 Azure 虚拟机资源管理器部署模型。Support for two debugging features is now available in Azure: Console Output and Screenshot support for Azure virtual machines Resource Manager deployment model.

将自己的映像加载到 Azure 或者启动某个平台映像时,可能会因为许多原因而导致虚拟机进入无法启动状态。When bringing your own image to Azure or even booting one of the platform images, there can be many reasons why a virtual machine gets into a non-bootable state. 有了这些功能,就可以轻松进行诊断,将虚拟机从启动故障恢复。These features enable you to easily diagnose and recover your virtual machines from boot failures.

对于 Linux 虚拟机,可以轻松地在门户中查看控制台日志的输出。For Linux virtual machines, you can easily view the output of your console log from the Portal. 对于 Windows 和 Linux 虚拟机,Azure 也允许从虚拟机监控程序查看 VM 的屏幕截图。For both Windows and Linux virtual machines, Azure also enables you to see a screenshot of the VM from the hypervisor. 所有区域的 Azure 虚拟机都支持这两项功能。Both of these 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

对新虚拟机启用诊断Enable diagnostics on a new virtual machine

  1. 从 Azure 门户创建新的虚拟机时,请从部署模型下拉列表中选择“Azure 资源管理器”:When creating a new virtual machine from the Azure Portal, select the Azure Resource Manager from the deployment model dropdown:

    Resource Manager

  2. 在“设置”中启用“启动诊断”,然后选择要在其中放置这些诊断文件的存储帐户。In Settings, enable the Boot diagnostics, and then select a storage account that you would like to place these 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.

  3. 若要从 Azure 资源管理器模板进行部署,请导航到虚拟机资源,并追加诊断配置文件部分。If you are deploying from an Azure Resource Manager template, navigate to your virtual machine resource and append the diagnostics profile section. 记得使用“2015-06-15”API 版本标头。Remember to use the "2015-06-15" API version header.

    {
          "apiVersion": "2015-06-15",
          "type": "Microsoft.Compute/virtualMachines",
          … 
    
  4. 可以通过诊断配置文件选择要在其中放置这些日志的存储帐户。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')]"
                }
            }
            }
        }
    

若要部署启用了启动诊断功能的示例虚拟机,请在此处查看我们的存储库。To deploy a sample virtual machine with boot diagnostics enabled, check out our repo here.

在现有的虚拟机上启用启动诊断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 Support + troubleshooting, select Boot diagnostics > Settings, change the status to On, and then select a storage account.

  3. 确保选中“启动诊断”选项,然后保存所做的更改。Make sure that the Boot diagnostics option is selected and then save the change.

    更新现有 VM

  4. 重启 VM,使设置生效。Restart the VM to take effect.