使用 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 PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

登录 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: