在 Azure 虚拟网络中将 IPv4 应用程序升级到 IPv6 - PowerShellUpgrade an IPv4 application to IPv6 in Azure virtual network - PowerShell

本文介绍如何将 IPv6 连接添加到 Azure 虚拟网络中使用标准负载均衡器和公共 IP 的现有 IPv4 应用程序。This article shows you how to add IPv6 connectivity to an existing IPv4 application in an Azure virtual network with a Standard Load Balancer and Public IP. 就地升级涉及到:The in-place upgrade includes:

  • 虚拟网络和子网的 IPv6 地址空间IPv6 address space for the virtual network and subnet
  • 采用 IPv4 和 IPV6 前端配置的标准负载均衡器a Standard Load Balancer with both IPv4 and IPV6 frontend configurations
  • 包含采用 IPv4 + IPv6 配置的 NIC 的 VMVMs with NICs that have both an IPv4 + IPv6 configuration
  • IPv6 公共 IP,使负载均衡器能够建立面向 Internet 的 IPv6 连接IPv6 Public IP so the load balancer has Internet-facing IPv6 connectivity

备注

本文进行了更新,以便使用新的 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 PowerShell 模块 6.9.0 或更高版本。This article requires the Azure PowerShell module version 6.9.0 or later. 运行 Get-Module -ListAvailable Az 查找已安装的版本。Run Get-Module -ListAvailable Az to find the installed version. 如果需要进行升级,请参阅 Install Azure PowerShell module(安装 Azure PowerShell 模块)。If you need to upgrade, see Install Azure PowerShell module. 如果在本地运行 PowerShell,则还需运行 Connect-AzAccount -Environment AzureChinaCloud 来创建与 Azure 的连接。If you are running PowerShell locally, you also need to run Connect-AzAccount -Environment AzureChinaCloud to create a connection with Azure.

先决条件Prerequisites

本文假设已根据以下文章所述部署了一个标准负载均衡器:快速入门:创建标准负载均衡器 - Azure PowerShellThis article assumes that you deployed a Standard Load Balancer as described in Quickstart: Create a Standard Load Balancer - Azure PowerShell.

检索资源组Retrieve the resource group

在创建双堆栈虚拟网络之前,必须先使用 Get-AzResourceGroup 创建检索资源组。Before you can create your dual-stack virtual network, you must retrieve the resource group with Get-AzResourceGroup.

 $rg = Get-AzResourceGroup  -ResourceGroupName "myResourceGroupSLB"

创建 IPv6 IP 地址Create an IPv6 IP addresses

使用 New-AzPublicIpAddress 为标准负载均衡器创建公共 IPv6 地址。Create a public IPv6 address with New-AzPublicIpAddress for your Standard Load Balancer. 以下示例在 myResourceGroupSLB 资源组中创建名为 PublicIP_v6 的 IPv6 公共 IP 地址:The following example creates an IPv6 public IP address named PublicIP_v6 in the myResourceGroupSLB resource group:


  $PublicIP_v6 = New-AzPublicIpAddress `
  -Name "PublicIP_v6" `
  -ResourceGroupName $rg.ResourceGroupName `
  -Location $rg.Location  `
  -Sku Standard  `
  -AllocationMethod Static `
  -IpAddressVersion IPv6

配置负载均衡器前端Configure load balancer frontend

检索现有的负载均衡器配置,然后使用 Add-AzLoadBalancerFrontendIpConfig 添加新的 IPv6 IP 地址,如下所示:Retrieve the existing load balancer configuration and then add the new IPv6 IP address using Add-AzLoadBalancerFrontendIpConfig as follows:

# Retrieve the load balancer configuration
$lb = Get-AzLoadBalancer -ResourceGroupName $rg.ResourceGroupName -Name "MyLoadBalancer"
# Add IPv6 components to the local copy of the load balancer configuration
$lb | Add-AzLoadBalancerFrontendIpConfig `
  -Name "dsLbFrontEnd_v6" `
  -PublicIpAddress $PublicIP_v6
#Update the running load balancer with the new frontend
$lb | Set-AzLoadBalancer

配置负载均衡器后端池Configure load balancer backend pool

在负载均衡器配置的本地副本中创建后端池,并使用新的后端池配置更新正在运行的负载均衡器,如下所示:Create the backend pool on the local copy of the load balancer configuration and update the running load balancer with the new backend pool configuration as follows:

$lb | Add-AzLoadBalancerBackendAddressPoolConfig -Name "LbBackEndPool_v6"
# Update the running load balancer with the new backend pool
$lb | Set-AzLoadBalancer

配置负载均衡器规则Configure load balancer rules

检索现有的负载均衡器前端和后端池配置,然后使用 Add-AzLoadBalancerRuleConfig 添加新的负载均衡规则。Retrieve the existing load balancer frontend and backend pool configuration and then add new load-balancing rules using Add-AzLoadBalancerRuleConfig.

# Retrieve the updated (live) versions of the frontend and backend pool
$frontendIPv6 = Get-AzLoadBalancerFrontendIpConfig -Name "dsLbFrontEnd_v6" -LoadBalancer $lb
$backendPoolv6 = Get-AzLoadBalancerBackendAddressPoolConfig -Name "LbBackEndPool_v6" -LoadBalancer $lb
# Create new LB rule with the frontend and backend
$lb | Add-AzLoadBalancerRuleConfig `
  -Name "dsLBrule_v6" `
  -FrontendIpConfiguration $frontendIPv6 `
  -BackendAddressPool $backendPoolv6 `
  -Protocol Tcp `
  -FrontendPort 80 `
  -BackendPort 80
