使用 Azure 门户对多个 IP 配置进行负载均衡Load balancing on multiple IP configurations by using the Azure portal

本文介绍如何对辅助网络接口控制器 (NIC) 上的多个 IP 地址使用 Azure 负载均衡器。In this article, we're going to show you how to use Azure Load Balancer with multiple IP addresses on a secondary network interface controller (NIC). 下图演示了本文所述的方案:The following diagram illustrates our scenario:

负载均衡器方案

此方案使用以下配置:In our scenario, we're using the following configuration:

  • 两个运行 Windows 的虚拟机 (VM)。Two virtual machines (VMs) that are running Windows.
  • 每个 VM 包含一个主要 NIC 和一个辅助 NIC。Each VM has a primary and a secondary NIC.
  • 每个辅助 NIC 有两个 IP 配置。Each secondary NIC has two IP configurations.
  • 每个 VM 托管两个网站:contoso.com 和 fabrikam.com。Each VM hosts two websites: contoso.com and fabrikam.com.
  • 每个网站已绑定到辅助 NIC 上的某个 IP 配置。Each website is bound to an IP configuration on the secondary NIC.
  • Azure 负载均衡器用于公开两个前端 IP 地址,每个地址对应于一个网站。Azure Load Balancer is used to expose two front-end IP addresses, one for each website. 前端地址用于将流量分配到每个网站的相应 IP 配置。The front-end addresses are used to distribute traffic to the respective IP configuration for each website.
  • 前端 IP 地址和后端池 IP 地址使用相同的端口号。The same port number is used for both front-end IP addresses and back-end pool IP addresses.

先决条件Prerequisites

方案示例假设已创建名为 contosofabrikam 的资源组,该资源组的配置如下:Our scenario example assumes that you have a resource group named contosofabrikam that is configured as follows:

  • 该资源组包含名为的 myVNet 虚拟网络。The resource group includes a virtual network named myVNet.
  • myVNet 包含名为 VM1VM2 的两个 VM 网络。The myVNet network includes two VMs named VM1 and VM2.
  • VM1 和 VM2 位于名为 myAvailset 的同一个可用性集中。VM1 and VM2 are in the same availability set named myAvailset.
  • VM1 和 VM2 各有一个主要 NIC,分别名为 VM1NIC1VM2NIC1VM1 and VM2 each have a primary NIC named VM1NIC1 and VM2NIC1, respectively.
  • VM1 和 VM2 各有一个辅助 NIC,分别名为 VM1NIC2VM2NIC2VM1 and VM2 each have a secondary NIC named VM1NIC2 and VM2NIC2, respectively.

有关创建具有多个 NIC 的 VM 的详细信息,请参阅使用 PowerShell 创建具有多个 NIC 的 VMFor more information about creating VMs with multiple NICs, see Create a VM with multiple NICs by using PowerShell.

针对多个 IP 配置执行负载均衡Perform load balancing on multiple IP configurations

完成以下步骤,实现本文中所述的方案:Complete the following steps to achieve the scenario outlined in this article.

步骤 1:配置辅助 NICStep 1: Configure the secondary NICs

对于虚拟网络中的每个 VM,请添加辅助 NIC 的 IP 配置:For each VM in your virtual network, add the IP configuration for the secondary NIC:

  1. 浏览到 Azure 门户: http://portal.azure.cn。Browse to the Azure portal: http://portal.azure.cn. 使用 Azure 帐户登录。Sign in with your Azure account.

  2. 在屏幕左上方,选择“资源组”图标。In the upper left of the screen, select the Resource Group icon. 然后选择 VM 所在的资源组(例如 contosofabrikam)。Then select the resource group where your VMs are located (for example, contosofabrikam). “资源组”窗格中显示了 VM 的所有资源和 NIC。The Resource groups pane displays all of the resources and NICs for the VMs.

  3. 针对每个 VM 的辅助 NIC,请添加 IP 配置:For the secondary NIC of each VM, add the IP configuration:

    1. 选择要配置的辅助 NIC。Select the secondary NIC that you want to configure.

    2. 选择“IP 配置”。Select IP configurations. 在下一个窗格中的顶部附近,选择“添加”。In the next pane, near the top, select Add.

    3. 在“添加 IP 配置”下,将第二个 IP 配置添加到 NIC:Under Add IP configurations, add a second IP configuration to the NIC:

      1. 输入辅助 IP 配置的名称。Enter a name for the secondary IP configuration. (例如,对于 VM1 和 VM2,分别将 IP 配置命名为 VM1NIC2-ipconfig2VM2NIC2-ipconfig2)。(For example, for VM1 and VM2, name the IP configuration VM1NIC2-ipconfig2 and VM2NIC2-ipconfig2, respectively.)

      2. 对于“专用 IP 地址”>“分配”设置,请选择“静态”。For the Private IP address, Allocation setting, select Static.

      3. 选择“确定” 。Select OK.

