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

Azure 中的自动缩放入门Get started with Autoscale in Azure

本文介绍如何在 Microsoft Azure 门户中为资源指定自动缩放设置。This article describes how to set up your Autoscale settings for your resource in the Microsoft Azure portal.

Azure Monitor 自动缩放仅适用于虚拟机规模集云服务应用服务 - Web 应用API 管理服务Azure Monitor autoscale applies only to Virtual Machine Scale Sets, Cloud Services, App Service - Web Apps, and API Management services.

了解订阅中的自动缩放设置Discover the Autoscale settings in your subscription

可在 Azure Monitor 中查找自动缩放功能适用的所有资源。You can discover all the resources for which Autoscale is applicable in Azure Monitor. 按下列步骤进行分步演练:Use the following steps for a step-by-step walkthrough:

  1. 打开 Azure 门户Open the Azure portal.
  2. 单击左窗格中的“Azure Monitor”图标。Click the Azure Monitor icon in the left pane. 打开 Azure MonitorOpen Azure Monitor
  3. 单击“自动缩放”以查看自动缩放适用的所有资源及其当前的自动缩放状态。Click Autoscale to view all the resources for which Autoscale is applicable, along with their current Autoscale status. 了解 Azure Monitor 中的自动缩放功能Discover Autoscale in Azure Monitor

可使用顶部的筛选器窗格缩小列表的范围,以选择特定资源组中的资源、特定的资源类型或特定资源。You can use the filter pane at the top to scope down the list to select resources in a specific resource group, specific resource types, or a specific resource.

对于每个资源,将会看到其当前实例计数和自动缩放状态。For each resource, you will find the current instance count and the Autoscale status. 自动缩放状态可以是:The Autoscale status can be:

  • 未配置:尚未对此资源启用自动缩放功能。Not configured: You have not enabled Autoscale yet for this resource.
  • 已启用:已对此资源启用自动缩放功能。Enabled: You have enabled Autoscale for this resource.
  • 已禁用:已对此资源禁用自动缩放功能。Disabled: You have disabled Autoscale for this resource.

创建第一个自动缩放设置Create your first Autoscale setting