#Finalize all the load balancer updates on the running load balancer
$lb | Set-AzLoadBalancer

添加 IPv6 地址范围Add IPv6 address ranges

将 IPv6 地址范围添加到托管 VM 的虚拟网络和子网,如下所示:Add IPv6 address ranges to the virtual network and subnet hosting the VMs as follows:

#Add IPv6 ranges to the VNET and subnet
#Retreive the VNET object
$vnet = Get-AzVirtualNetwork  -ResourceGroupName $rg.ResourceGroupName -Name "myVnet" 
#Add IPv6 prefix to the VNET
$vnet.addressspace.addressprefixes.add("ace:cab:deca::/48")
#Update the running VNET
$vnet |  Set-AzVirtualNetwork

#Retrieve the subnet object from the local copy of the VNET
$subnet= $vnet.subnets[0]
#Add IPv6 prefix to the Subnet (subnet of the VNET prefix, of course)
$subnet.addressprefix.add("ace:cab:deca::/64")
#Update the running VNET with the new subnet configuration
$vnet |  Set-AzVirtualNetwork

将 IPv6 配置添加到 NICAdd IPv6 configuration to NIC

运行 Add-AzNetworkInterfaceIpConfig 配置使用 IPv6 地址的所有 VM NIC,如下所示:Configure all of the VM NICs with an IPv6 address using Add-AzNetworkInterfaceIpConfig as follows:


#Retrieve the NIC objects
$NIC_1 = Get-AzNetworkInterface -Name "myNic1" -ResourceGroupName $rg.ResourceGroupName
$NIC_2 = Get-AzNetworkInterface -Name "myNic2" -ResourceGroupName $rg.ResourceGroupName
$NIC_3 = Get-AzNetworkInterface -Name "myNic3" -ResourceGroupName $rg.ResourceGroupName
#Add an IPv6 IPconfig to NIC_1 and update the NIC on the running VM
$NIC_1 | Add-AzNetworkInterfaceIpConfig -Name MyIPv6Config -Subnet $vnet.Subnets[0]  -PrivateIpAddressVersion IPv6 -LoadBalancerBackendAddressPool $backendPoolv6 
$NIC_1 | Set-AzNetworkInterface
#Add an IPv6 IPconfig to NIC_2 and update the NIC on the running VM
$NIC_2 | Add-AzNetworkInterfaceIpConfig -Name MyIPv6Config -Subnet $vnet.Subnets[0]  -PrivateIpAddressVersion IPv6 -LoadBalancerBackendAddressPool $backendPoolv6 
$NIC_2 | Set-AzNetworkInterface
#Add an IPv6 IPconfig to NIC_3 and update the NIC on the running VM
$NIC_3 | Add-AzNetworkInterfaceIpConfig -Name MyIPv6Config -Subnet $vnet.Subnets[0]  -PrivateIpAddressVersion IPv6 -LoadBalancerBackendAddressPool $backendPoolv6 
$NIC_3 | Set-AzNetworkInterface

在 Azure 门户中查看 IPv6 双堆栈虚拟网络View IPv6 dual stack virtual network in Azure portal

可以在 Azure 门户中查看 IPv6 双堆栈虚拟网络,如下所示:You can view the IPv6 dual stack virtual network in Azure portal as follows:

  1. 在门户的搜索栏中输入 myVnetIn the portal's search bar, enter myVnet.

  2. 当“myVnet”出现在搜索结果中时,将其选中。****When myVnet appears in the search results, select it. 此时会启动名为 myVNet 的双堆栈虚拟网络的“概述”页。****This launches the Overview page of the dual stack virtual network named myVNet. 该双堆栈虚拟网络显示了位于 mySubnet 双堆栈子网中的三个 NIC,这些 NIC 采用 IPv4 和 IPv6 配置。The dual stack virtual network shows the three NICs with both IPv4 and IPv6 configurations located in the dual stack subnet named mySubnet.

    Azure 中的 IPv6 双堆栈虚拟网络

清理资源Clean up resources

如果不再需要资源组、VM 和所有相关的资源,可以使用 Remove-AzResourceGroup 命令将其删除。When no longer needed, you can use the Remove-AzResourceGroup command to remove the resource group, VM, and all related resources.

Remove-AzResourceGroup -Name MyAzureResourceGroupSLB

后续步骤Next steps

在本文中,你已将采用 IPv4 前端 IP 配置的现有标准负载均衡器更新为双堆栈(IPv4 和 IPv6)配置。In this article, you updated an existing Standard Load Balancer with a IPv4 frontend IP configuration to a dual stack (IPv4 and IPv6) configuration. 你还将 IPv6 配置添加到了后端池中 VM 的 NIC,并添加到了托管这些 VM 的虚拟网络。You also added IPv6 configurations to the NICs of the VMs in the backend pool and to the Virtual Network that hosts them. 若要详细了解 Azure 虚拟网络中的 IPv6 支持,请参阅 Azure 虚拟网络 IPv6 是什么?To learn more about IPv6 support in Azure virtual networks, see What is IPv6 for Azure Virtual Network?