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

如何使用可用性集How to use availability sets

本教程介绍如何使用称作“可用性集”的功能提高 Azure 上虚拟机解决方案的可用性和可靠性。In this tutorial, you learn how to increase the availability and reliability of your Virtual Machine solutions on Azure using a capability called Availability Sets. 可用性集可确保在 Azure 上部署的 VM 能够跨多个隔离的硬件群集分布。Availability sets ensure that the VMs you deploy on Azure are distributed across multiple isolated hardware clusters. 这样,就可以确保当 Azure 中发生硬件或软件故障时,只有一部分 VM 受到影响,整体解决方案仍可使用和操作。Doing this ensures that if a hardware or software failure within Azure happens, only a subset of your VMs is impacted and that your overall solution remains available and operational.

本教程介绍如何执行下列操作:In this tutorial, you learn how to:

  • 创建可用性集Create an availability set
  • 在可用性集中创建 VMCreate a VM in an availability set
  • 检查可用的 VM 大小Check available VM sizes

启动 Azure Cloud ShellLaunch Azure Cloud Shell

Azure Cloud Shell 是免费的交互式 shell,可以使用它运行本文中的步骤。The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. 它预安装有常用 Azure 工具并将其配置与帐户一起使用。It has common Azure tools preinstalled and configured to use with your account. 请直接单击“复制”按钮对代码进行复制,将其粘贴到 Cloud Shell 中,然后按 Enter 来运行它。Just click the Copy button to copy the code, paste it into the Cloud Shell, and then press enter to run it. 可通过多种方式来启动 Cloud Shell:There are a few ways to launch the Cloud Shell:

单击代码块右上角的“试用”。Click Try It in the upper right corner of a code block. 本文中的 Cloud Shell
在浏览器中打开 Cloud Shell。Open Cloud Shell in your browser. https://shell.azure.com/bashhttps://shell.azure.com/bash
单击 Azure 门户右上角菜单上的“Cloud Shell”按钮。Click the Cloud Shell button on the menu in the upper right of the Azure portal. 门户中的 Cloud Shell

如果选择在本地安装并使用 CLI,本教程要求运行 Azure CLI 2.0.4 或更高版本。If you choose to install and use the CLI locally, this tutorial requires that you are running the Azure CLI version 2.0.4 or later. 运行 az --version 即可查找版本。Run az --version to find the version. 如果需要进行安装或升级,请参阅安装 Azure CLI 2.0If you need to install or upgrade, see Install Azure CLI 2.0.

可用性集概述Availability set overview

可用性集是一种逻辑分组功能,在 Azure 中使用它可以确保将 VM 资源部署在 Azure 数据中心后,这些资源相互隔离。An Availability Set is a logical grouping capability that you can use in Azure to ensure that the VM resources you place within it are isolated from each other when they are deployed within an Azure datacenter. Azure 确保可用性集中部署的 VM 能够跨多个物理服务器、计算机架、存储单元和网络交换机运行。Azure ensures that the VMs you place within an Availability Set run across multiple physical servers, compute racks, storage units, and network switches. 如果出现硬件或 Azure 软件故障,只有一部分 VM 会受到影响,整体应用程序仍会保持运行,可供客户使用。If a hardware or Azure software failure occurs, only a subset of your VMs are impacted, and your overall application stays up and continues to be available to your customers. 如果想要构建可靠的云解决方案,可用性集是一项关键功能。Availability Sets are an essential capability when you want to build reliable cloud solutions.

假设某个基于 VM 的典型解决方案包含四个前端 Web 服务器,以及两个托管数据库的后端 VM。Let’s consider a typical VM-based solution where you might have four front-end web servers and use two back-end VMs that host a database. 在 Azure 中,若想在部署 VM 之前先定义两个可用性集:一个可用性集用于“Web”层级,另一个可用性集用于“数据库”层级。With Azure, you’d want to define two availability sets before you deploy your VMs: one availability set for the “web” tier and one availability set for the “database” tier. 创建新的 VM 时,可在 az vm create 命令中指定可用性集作为参数,Azure 会自动确保在可用性集中创建的 VM 在多个物理硬件资源之间保持独立。When you create a new VM you can then specify the availability set as a parameter to the az vm create command, and Azure automatically ensures that the VMs you create within the available set are isolated across multiple physical hardware resources. 如果运行某个 Web 服务器或数据库服务器 VM 的物理硬件有问题,可以确信 Web 服务器和数据库 VM 的其他实例会保持运行,因为它们位于不同的硬件上。If the physical hardware that one of your Web Server or Database Server VMs is running on has a problem, you know that the other instances of your Web Server and Database VMs remain running because they are on different hardware.

