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

导致 Azure 云服务 (经典) 角色回收的常见问题Common issues that cause Azure Cloud Service (classic) roles to recycle


Azure 云服务 (扩展支持) 是适用于 Azure 云服务产品的新的基于 azure 资源管理器的部署模型。Azure Cloud Services (extended support) is a new Azure Resource Manager based deployment model for the Azure Cloud Services product.进行此更改后,基于 Azure Service Manager 的部署模型运行的 Azure 云服务已重命名为云服务 (经典) ,所有新部署应使用 云服务 (扩展支持)  With this change, Azure Cloud Services running on the Azure Service Manager based deployment model have been renamed as Cloud Services (classic) and all new deployments should use Cloud Services (extended support).

本文讨论部署问题的一些常见原因,并提供故障排除技巧以帮助你解决这些问题。This article discusses some of the common causes of deployment problems and provides troubleshooting tips to help you resolve these problems. 角色实例无法启动,或者在“正在初始化”、“忙”和“正在停止”状态之间循环时,即指示应用程序存在问题。An indication that a problem exists with an application is when the role instance fails to start, or it cycles between the initializing, busy, and stopping states.

如果本文未解决 Azure 问题,请访问 MSDN 和 Stack Overflow 上的 Azure 论坛。If your Azure issue is not addressed in this article, visit the Azure forums on MSDN and Stack Overflow. 可将问题发布到这些论坛上,或发布到 Twitter 上的 @AzureSupportYou can post your issue in these forums, or post to @AzureSupport on Twitter. 还可提交 Azure 支持请求。You also can submit an Azure support request. 若要提交支持请求,请在 Azure 支持页上,选择“获取支持”。To submit a support request, on the Azure support page, select Get support.

缺少运行时依赖项Missing runtime dependencies

如果应用程序中的某个角色依赖于某个程序集,而该程序集不属 .NET Framework 或 Azure 托管库的一部分,则必须在应用程序包中显式包括该程序集。If a role in your application relies on any assembly that is not part of the .NET Framework or the Azure managed library, you must explicitly include that assembly in the application package. 请记住,默认情况下,其他 Microsoft 框架在 Azure 上不可用。Keep in mind that other Microsoft frameworks are not available on Azure by default. 如果角色依赖于此类框架,则必须将这些程序集添加到应用程序包。If your role relies on such a framework, you must add those assemblies to the application package.

生成和打包应用程序之前,请验证以下各项:Before you build and package your application, verify the following:

  • 如果使用 Visual Studio,请确保针对项目中每个不属于 Azure SDK 或 .NET Framework 的引用程序集,将其“复制本地”属性设置为“True” 。If using Visual studio, make sure the Copy Local property is set to True for each referenced assembly in your project that is not part of the Azure SDK or the .NET Framework.
  • 请确保 web.config 文件在 compilation 元素中未引用任何未使用的程序集。Make sure the web.config file does not reference any unused assemblies in the compilation element.
  • 每个 .cshtml 文件的“生成操作”将设置为“内容” 。The Build Action of every .cshtml file is set to Content. 这可确保这些文件会正确显示在包中,并允许其他引用的文件显示在包中。This ensures that the files will appear correctly in the package and enables other referenced files to appear in the package.

程序集针对的平台错误Assembly targets wrong platform

Azure 是一个 64 位的环境。Azure is a 64-bit environment. 因此,针对 32 位目标编译的 .NET 程序集不会在 Azure 上运行。Therefore, .NET assemblies compiled for a 32-bit target won't work on Azure.

角色在初始化或停止时引发未处理异常Role throws unhandled exceptions while initializing or stopping

任何通过 RoleEntryPoint 类的方法(包括 OnStartOnStopRun 方法)引发的异常均属未处理异常。Any exceptions that are thrown by the methods of the RoleEntryPoint class, which includes the OnStart, OnStop, and Run methods, are unhandled exceptions. 如果这些方法中的某个方法出现未处理异常,则会对角色进行回收。If an unhandled exception occurs in one of these methods, the role will recycle. 如果角色处于反复回收的状态,则每次该角色尝试启动时,都可能会引发未处理异常。If the role is recycling repeatedly, it may be throwing an unhandled exception each time it tries to start.

角色从 Run 方法返回Role returns from Run method

Run 方法会不限次数地运行。The Run method is intended to run indefinitely. 如果代码重写了 Run 方法,该方法会无限地休眠下去。If your code overrides the Run method, it should sleep indefinitely. 如果 Run 方法返回,则角色会回收。If the Run method returns, the role recycles.

不正确的 DiagnosticsConnectionString 设置Incorrect DiagnosticsConnectionString setting

如果应用程序使用 Azure 诊断,则服务配置文件必须指定 DiagnosticsConnectionString 配置设置。If application uses Azure Diagnostics, your service configuration file must specify the DiagnosticsConnectionString configuration setting. 此设置应在 Azure 中指定一个连接到存储帐户的 HTTPS 连接。This setting should specify an HTTPS connection to your storage account in Azure.

将应用程序包部署到 Azure 之前,要确保 DiagnosticsConnectionString 设置正确,请验证以下内容:To ensure that your DiagnosticsConnectionString setting is correct before you deploy your application package to Azure, verify the following:

  • DiagnosticsConnectionString 设置指向 Azure 中的有效存储帐户。The DiagnosticsConnectionString setting points to a valid storage account in Azure.
    默认情况下,此设置指向模拟的存储帐户中,因此必须在部署应用程序包之前显式更改此设置。By default, this setting points to the emulated storage account, so you must explicitly change this setting before you deploy your application package. 如果不更改此设置,则角色实例尝试启动诊断监视器时,会引发异常。If you do not change this setting, an exception is thrown when the role instance attempts to start the diagnostic monitor. 这可能导致角色实例无限期回收。This may cause the role instance to recycle indefinitely.
  • 连接字符串是使用以下格式指定的。The connection string is specified in the following format. (协议必须指定为 HTTPS。)将 MyAccountName 替换为存储帐户名称,将 MyAccountKey 替换为访问密钥 :(The protocol must be specified as HTTPS.) Replace MyAccountName with the name of your storage account, and MyAccountKey with your access key:

如果要使用 Microsoft Azure Visual Studio 的 Azure 工具来开发应用程序,则可使用属性页设置此值。If you are developing your application by using Azure Tools for Microsoft Visual Studio, you can use the property pages to set this value.

导出的证书不含私钥Exported certificate does not include private key

若要在 TLS 下运行 Web 角色,必须确保导出的管理证书包含私钥。To run a web role under TLS, you must ensure that your exported management certificate includes the private key. 如果使用 Windows 证书管理器导出证书,请务必对“导出私钥”选项选择“是” 。If you use the Windows Certificate Manager to export the certificate, be sure to select Yes for the Export the private key option. 该证书必须以 PFX 格式导出,这是当前支持的唯一格式。The certificate must be exported in the PFX format, which is the only format currently supported.

后续步骤Next steps

查看更多针对云服务的 故障排除文章View more troubleshooting articles for cloud services.

Kevin Williamson 博客系列中查看更多角色回收方案。View more role recycling scenarios at Kevin Williamson's blog series.