如何按计划向上或向下扩展Azure应用程序服务实例大小?

如何按计划向上或向下扩展Azure应用程序服务实例大小?,azure,azure-web-app-service,autoscaling,azure-app-service-plans,Azure,Azure Web App Service,Autoscaling,Azure App Service Plans,关于Azure应用程序服务的自动扩展,我只找到以下内容 这只允许缩放到更多或更少的实例。它不允许扩展到更大和更小的实例 我想按计划安排应用程序服务实例大小介于小型、中型和大型之间。有允许我这样做的API吗 非常感谢。我认为您正在寻找的是按计划或CPU方式自动缩放Azure WebApp 1.将您的托管计划更改为标准,您无法在标准层下设置自动缩放 2.在Portal.Azure.com上使用Azure预览门户 3.Azure预览门户:正确的设置是使用“CPU百分比” 4.Azure Portal

关于Azure应用程序服务的自动扩展,我只找到以下内容

这只允许缩放到更多或更少的实例。它不允许扩展到更大和更小的实例

我想按计划安排应用程序服务实例大小介于小型、中型和大型之间。有允许我这样做的API吗


非常感谢。

我认为您正在寻找的是按计划或CPU方式自动缩放Azure WebApp

1.将您的托管计划更改为标准,您无法在标准层下设置自动缩放

2.在Portal.Azure.com上使用Azure预览门户

3.Azure预览门户:正确的设置是使用“CPU百分比”

4.Azure Portal您可以按指标设置从无到CPU的比例

5.将实例计数设置为介于1和4或8之间,您可以稍后更改,最多可以设置为10

有关更多详细信息,您可以参考本文,本文没有讨论的是按计划进行缩放,我认为您可以在到达后了解到这一点。
确保您使用portal.azure.com

不幸的是,目前无法按计划扩展azure应用程序服务实例大小(即应用程序服务计划定价层)

到目前为止,Azure应用程序服务只能支持基于时间表的水平缩放(即实例数量缩放),而不能支持垂直缩放(即实例大小缩放)


希望这有帮助

要做到这一点没有简单的方法

但是,如果您愿意编写一些代码,您可以使用PowerShell api和Azure Automation为自己创建此功能


您将使用API每X分钟检查一次指标(如CPU),如果CPU高于Y,则将其扩展到下一个更大的实例。如果低于您的阈值,请缩小规模。

使用powershell,您可以像这样切换web应用的应用程序服务计划

PS C:\> $Resource = Get-AzureRmResource -ResourceType "microsoft.web/sites" -ResourceGroupName "ResourceGroup11" -ResourceName "ContosoSite" 
PS C:\> $Resource.Properties.ServerFarmId = "/subscriptions/{subscr_id}/resourceGroups/FriendsRGrp/provider
s/Microsoft.Web/serverfarms/FriendsPlan"
PS C:\> $Resource | Set-AzureRmResource -Force
在这里,服务器场id只是服务计划的资源id,您可以通过查看计划的属性从新门户获取该资源id

您可以有两个服务计划,一个是基本服务计划,另一个是标准服务计划。然后,您可以使用Azure Automation在工作日升级到standard,并在周末降级到basic

我知道你的要求是改变现有的计划本身,而不是在计划之间切换。我认为这应该是可能的,尽管我自己还没有试过。但是,如果您查看资源中返回的属性。返回的Azure web app资源的属性如上所述,您应该能够找到它。

实际上,您可以自动放大(垂直,即更改服务计划)和缩小(实例计数)

扩展选项一直存在,允许您设置规则(例如CPU超过%,内存超过阈值,等等)

放大选项要求使用Azure自动化。它有完整的文档记录


希望有帮助

由于缺乏简单的解决方案,我创建了一个一键式部署来执行您的要求

概述 我的方法使用Azure自动化运行手册。通过单击部署方法,您可以在几分钟内完全启动并运行。两个互补的运行手册(ScaleAppServicePlansUp和ScaleAppServicePlansDown)共同存储、读取和修改您选择的应用程序服务计划。这些运行手册的主要目标是非prod环境

不幸的是,代码太长,无法包含在此答案中(因此,是的,这将主要是一个仅链接的答案)

伪码 缩小 放大 额外资源
  • :
免责声明 我在完成工作后意识到了这一点。与his相比,我的方法的好处如下:

  • 一键部署到Azure
  • 基于参数的通用或特定
  • 使用更新的
  • 依靠存储通过自动化变量保持以前的状态

  • 没有。这只允许实例数量,不允许实例大小。谢谢。你知道这些API允许实例大小的上下伸缩吗?@JacquesBosch:是的,它们肯定支持实例大小的上下伸缩。如果我没记错的话,size属性在应用程序服务计划中,而不是在网站上,所以这就是您想要查看的地方。是的,我知道实例大小在计划级别。再次感谢。我来看看。
    Iterate across all Resource Groups (or pass in specific one)
    Iterate across all App Service Plans (or pass in specific one)
    Iterate across all App Services (identify Tier-specific settings)
    
    During iteration, the current App Service Plan Service Tier is stored in Azure Automation Variables (3 distinct variables for each App Service Plan)
    
    Within each App Service Plan, each App Service is iterated to identify tier-specific settings. Some of these settings include: AlwaysOn, Use32BitWorkerProcess, and ClientCertEnabled. All current settings are stored in Azure Automation Variables.
    
    All App Service Plans are then scaled down to the FREE tier.
    
    Iterate across all Resource Groups (or pass in specific one)
    Iterate across all App Service Plans (or pass in specific one)
    Iterate across all App Services (identify Tier-specific settings)
    
    During iteration, the original App Service Plan Service Tier is retrieved from Azure Automation Variables (3 distinct variables for each App Service Plan)
    
    Within each App Service Plan, each App Service is iterated and any previously stored tier-specific settings are retrieved.
    
    All App Service Plans are then scaled up to their original tier.
    All App Services with tier-specific settings are reapplied to their original values.