在 Azure 中部署基于 VM 的可靠解决方案时,使用可用性集。Use Availability Sets when you want to deploy reliable VM-based solutions within Azure.

创建可用性集Create an availability set

可使用 az vm availability-set create 创建可用性集。You can create an availability set using az vm availability-set create. 在本示例中,将 myResourceGroupAvailability 资源组中名为 myAvailabilitySet 的可用性集的更新域数和容错域数均设置为 2。In this example, we set both the number of update and fault domains at 2 for the availability set named myAvailabilitySet in the myResourceGroupAvailability resource group.

创建资源组。Create a resource group.

az group create --name myResourceGroupAvailability --location eastus
az vm availability-set create \
    --resource-group myResourceGroupAvailability \
    --name myAvailabilitySet \
    --platform-fault-domain-count 2 \
    --platform-update-domain-count 2

使用可用性集可跨容错域和更新域隔离资源。Availability Sets allow you to isolate resources across fault domains and update domains. 容错域代表服务器、网络和存储资源的隔离集合。A fault domain represents an isolated collection of server + network + storage resources. 前面的示例指出我们想要在部署 VM 时,将可用性集至少分布在两个容错域之间。In the preceding example, we indicate that we want our availability set to be distributed across at least two fault domains when our VMs are deployed. 此外,还指出要将可用性集分布在两个更新域之间。We also indicate that we want our availability set distributed across two update domains. 两个更新域确保当 Azure 执行软件更新时,VM 资源可以隔离,防止 VM 下面运行的所有软件同时更新。Two update domains ensure that when Azure performs software updates our VM resources are isolated, preventing all the software running underneath our VM from being updated at the same time.

在可用性集内创建 VMCreate VMs inside an availability set

必须在可用性集中创建 VM,确保它们正确地分布在硬件中。VMs must be created within the availability set to make sure they are correctly distributed across the hardware. 创建后,无法将现有 VM 添加到可用性集中。You can't add an existing VM to an availability set after it is created.

使用 az vm create 创建 VM 时,利用 --availability-set 参数指定可用性集,以指定该可用性集的名称。When you create a VM using az vm create you specify the availability set using the --availability-set parameter to specify the name of the availability set.

for i in `seq 1 2`; do
   az vm create \
     --resource-group myResourceGroupAvailability \
     --name myVM$i \
     --availability-set myAvailabilitySet \
     --size Standard_DS1_v2  \
     --image Canonical:UbuntuServer:14.04.4-LTS:latest \
     --admin-username azureuser \
     --generate-ssh-keys \

现在,我们已在新建的可用性集中创建了两个虚拟机。We now have two virtual machines within our newly created availability set. 由于它们在同一可用性集中,Azure 会确保 VM 及其所有资源(包括数据磁盘)分布在隔离的物理硬件上。Because they are in the same availability set, Azure ensures that the VMs and all their resources (including data disks) are distributed across isolated physical hardware. 这种分布方式有助于确保提高整体 VM 解决方案的可用性。This distribution helps ensure much higher availability of our overall VM solution.

如果通过转到“资源组”>“我的资源组可用性”>“我的可用性集”在门户中查看可用性集,则应查看如何跨两个容错域和更新域分布 VM。If you look at the availability set in the portal by going to Resource Groups > myResourceGroupAvailability > myAvailabilitySet, you should see how the VMs are distributed across the two fault and update domains.


检查可用的 VM 大小Check for available VM sizes

稍后可向可用性集添加更多 VM,但需了解在硬件上可用的 VM 大小。You can add more VMs to the availability set later, but you need to know what VM sizes are available on the hardware. 使用 az vm availability-set list-sizes 列出可用性集的硬件群集上所有可用的大小。Use az vm availability-set list-sizes to list all the available sizes on the hardware cluster for the availability set.

az vm availability-set list-sizes \
     --resource-group myResourceGroupAvailability \
     --name myAvailabilitySet \
     --output table  

后续步骤Next steps

本教程介绍了如何:In this tutorial, you learned how to:

  • 创建可用性集Create an availability set
  • 在可用性集中创建 VMCreate a VM in an availability set
  • 检查可用的 VM 大小Check available VM sizes

请转到下一教程,了解虚拟机规模集。Advance to the next tutorial to learn about virtual machine scale sets.