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

教程:排查资源管理器模板部署问题Tutorial: Troubleshoot Resource Manager template deployments

了解如何排查资源管理器模板部署错误。Learn how to troubleshoot Resource Manager template deployment errors. 在本教程中,请先在模板中设置两个错误,然后了解如何使用活动日志和部署历史记录来解决问题。In this tutorial, you set up two errors in a template, and learn how to use the activity logs and deployment history to resolve the issues.

有两种类型的错误与模板部署相关:There are two types of errors that are related to template deployment:

  • 验证错误源于部署之前可确定的方案。Validation errors arise from scenarios that can be determined before deployment. 原因包括模板中的语法错误,或尝试部署超出订阅配额的资源。They include syntax errors in your template, or trying to deploy resources that would exceed your subscription quotas.
  • 部署错误源于部署过程中发生的条件。Deployment errors arise from conditions that occur during the deployment process. 原因包括尝试访问并行部署的资源。They include trying to access a resource that is being deployed in parallel.

两种类型的错误都会返回用于对部署进行故障排除的错误代码。Both types of errors return an error code that you use to troubleshoot the deployment. 两种类型的错误都会显示在活动日志中。Both types of errors appear in the activity log. 但是,验证错误不会显示在部署历史记录中,因为部署从未启动。However, validation errors don't appear in your deployment history because the deployment never started.

本教程涵盖以下任务:This tutorial covers the following tasks:

  • 创建有问题的模板Create a problematic template
  • 排查验证错误Troubleshoot validation errors
  • 排查部署错误Troubleshoot deployment errors
  • 清理资源Clean up resources

如果还没有 Azure 订阅,可以在开始前创建一个免费帐户If you don't have an Azure subscription, create a free account before you begin.

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

先决条件Prerequisites

若要完成本文,需要做好以下准备:To complete this article, you need:

创建有问题的模板Create a problematic template

打开 Azure 快速入门模板中名为创建标准存储帐户的模板,设置两个模板问题。Open a template called Create a standard storage account from Azure QuickStart Templates, and setup two template issues.

  1. 在 Visual Studio Code 中,选择“文件”>“打开文件”。From Visual Studio Code, select File>Open File.

  2. 在“文件名”中粘贴以下 URL:In File name, paste the following URL:

    https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-storage-account-create/azuredeploy.json
    
  3. 选择“打开”以打开该文件。Select Open to open the file.

  4. apiVersion 行更改为以下行:Change the apiVersion line to the following line:

    "apiVersion1": "2018-07-02",
    
    • apiVersion1 是无效的元素名称。apiVersion1 is invalid element name. 它是验证错误。It is a validation error.
    • API 版本应该是“2018-07-01”。The API version shall be "2018-07-01". 它是部署错误。It is a deployment error.
  5. 选择“文件”>“另存为”,将该文件作为 azuredeploy.json 保存到本地计算机。Select File>Save As to save the file as azuredeploy.json to your local computer.

排查验证错误Troubleshoot the validation error

请参阅部署模板部分,了解如何部署模板。Refer to the Deploy the template section to deploy the template.

你会从 shell 获得类似于以下内容的错误:You shall get an error from the shell similar to:

New-AzResourceGroupDeployment : 4:29:24 PM - Error: Code=InvalidRequestContent; Message=The request content was invalid and could not be deserialized: 'Could not find member 'apiVersion1' on object of type 'TemplateResource'. Path 'properties.template.resources[0].apiVersion1', line 36, position 24.'.

错误消息指示问题出在 apiVersion1The error message indicates the problem is with apiVersion1.

使用 Visual Studio Code 修正此问题,方法是将 apiVersion1 更改为 apiVersion,然后保存模板。Use Visual Studio Code to correct the problem by changing apiVersion1 to apiVersion, and then save the template.

排查部署错误Troubleshoot the deployment error

请参阅部署模板部分,了解如何部署模板。Refer to the Deploy the template section to deploy the template.

你会从 shell 获得类似于以下内容的错误:You shall get an error from the shell similar to:

New-AzResourceGroupDeployment : 4:48:50 PM - Resource Microsoft.Storage/storageAccounts 'storeqii7x2rce77dc' failed with message '{
  "error": {
    "code": "NoRegisteredProviderFound",
    "message": "No registered resource provider found for location 'centralus' and API version '2018-07-02' for type 'storageAccounts'. The supported api-versions are '2018-07-01, 2018-03-01-preview, 2018-02-01, 2017-10-01, 2017-06-01, 2016-12-01, 2016-05-01, 2016-01-01, 2015-06-15, 2015-05-01-preview'. The supported locations are 'eastus, eastus2, westus, westeurope, eastasia, southeastasia, japaneast, japanwest, northcentralus, southcentralus, centralus, northeurope, brazilsouth, australiaeast, australiasoutheast, southindia, centralindia, westindia, canadaeast, canadacentral, westus2, westcentralus, uksouth, ukwest, koreacentral, koreasouth, francecentral'."
  }
}'

可通过以下过程从 Azure 门户找出部署错误:The deployment error can be found from the Azure portal using the following procedure:

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 打开资源组,方法是:选择“资源组”,然后选择资源组名称。Open the resource group by selecting Resource groups and then the resource group name. 此时会看到“部署”下显示“1 个失败”。You shall see 1 Failed under Deployment.

    资源管理器教程故障排除

  3. 选择“错误详细信息”。Select Error details.

    资源管理器教程故障排除

    错误消息与此前显示的相同:The error message is the same as the one shown earlier:

    资源管理器教程故障排除

也可在活动日志中查找错误:You can also find the error from the activity logs:

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 选择“Monitor” > “活动日志”。Select Monitor > Activity log.

  3. 使用筛选器查找日志。Use the filters to find the log.

    资源管理器教程故障排除

使用 Visual Studio Code 修正此问题,然后重新部署模板。Use Visual Studio Code to correct the problem, and then redeploy the template.

如需常见错误的列表,请参阅排查使用 Azure 资源管理器时的常见 Azure 部署错误For a list of common errors, see Troubleshoot common Azure deployment errors with Azure Resource Manager.

清理资源Clean up resources

不再需要 Azure 资源时,请通过删除资源组来清理部署的资源。When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.

  1. 在 Azure 门户上的左侧菜单中选择“资源组”。From the Azure portal, select Resource group from the left menu.
  2. 在“按名称筛选”字段中输入资源组名称。Enter the resource group name in the Filter by name field.
  3. 选择资源组名称。Select the resource group name. 应会看到,该资源组中总共有六个资源。You shall see a total of six resources in the resource group.
  4. 在顶部菜单中选择“删除资源组”。Select Delete resource group from the top menu.

后续步骤Next steps

本教程介绍了如何排查资源管理器模板部署错误。In this tutorial, you learned how to troubleshoot Resource Manager template deployment errors. 有关详细信息,请参阅排查使用 Azure 资源管理器时的常见 Azure 部署错误For more information, see Troubleshoot common Azure deployment errors with Azure Resource Manager.