你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用混沌试验模板来关闭禁用自动缩放的虚拟机规模集可用性区域

可以使用混沌试验,通过在受控环境中引发一些故障,来验证应用程序是否可以应对这些故障。 在本文中,你将使用预填充的试验模板和 Azure Chaos Studio 来关闭虚拟机规模集实例的可用性区域(禁用自动缩放)。

先决条件

  • Azure 订阅。 如果没有 Azure 订阅,请在开始之前创建一个 Azure 免费帐户
  • 虚拟机规模集实例。
  • 自动缩放设置实例。

在虚拟机规模集和自动缩放设置实例上启用 Chaos Studio

在将该资源添加到 Chaos Studio 之前,Azure Chaos Studio 无法针对资源注入错误。 若要将资源添加到 Chaos Studio,请在资源上创建 目标和功能 。 虚拟机规模集只有一个目标类型(Microsoft-VirtualMachineScaleSet)和一个功能(shutdown)。 自动缩放设置只有一个目标类型(Microsoft-AutoScaleSettings)和一个功能(disableAutoscale)。 其他资源最多可以有两种目标类型。 一种目标类型用于服务直接故障。 另一个目标类型用于基于代理的故障。 其他资源可能具有许多其他功能。

  1. 打开 Azure 门户

  2. 在搜索栏中搜索 Chaos Studio

  3. 选择“目标并查找自动缩放设置资源。

  4. 选择自动缩放设置资源,然后选择“启用目标>启用服务直接目标”。

    Screenshot that shows the Targets screen in Chaos Studio, with the autoscale setting resource selected.

  5. 选择“审阅 + 启用”。>

  6. 查找虚拟机规模集资源。

  7. 选择虚拟机规模集资源,然后选择“启用目标>启用服务直接目标”。

    Screenshot that shows the Targets screen in Chaos Studio, with the virtual machine scale set resource selected.

  8. 选择“审阅 + 启用”。>

现已成功将自动缩放设置和虚拟机规模集添加到 Chaos Studio。

从模板创建试验

现在,可以从预先填充的试验模板创建试验。 混沌试验定义要针对目标资源执行的操作。 操作按顺序组织并运行。 混沌试验还定义了要针对并行运行的分支执行的操作。

  1. 在 Chaos Studio 中,转到“从模板创建新>试验”。>

    Screenshot that shows the Experiments screen, with the New from template button highlighted.

  2. 选择 “可用性区域关闭”。

    Screenshot that shows the experiment templates screen, with the Availability Zone down template button highlighted.

  3. 为符合资源命名准则的试验添加名称。 在完成时选择“下一步: 权限”。

    Screenshot that shows the experiment basics screen, with the permissions tab button highlighted.

  4. 要使混沌试验成功运行,它必须对目标资源具有足够的权限。 为试验选择系统分配的托管标识或用户分配的托管标识。 如果希望 Chaos Studio 将运行所需的权限(以自定义角色的形式)添加到试验的标识中,可以选择启用自定义角色分配。 选择“下一步: 试验设计器”。

    Screenshot that shows the experiment permissions screen, with the experiment designer tab button highlighted.

  5. “禁用自动缩放 ”错误中,选择“ 编辑”。

    Screenshot that shows the experiment designer screen, with the edit button within the disable autoscale fault highlighted.

  6. 查看错误参数并选择“ 下一步:目标资源”。

    Screenshot that shows the fault parameters pane for autoscale, with the target resources button highlighted.

  7. 选择要在试验中使用的自动缩放设置资源。 选择“保存”。

    Screenshot that shows the fault targets pane for autoscale, with the save button highlighted.

  8. VMSS 关闭(版本 2.0) 错误中,选择“ 编辑”。

    Screenshot that shows the experiment designer screen, with the edit button within the Virtual Machine Scale Set shutdown fault highlighted.

  9. 查看错误参数并选择“ 下一步:目标资源”。

    Screenshot that shows the fault parameters pane for the virtual machine scale set, with the target resources button highlighted.

  10. 选择要在试验中使用的虚拟机规模集资源。 选择“ 下一步:作用域”。

    Screenshot that shows the fault targets pane for Virtual Machine Scale Set, with the save button highlighted.

  11. 选择要关闭的虚拟机规模集中的区域。 选择“保存”。

    Screenshot that shows the scope pane, with the save button highlighted.

  12. 选择“查看 + 创建>”以保存试验。

运行试验

现在可以运行试验了。

  1. “试验 ”视图中,选择试验。 选择“开始>确定”。
  2. 当状态更改为“正在运行”时,选择“历史记录最新运行的详细信息以查看正在运行的试验的详细信息。

后续步骤

运行可用性区域关闭模板试验后,即可: