使用模板创建内部负载均衡器Create an internal load balancer using a template

Azure 内部负载均衡器 (ILB) 可在驻留于云服务或虚拟网络(具有区域性作用域)中的虚拟机之间提供网络负载均衡。Azure Internal Load Balancer (ILB) provides network load balancing between virtual machines that reside inside a cloud service or a virtual network with a regional scope.

有关使用和配置具有区域性作用域的虚拟网络的信息,请参阅区域虚拟网络For information about the use and configuration of virtual networks with a regional scope, see Regional virtual networks. 已配置关联组的现有虚拟网络无法使用 ILB。Existing virtual networks that have been configured for an affinity group cannot use ILB.

配置方案Configuration scenario

在此方案中,我们将在虚拟网络中创建一个内部负载均衡器,如下图所示:In this scenario, we're creating an internal load balancer in a virtual network as shown in the following figure:

内部负载均衡器方案

方案的配置如下所示:The configuration for our scenario is as follows:

  • 两台分别名为 DB1 和 DB2 的虚拟机 Two virtual machines named DB1 and DB2
  • 内部负载均衡器的终结点Endpoints for the internal load balancer
  • 内部负载均衡器An internal load balancer

通过单击部署方式部署模板Deploy the template by using click to deploy

公共存储库中提供的示例模板采用包含用于生成上述方案的默认值的参数文件。The sample template available in the public repository uses a parameter file containing the default values used to generate the scenario described above. 要通过单击部署的方式来部署此模板,请访问此链接,单击“部署至 Azure” ,如有必要,请替换默认参数值,并按照门户中的说明进行操作。To deploy this template using click to deploy, follow this link, click Deploy to Azure, replace the default parameter values if necessary, and follow the instructions in the portal.

使用 PowerShell 部署模板Deploy the template by using PowerShell

若要使用 PowerShell 部署下载的模板,请执行以下步骤。To deploy the template you downloaded by using PowerShell, follow the steps below.

  1. 如果从未使用过 Azure PowerShell,请参阅 How to Install and Configure Azure PowerShell(如何安装和配置 Azure PowerShell),并始终按照说明进行操作,以登录到 Azure 并选择订阅。If you have never used Azure PowerShell, see How to Install and Configure Azure PowerShell and follow the instructions all the way to the end to sign into Azure and select your subscription.

  2. 将参数文件下载到本地磁盘。Download the parameters file to your local disk.

  3. 编辑该文件并将其保存。Edit the file and save it.

  4. 运行 New-AzResourceGroupDeployment cmdlet 以使用模板创建资源组。Run the New-AzResourceGroupDeployment cmdlet to create a resource group using the template.

    New-AzResourceGroupDeployment -Name TestRG -Location chinanorth `
        -TemplateFile 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/201-2-vms-internal-load-balancer/azuredeploy.json' `
        -TemplateParameterFile 'C:\temp\azuredeploy.parameters.json'
    

使用 Azure CLI 部署模板Deploy the template by using the Azure CLI

若要使用 Azure CLI 部署模板,请执行以下步骤。To deploy the template by using the Azure CLI, follow the steps below.

  1. 如果从未使用过 Azure CLI,请参阅安装和配置 Azure CLI,并按照说明进行操作,直到选择 Azure 帐户和订阅。If you have never used Azure CLI, see Install and Configure the Azure CLI and follow the instructions up to the point where you select your Azure account and subscription.

  2. 运行 azure config mode 命令以切换到 Resource Manager 模式,如下所示。Run the azure config mode command to switch to Resource Manager mode, as shown below.

    azure config mode arm
    

    下面是上述命令的预期输出:Here is the expected output for the command above:

    info:    New mode is arm
    
  3. 打开参数文件,选择其内容,然后将其保存到计算机上的文件中。Open the parameter file, select its contents, and save it to a file in your computer. 对于本示例,我们将参数文件保存到 parameters.jsonFor this example, we saved the parameters file to parameters.json.

  4. 运行 azure group deployment create 命令以使用之前下载并修改的模板和参数文件部署新的内部负载均衡器。Run the azure group deployment create command to deploy the new internal load balancer by using the template and parameter files you downloaded and modified above. 在输出后显示的列表说明了所用的参数。The list shown after the output explains the parameters used.

    azure group create --name TestRG --location chinanorth --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/201-2-vms-internal-load-balancer/azuredeploy.json --parameters-file parameters.json
    

后续步骤Next steps

使用源 IP 关联配置负载均衡器分发模式Configure a load balancer distribution mode using source IP affinity

配置负载均衡器的空闲 TCP 超时设置Configure idle TCP timeout settings for your load balancer

有关模板中负载均衡器的 JSON 语法和属性,请参阅 Microsoft.Network/loadBalancersFor the JSON syntax and properties of a load balancer in a template, see Microsoft.Network/loadBalancers.