完成辅助 NIC 的第二个 IP 配置后,它会显示在给定 NIC 的“IP 配置”设置下。After the second IP configuration for the secondary NIC is complete, it's displayed under the IP configurations settings for the given NIC.

步骤 2:创建负载均衡器Step 2: Create the load balancer

为配置创建负载均衡器:Create your load balancer for the configuration:

  1. 浏览到 Azure 门户: http://portal.azure.cn。Browse to the Azure portal: http://portal.azure.cn. 使用 Azure 帐户登录。Sign in with your Azure account.

  2. 在屏幕的左上方,选择“创建资源” > “网络” > “负载均衡器”。In the upper left of the screen, select Create a resource > Networking > Load Balancer. 接下来,选择“创建”。Next, select Create.

  3. 在“创建负载均衡器”下,为负载均衡器键入一个名称。Under Create load balancer, type a name for your load balancer. 此方案使用名称 mylbIn this scenario, we're using the name mylb.

  4. 在“公共 IP 地址”下,创建名为 PublicIP1 的新公共 IP。Under Public IP address, create a new public IP called PublicIP1.

  5. 在“资源组”下,选择 VM 的现有资源组(例如 contosofabrikam)。Under Resource Group, select the existing resource group for your VMs (for example, contosofabrikam). 选择负载均衡器要部署到的位置,再选择“确定”。Select the location to deploy your load balancer to, and then select OK.

负载均衡器随即开始部署。The load balancer starts to deploy. 部署可能需要几分钟才能成功完成。Deployment can take a few minutes to successfully complete. 部署完成后,负载均衡器将作为资源显示在资源组中。After deployment is complete, the load balancer is displayed as a resource in your resource group.

步骤 3:配置前端 IP 池Step 3: Configure the front-end IP pool

针对每个网站(contoso.com 和 fabrikam.com),请在负载均衡器上配置前端 IP 池:For each website (contoso.com and fabrikam.com), configure the front-end IP pool on your load balancer:

  1. 在门户中选择“更多服务”。In the portal, select More services. 在筛选框中键入“公共 IP 地址”,选择“公共 IP 地址”。In the filter box, type Public IP address and then select Public IP addresses. 在下一个窗格中的顶部附近,选择“添加”。In the next pane, near the top, select Add.

  2. 为两个网站(contoso.com 和 fabrikam.com)配置两个公共 IP 地址(PublicIP1PublicIP2):Configure two public IP addresses (PublicIP1 and PublicIP2) for both websites (contoso.com and fabrikam.com):

    1. 键入前端 IP 地址的名称。Type a name for your front-end IP address.

    2. 对于“资源组”,请选择 VM 的现有资源组(例如 contosofabrikam)。For Resource Group, select the existing resource group for your VMs (for example, contosofabrikam).

    3. 对于“位置”,请选择 VM 所在的同一位置。For Location, select the same location as the VMs.

    4. 选择“确定” 。Select OK.

      创建公共 IP 地址后,它们会显示在“公共 IP 地址”下。After the public IP addresses are created, they are displayed under the Public IP addresses.

  3. 在门户中选择“更多服务”。In the portal, select More services. 在筛选框中键入“负载均衡器”,选择“负载均衡器”。In the filter box, type load balancer and then select Load Balancer.

  4. 选择要将前端 IP 池添加到的负载均衡器 (mylb)。Select the load balancer (mylb) that you want to add the front-end IP pool to.

  5. 在“设置”下,选择“前端 IP 配置”。Under Settings, select Frontend IP configuration. 在下一个窗格中的顶部附近,选择“添加”。In the next pane, near the top, select Add.

  6. 键入前端 IP 地址的名称(例如 contosofefabrikamfe)。Type a name for your front-end IP address (for example, contosofe or fabrikamfe).

  7. 选择“IP 地址”。Select IP address. 在“选择公共 IP 地址”下选择前端的 IP 地址(PublicIP1PublicIP2)。Under Choose Public IP address, select the IP addresses for your front-end (PublicIP1 or PublicIP2).

  8. 重复本部分中的步骤 3步骤 7,创建第二个前端 IP 地址。Create the second front-end IP address by repeating step 3 through step 7 in this section.

配置前端池后,IP 地址会显示在负载均衡器的“前端 IP 配置”设置下。After the front-end pool is configured, the IP addresses are displayed under your load balancer Frontend IP configuration settings.

步骤 4:配置后端池Step 4: Configure the back-end pool