现在,让我们完成一个简单的分步演练,以创建第一个自动缩放设置。Let's now go through a simple step-by-step walkthrough to create your first Autoscale setting.

  1. 在 Azure Monitor 中打开“自动缩放”边栏选项卡,然后选择要缩放的资源。Open the Autoscale blade in Azure Monitor and select a resource that you want to scale. (以下步骤使用与某 Web 应用关联的应用服务计划。(The following steps use an App Service plan associated with a web app. 仅需 5 分钟,就可在 Azure 中创建首个 ASP.NET Web 应用。You can create your first ASP.NET web app in Azure in 5 minutes.)

  2. 请注意当前实例计数为 1。Note that the current instance count is 1. 单击“启用自动缩放”。Click Enable autoscale. 新 Web 应用的缩放设置Scale setting for new web app

  3. 提供缩放设置的名称,然后单击“添加规则”。Provide a name for the scale setting, and then click Add a rule. 请注意右侧以上下文窗格形式打开的缩放规则选项。Notice the scale rule options that open as a context pane on the right side. 默认情况下,这将选项设置为当资源的 CPU 百分比超过 70% 时,将实例计数缩放 1 个单位。By default, this sets the option to scale your instance count by 1 if the CPU percentage of the resource exceeds 70 percent. 请将此选项保留默认值,并单击“添加”。Leave it at its default values and click Add. 为 Web 应用创建缩放设置Create scale setting for a web app

  4. 现已创建第一个缩放规则。You've now created your first scale rule. 请注意,UX 建议了最佳做法,并指出“建议至少在规则中包含一个缩放设置”。Note that the UX recommends best practices and states that "It is recommended to have at least one scale in rule." 为此,请执行以下操作:To do so:

    a.a. 单击“添加规则”。Click Add a rule.

    b.b. 将“运算符”设置为“小于”。Set Operator to Less than.

    c.c. 将“阈值”设置为 20。Set Threshold to 20.

    d.d. 将“操作”设置为“按以下值递减计数”。Set Operation to Decrease count by.

    现在应已创建一个可以根据 CPU 使用率进行扩展/缩减的缩放设置。You should now have a scale setting that scales out/scales in based on CPU usage. 基于 CPU 进行缩放Scale based on CPU

  5. 单击“保存”。Click Save.

祝贺你!Congratulations! 现已成功创建第一个缩放设置,用于根据 CPU 使用率自动缩放 Web 应用。You've now successfully created your first scale setting to autoscale your web app based on CPU usage.

备注

若要开始使用虚拟机规模集或云服务角色,才可采用相同步骤操作。The same steps are applicable to get started with a virtual machine scale set or cloud service role.

其他注意事项Other considerations

基于计划的缩放Scale based on a schedule

除了基于 CPU 进行缩放,还可设置为在特定的星期日期按其他方式缩放。In addition to scale based on CPU, you can set your scale differently for specific days of the week.

  1. 单击“添加缩放条件”。Click Add a scale condition.
  2. 缩放模式和规则的设置方式与默认条件的相同。Setting the scale mode and the rules is the same as the default condition.
  3. 为计划选择“重复特定的星期日期”。Select Repeat specific days for the schedule.
  4. 选择星期日期,以及需应用缩放条件的开始/结束时间。Select the days and the start/end time for when the scale condition should be applied.

基于计划的缩放条件

在特定的日期以不同的方式缩放Scale differently on specific dates

除了基于 CPU 进行缩放,还可设置为在特定日期按其他方式缩放。In addition to scale based on CPU, you can set your scale differently for specific dates.

  1. 单击“添加缩放条件”。Click Add a scale condition.
  2. 缩放模式和规则的设置方式与默认条件的相同。Setting the scale mode and the rules is the same as the default condition.
  3. 为计划选择“指定开始/结束日期”。Select Specify start/end dates for the schedule.
  4. 选择开始/结束日期,以及需应用缩放条件的开始/结束时间。Select the start/end dates and the start/end time for when the scale condition should be applied.

基于日期的缩放条件

查看资源的缩放历史记录View the scale history of your resource

每次增加或缩小资源后,都会在活动日志中记录一个事件。Whenever your resource is scaled up or down, an event is logged in the activity log. 切换到“运行历史记录”选项卡即可查看资源在过去 24 小时的缩放历史记录。You can view the scale history of your resource for the past 24 hours by switching to the Run history tab.

运行历史记录

若要查看完整的缩放历史记录(最长 90 天),请选择“单击此处查看更多详细信息”。If you want to view the complete scale history (for up to 90 days), select Click here to see more details. 随后将启动活动日志,其中包含已预先选择“自动缩放”的资源和类别。The activity log opens, with Autoscale pre-selected for your resource and category.

查看资源的缩放定义View the scale definition of your resource

“自动缩放”是一种 Azure 资源管理器资源。Autoscale is an Azure Resource Manager resource. 切换到“JSON”选项卡即可在 JSON 中查看缩放定义。You can view the scale definition in JSON by switching to the JSON tab.

缩放定义

如果需要,可以直接在 JSON 中进行更改。You can make changes in JSON directly, if required. 这些更改将在保存后生效。These changes will be reflected after you save them.

禁用“自动缩放”并手动缩放实例Disable Autoscale and manually scale your instances

有时,可能需要禁用当前的缩放设置并手动缩放资源。There might be times when you want to disable your current scale setting and manually scale your resource.

单击顶部的“禁用自动缩放”按钮。Click the Disable autoscale button at the top. 禁用自动缩放Disable Autoscale

备注

此选项将禁用你的配置。This option disables your configuration. 但是,再次启用“自动缩放”后,则可恢复此设置。However, you can get back to it after you enable Autoscale again.

现在,可手动设置要缩放到的实例数。You can now set the number of instances that you want to scale to manually.

设置手动缩放

始终可单击“启用自动缩放”,再单击“保存”来恢复自动缩放。You can always return to Autoscale by clicking Enable autoscale and then Save.

后续步骤Next steps