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

使用 Azure 资源管理器查看部署操作View deployment operations with Azure Resource Manager

可以通过 Azure 门户查看部署操作。You can view the operations for a deployment through the Azure portal. 在部署过程中收到错误时,可能最想要查看操作,因此本文将重点介绍如何查看已失败的操作。You may be most interested in viewing the operations when you have received an error during deployment so this article focuses on viewing operations that have failed. 该门户提供一个界面,可用于轻松查找错误并确定潜在修复。The portal provides an interface that enables you to easily find the errors and determine potential fixes.

可以通过查看审核日志或部署操作来对部署进行故障排除。You can troubleshoot your deployment by looking at either the audit logs, or the deployment operations. 本文介绍了这两种方法。This article shows both methods. 有关解决特定部署错误的帮助,请参阅解决使用 Azure 资源管理器将资源部署到 Azure 时的常见错误For help with resolving particular deployment errors, see Resolve common errors when deploying resources to Azure with Azure Resource Manager.

门户Portal

若要查看部署操作,请使用以下步骤 :To see the deployment operations, use the following steps:

  1. 对于部署中涉及的资源组,请注意最后一个部署的状态。For the resource group involved in the deployment, notice the status of the last deployment. 可以选择此状态以获取更多详细信息。You can select this status to get more details.

    部署状态

  2. 看到最近的部署历史记录。You see the recent deployment history. 选择失败的部署。Select the deployment that failed.

    部署状态

  3. 选择链接,查看部署失败的原因说明。Select the link to see a description of why the deployment failed. 在下图中,DNS 记录不是唯一的。In the image below, the DNS record is not unique.

    查看失败的部署

    此错误消息应足够让可以开始进行故障排除。This error message should be enough for you to begin troubleshooting. 但是,如果需要有关完成了哪些任务的更多详细信息,可以查看操作,如下面的步骤所示。However, if you need more details about which tasks were completed, you can view the operations as shown in the following steps.

  4. 可以查看所有部署操作。You can view all the deployment operations. 选择任何操作,以查看更多详细信息。Select any operation to see more details.

    查看操作

    在此示例中,会看到已成功创建存储帐户、虚拟网络和可用性集。In this case, you see that the storage account, virtual network, and availability set were successfully created. 公共 IP 地址失败,未尝试其他资源。The public IP address failed, and other resources were not attempted.

  5. 可以通过选择“事件”查看部署的事件。You can view events for the deployment by selecting Events.

    查看事件

  6. 查看部署的所有事件,并选择任何事件以了解更多详细信息。You see all the events for the deployment and select any one for more details. 请注意相关 ID。Notice the correlation IDs. 与技术支持人员合作排查部署问题时,此值非常有用。This value can be helpful when working with technical support to troubleshoot a deployment.

    查看事件