针对每个网站(contoso.com 和 fabrikam.com),请在负载均衡器上配置后端地址池:For each website (contoso.com and fabrikam.com), configure the back-end address pool on your load balancer:

  1. 在门户中选择“更多服务”。In the portal, select More services. 在筛选框中键入“负载均衡器”,选择“负载均衡器”。In the filter box, type load balancer and then select Load Balancer.

  2. 选择要将后端池添加到的负载均衡器 (mylb)。Select the load balancer (mylb) that you want to add the back-end pool to.

  3. 在“设置”下,选择“后端池”。Under Settings, select Backend Pools. 键入后端池的名称(例如 contosopoolfabrikampool)。Type a name for your back-end pool (for example, contosopool or fabrikampool). 在下一个窗格中的顶部附近,选择“添加”。In the next pane, near the top, select Add.

  4. 对于“关联到”,请选择“可用性集”。For Associated to, select Availability set.

  5. 对于“可用性集”,请选择“myAvailset”。For Availability set, select myAvailset.

  6. 为两个 VM 添加目标网络 IP 配置:Add the target network IP configurations for both VMs:

    为负载均衡器配置后端池

    1. 对于“目标虚拟机”,请选择要添加到后端池的 VM(例如 VM1VM2)。For Target virtual machine, select the VM that you want to add to the back-end pool (for example, VM1 or VM2).

    2. 对于“网络 IP 配置”,请选择在前一步骤中为 VM 的辅助 NIC 选择的 IP 配置(例如 VM1NIC2-ipconfig2VM2NIC2-ipconfig2)。For Network IP configuration, select the IP configuration of the secondary NIC for the VM that you selected in the previous step (for example, VM1NIC2-ipconfig2 or VM2NIC2-ipconfig2).

  7. 选择“确定” 。Select OK.

配置后端池后,地址会显示在负载均衡器的“后端池”设置下。After the back-end pool is configured, the addresses are displayed under your load balancer Backend pool settings.

步骤 5:配置运行状况探测Step 5: Configure the health probe

为负载均衡器配置运行状况探测Configure a health probe for your load balancer:

  1. 在门户中选择“更多服务”。In the portal, select More services. 在筛选框中键入“负载均衡器”,选择“负载均衡器”。In the filter box, type load balancer and then select Load Balancer.

  2. 选择要将运行状况探测添加到的负载均衡器 (mylb)。Select the load balancer (mylb) that you want to add the health probe to.

  3. 在“设置”下,选择“运行状况探测”。Under Settings, select Health probe. 在下一个窗格中的顶部附近,选择“添加”。In the next pane, near the top, select Add.

  4. 键入运行状况探测的名称(例如 HTTP)。Type a name for the health probe (for example, HTTP). 选择“确定” 。Select OK.

步骤 6:配置负载均衡规则Step 6: Configure load balancing rules

针对每个网站(contoso.com 和 fabrikam.com),请配置负载均衡规则:For each website (contoso.com and fabrikam.com), configure the load balancing rules:

  1. 在“设置”下,选择“负载均衡规则”。Under Settings, select Load balancing rules. 在下一个窗格中的顶部附近,选择“添加”。In the next pane, near the top, select Add.

  2. 对于“名称”,请键入负载均衡规则的名称(例如,为 contoso.com 键入 HTTPc,为 fabrikam.com 键入 HTTPf)。For Name, type a name for the load balancing rule (for example, HTTPc for contoso.com, or HTTPf for fabrikam.com).

  3. 对于“前端 IP 地址”,请选择前面创建的前端 IP 地址(例如 contosofefabrikamfe)。For Frontend IP address, select the front-end IP address that you previously created (for example, contosofe or fabrikamfe).

  4. 对于“端口”和“后端端口”,请保留默认值 80For Port and Backend port, keep the default value 80.

  5. 对于“浮动 IP (直接服务器返回)”,选择“已禁用”。For Floating IP (direct server return), select Disabled.

  6. 选择“确定”。Select OK.

  7. 重复本部分中的步骤 1步骤 6,创建第二个负载均衡器规则。Create the second load balancer rule by repeating step 1 through step 6 in this section.

配置规则后,它们会显示在负载均衡器的“负载均衡规则”设置下。After the rules are configured, they are displayed under your load balancer Load balancing rules settings.

步骤 7:配置 DNS 记录Step 7: Configure DNS records

最后一个步骤是,将 DNS 资源记录配置为指向负载均衡器的相应前端 IP 地址。As the last step, configure your DNS resource records to point to the respective front-end IP addresses for your load balancer. 可以在 Azure DNS 中托管域。You can host your domains in Azure DNS. 有关将 Azure DNS 与负载均衡器配合使用的详细信息,请参阅将 Azure DNS 与其他 Azure 服务配合使用For more information about using Azure DNS with Load Balancer, see Using Azure DNS with other Azure services.

后续步骤Next steps