使用 Azure PowerShell 配置包含现有 Azure 负载均衡器的虚拟机规模集Configure a virtual machine scale set with an existing Azure Load Balancer using Azure PowerShell

本文介绍如何配置包含现有 Azure 负载均衡器的虚拟机规模集。In this article, you'll learn how to configure a virtual machine scale set with an existing Azure Load Balancer.

必备条件Prerequisites

  • Azure 订阅。An Azure subscription.
  • 要将虚拟机规模集部署到的订阅中的现有标准 SKU 负载均衡器。An existing standard sku load balancer in the subscription where the virtual machine scale set will be deployed.
  • 虚拟机规模集的 Azure 虚拟网络。An Azure Virtual Network for the virtual machine scale set.

备注

本文已经过更新,以便使用 Azure Az PowerShell 模块。This article has been updated to use the Azure Az PowerShell module. 若要与 Azure 交互,建议使用的 PowerShell 模块是 Az PowerShell 模块。The Az PowerShell module is the recommended PowerShell module for interacting with Azure. 若要开始使用 Az PowerShell 模块,请参阅安装 Azure PowerShellTo get started with the Az PowerShell module, see Install Azure PowerShell. 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 AzTo learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

登录 Azure CLISign in to Azure CLI

登录到 Azure。Sign into Azure.

Connect-AzAccount -Environment AzureChinaCloud

部署包含现有负载均衡器的虚拟机规模集Deploy a virtual machine scale set with existing load balancer

请将括号中的值替换为配置中的资源名称。Replace the values in brackets with the names of the resources in your configuration.


$rsg = <resource-group>
$loc = <location>
$vms = <vm-scale-set-name>
$vnt = <virtual-network>
$sub = <subnet-name>
$lbn = <load-balancer-name>
$pol = <upgrade-policy-mode>

$lb = Get-AzLoadBalancer -ResourceGroupName $rsg -Name $lbn

New-AzVmss -ResourceGroupName $rsg -Location $loc -VMScaleSetName $vms -VirtualNetworkName $vnt -SubnetName $sub -LoadBalancerName $lb -UpgradePolicyMode $pol

以下示例部署一个虚拟机规模集:The below example deploys a virtual machine scale set with:

  • 该虚拟机规模集名为 myVMSS Virtual machine scale set named myVMSS
  • 其中包含名为 myLoadBalancer 的 Azure 负载均衡器 Azure Load Balancer named myLoadBalancer
  • 其中包含名为 myBackendPool 的负载均衡器后端池 Load balancer backend pool named myBackendPool
  • 其中包含名为 myVnet 的 Azure 虚拟网络 Azure Virtual Network named myVnet
  • 其中包含名为 mySubnet 的子网 Subnet named mySubnet
  • 其中包含名为 myResourceGroup 的资源组 Resource group named myResourceGroup

$rsg = "myResourceGroup"
$loc = "China East 2"
$vms = "myVMSS"
$vnt = "myVnet"
$sub = "mySubnet"
$pol = "Automatic"
$lbn = "myLoadBalancer"

$lb = Get-AzLoadBalancer -ResourceGroupName $rsg -Name $lbn

New-AzVmss -ResourceGroupName $rsg -Location $loc -VMScaleSetName $vms -VirtualNetworkName $vnt -SubnetName $sub -LoadBalancerName $lb -UpgradePolicyMode $pol

备注

创建规模集后,无法为负载均衡器的运行状况探测所用的负载均衡规则修改后端端口。After the scale set has been created, the backend port cannot be modified for a load balancing rule used by a health probe of the load balancer. 为了更改端口,可以通过更新 Azure 虚拟机规模集来删除运行状况探测,更新端口,然后重新配置运行状况探测。To change the port, you can remove the health probe by updating the Azure virtual machine scale set, update the port and then configure the health probe again.

后续步骤Next steps

在本文中,你已部署一个包含现有 Azure 负载均衡器的虚拟机规模集。In this article, you deployed a virtual machine scale set with an existing Azure Load Balancer. 若要详细了解虚拟机规模集和负载均衡器,请参阅:To learn more about virtual machine scale sets and load balancer, see: