如何在 Azure 中关闭应用服务的一个实例

How to shutdown one instance of an app service in azure

我已经将 Asp.Net MVC 应用程序部署到 Azure 中的应用程序服务并将其扩展到 2 个实例。

有时我需要重启一个实例,但我只是想办法重启整个网络应用程序。有没有办法只重启一个实例?即使删除实例然后创建一个新实例也对我有用。

如果您使用的是应用服务,那么不幸的是,这是不可能的。您只能更新编号。实例数。

但作为替代方案,您可以减少实例数,然后再增加回来。或者,如果您出于任何原因想要更精细的控制,则可以在 IaaS 虚拟机工作负载中部署 Web 应用程序并手动设置实例。

没有超级干净的方法来做到这一点,但仍然可以通过以下步骤实现:

  • 转到门户中的 Web 应用程序
  • 从工具菜单中选择 Process Explorer
  • 您将看到所有实例的进程。您可以右键单击特定的 w3wp 并杀死它们,这会有效地重新启动站点。如果您只想重新启动站点,则不必终止 Kudu 进程(带有 K 图标的进程)。对于 WebJobs,还要杀死 Kudu。

在发布此帖子时,Azure 门户中 "Diagnose and solve problems -> Best Practices" blade 下的应用服务中提到了一项 Health Check (Preview) 功能。

Health Check feature automatically removes a faulty instance from rotation, thus improving availability. This feature will ping the specified health check path on all instances of your webapp every 2 minutes. If an instance does not respond within 10 minutes (5 pings), the instance is determined to be unhealthy and our service will stop routing requests to it. It is highly recommended for production apps to utilize this feature and minimize any potential downtime caused due to a faulty instance. Note : Health Check feature only works for applications that are hosted on more than one instance. For more information check the documentation below.

您可以使用“高级应用程序重启”重启单个实例,您可以在 Azure 门户中的应用服务诊断工具下找到它。

您现在可以从 Azure 文档的 App Service Plans - Reboot Worker 页面重新启动应用服务计划的实例。您可以使用 'Try it' 功能直接从该页面重新启动实例。

  • 访问Reboot Worker页面
  • 使用来自包含应用服务计划的 Azure 租户的帐户登录
  • 点击'Try it'
  • 在右侧窗格中输入应用服务计划的名称和包含该计划的资源组
  • Select 包含应用服务计划的 Azure 订阅
  • 输入您要重启的工作机器(实例)的名称。此值通常以 RD 开头,可以使用 Azure 门户中 Web 应用程序的指标和诊断工具找到。
  • 单击请求预览下方的绿色 运行 按钮。