PowerShellPowerShell

  1. 若要获取部署的总体状态,请使用 Get-AzureRmResourceGroupDeployment 命令。To get the overall status of a deployment, use the Get-AzureRmResourceGroupDeployment command.

    Get-AzureRmResourceGroupDeployment -ResourceGroupName ExampleGroup
    

    也可以筛选结果,以便只获取失败的部署。Or, you can filter the results for only those deployments that have failed.

    Get-AzureRmResourceGroupDeployment -ResourceGroupName ExampleGroup | Where-Object ProvisioningState -eq Failed
    
  2. 每个部署包括多个操作。Each deployment includes multiple operations. 每个操作代表部署过程中的一个步骤。Each operation represents a step in the deployment process. 为了查明部署何处出现问题,通常需要查看部署操作的详细信息。To discover what went wrong with a deployment, you usually need to see details about the deployment operations. 可以使用 Get-AzureRmResourceGroupDeploymentOperation 查看操作状态。You can see the status of the operations with Get-AzureRmResourceGroupDeploymentOperation.

    Get-AzureRmResourceGroupDeploymentOperation -ResourceGroupName ExampleGroup -DeploymentName vmDeployment
    

    它将返回多个操作,其中每个操作采用以下格式:Which returns multiple operations with each one in the following format:

    Id             : /subscriptions/{guid}/resourceGroups/ExampleGroup/providers/Microsoft.Resources/deployments/Microsoft.Template/operations/A3EB2DA598E0A780
    OperationId    : A3EB2DA598E0A780
    Properties     : @{provisioningOperation=Create; provisioningState=Succeeded; timestamp=2016-06-14T21:55:15.0156208Z;
                    duration=PT23.0227078S; trackingId=11d376e8-5d6d-4da8-847e-6f23c6443fbf;
                    serviceRequestId=0196828d-8559-4bf6-b6b8-8b9057cb0e23; statusCode=OK; targetResource=}
    PropertiesText : {duration:PT23.0227078S, provisioningOperation:Create, provisioningState:Succeeded,
                    serviceRequestId:0196828d-8559-4bf6-b6b8-8b9057cb0e23...}
    
  3. 若要获取有关失败操作的更多详细信息,请检索状态为“失败”的操作的属性。To get more details about failed operations, retrieve the properties for operations with Failed state.

    (Get-AzureRmResourceGroupDeploymentOperation -DeploymentName Microsoft.Template -ResourceGroupName ExampleGroup).Properties | Where-Object ProvisioningState -eq Failed
    

    它将返回所有失败的操作,其中每个操作采用以下格式:Which returns all the failed operations with each one in the following format:

    provisioningOperation : Create
    provisioningState     : Failed
    timestamp             : 2016-06-14T21:54:55.1468068Z
    duration              : PT3.1449887S
    trackingId            : f4ed72f8-4203-43dc-958a-15d041e8c233
    serviceRequestId      : a426f689-5d5a-448d-a2f0-9784d14c900a
    statusCode            : BadRequest
    statusMessage         : @{error=}
    targetResource        : @{id=/subscriptions/{guid}/resourceGroups/ExampleGroup/providers/
                           Microsoft.Network/publicIPAddresses/myPublicIP;
                           resourceType=Microsoft.Network/publicIPAddresses; resourceName=myPublicIP}
    

    注意操作的 serviceRequestId 和 trackingId。Note the serviceRequestId and the trackingId for the operation. 与技术支持人员合作排查部署问题时,serviceRequestId 非常有用。The serviceRequestId can be helpful when working with technical support to troubleshoot a deployment. 将在下一步使用 trackingId 重点关注特定操作。You will use the trackingId in the next step to focus on a particular operation.

  4. 若要获取特定失败操作的状态消息,请使用以下命令:To get the status message of a particular failed operation, use the following command:

    ((Get-AzureRmResourceGroupDeploymentOperation -DeploymentName Microsoft.Template -ResourceGroupName ExampleGroup).Properties | Where-Object trackingId -eq f4ed72f8-4203-43dc-958a-15d041e8c233).StatusMessage.error
    

    将返回:Which returns:

    code           message                                                                        details
    ----           -------                                                                        -------
    DnsRecordInUse DNS record dns.westus.cloudapp.azure.com is already used by another public IP. {}
    
  5. Azure 中的每个部署操作均包括请求和响应内容。Every deployment operation in Azure includes request and response content. 请求内容是在部署过程中发送到 Azure 的内容(例如,创建 VM、OS 磁盘和其他资源)。The request content is what you sent to Azure during deployment (for example, create a VM, OS disk, and other resources). 响应内容是 Azure 从部署请求发送回的内容。The response content is what Azure sent back from your deployment request. 在部署期间,可以使用 DeploymentDebugLogLevel 参数指定将请求和/或响应保留在日志中。During deployment, you can use DeploymentDebugLogLevel parameter to specify that the request and/or response are retained in the log.

    可以使用以下 PowerShell 命令从日志中获取该信息,然后将其保存在本地:You get that information from the log, and save it locally by using the following PowerShell commands:

    (Get-AzureRmResourceGroupDeploymentOperation -DeploymentName "TestDeployment" -ResourceGroupName "Test-RG").Properties.request | ConvertTo-Json |  Out-File -FilePath <PathToFile>
    
    (Get-AzureRmResourceGroupDeploymentOperation -DeploymentName "TestDeployment" -ResourceGroupName "Test-RG").Properties.response | ConvertTo-Json |  Out-File -FilePath <PathToFile>
    

Azure CLIAzure CLI

  1. 使用 azure group deployment show 命令获取部署的总体状态。Get the overall status of a deployment with the azure group deployment show command.

    az group deployment show -g ExampleGroup -n ExampleDeployment
    
  2. 返回的值之一是 correlationIdOne of the returned values is the correlationId. 此值可用于跟踪相关事件,在与技术支持人员合作排查部署问题时非常有用。This value is used to track related events, and can be helpful when working with technical support to troubleshoot a deployment.

    az group deployment show -g ExampleGroup -n ExampleDeployment --query properties.correlationId
    
  3. 若要查看部署操作,请使用:To see the operations for a deployment, use:

    az group deployment operation list -g ExampleGroup -n ExampleDeployment
    

RESTREST

  1. 使用获取有关模板部署的信息操作获取有关部署的信息。Get information about a deployment with the Get information about a template deployment operation.

    GET https://management.azure.com/subscriptions/{subscription-id}/resourcegroups/{resource-group-name}/providers/microsoft.resources/deployments/{deployment-name}?api-version={api-version}
    

    在响应中,请特别注意 provisioningStatecorrelationIderror 元素。In the response, note in particular the provisioningState, correlationId, and error elements. correlationId 可用于跟踪相关事件,在与技术支持人员合作排查部署问题时非常有用。The correlationId is used to track related events, and can be helpful when working with technical support to troubleshoot a deployment.

    { 
     ...
     "properties": {
       "provisioningState":"Failed",
       "correlationId":"d5062e45-6e9f-4fd3-a0a0-6b2c56b15757",
       ...
       "error":{
         "code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see http://aka.ms/arm-debug for usage details.",
         "details":[{"code":"Conflict","message":"{\r\n  \"error\": {\r\n    \"message\": \"Conflict\",\r\n    \"code\": \"Conflict\"\r\n  }\r\n}"}]
       }  
     }
    }
    
  2. 使用列出所有模板部署操作获取有关部署的信息。Get information about deployments with List all template deployment operations.

    GET https://management.azure.com/subscriptions/{subscription-id}/resourcegroups/{resource-group-name}/providers/microsoft.resources/deployments/{deployment-name}/operations?$skiptoken={skiptoken}&api-version={api-version}
    

    响应包含请求和/或响应信息,具体取决于部署期间在 debugSetting 属性中指定的内容。The response includes request and/or response information based on what you specified in the debugSetting property during deployment.

    {
     ...
     "properties": 
     {
       ...
       "request":{
         "content":{
           "location":"West US",
           "properties":{
             "accountType": "Standard_LRS"
           }
         }
       },
       "response":{
         "content":{
           "error":{
             "message":"Conflict","code":"Conflict"
           }
         }
       }
     }
    }
    

后续步骤Next steps