本文帮助你使用 PowerShell 配置 ExpressRoute Global Reach。 有关详细信息,请参阅 ExpressRoute Global Reach。
开始之前
在开始配置前,请确保以下先决条件:
- 了解 ExpressRoute 线路预配工作流。
- ExpressRoute 线路处于“已预配”状态。
- 在 ExpressRoute 线路上配置了 Azure 专用对等互连。
- 如果要在本地运行 PowerShell,请验证计算机上是否安装了最新版本的 Azure PowerShell。
使用 Azure PowerShell
本文中的步骤和示例使用 Azure PowerShell Az 模块。 若要在计算机上本地安装 Az 模块,请参阅安装 Azure PowerShell。 若要详细了解新 Az 模块,请参阅新 Azure Powershell Az 模块简介。 PowerShell cmdlet 经常更新。 如果未运行最新版本,在说明中指定的值可能无法使用。 若要在系统上查找已安装的 PowerShell 版本,请使用 Get-Module -ListAvailable Az
cmdlet。
可以使用 Azure Cloud Shell 来运行大多数 PowerShell cmdlet 和 CLI 命令,而无需在本地安装 Azure PowerShell 或 CLI。 Azure Cloud Shell 是免费的交互式 Shell,预安装有常用 Azure 工具,并将其配置为与帐户一起使用。 若要在 Azure Cloud Shell 上运行本文中包含的任何代码,请打开 Cloud Shell 会话,对代码块使用“复制”按钮以复制代码,然后使用 Ctrl+Shift+V(在 Windows 和 Linux 上)或 Cmd+Shift+V(在 macOS 上)将其粘贴到 Cloud Shell 会话中。 粘贴的文本不会自动执行,请按“Enter”运行代码。
可通过多种方式来启动 Cloud Shell:
选项 | 链接 |
---|---|
单击代码块右上角的“试用”。 |
![]() |
在浏览器中打开 Cloud Shell。 | ![]() |
单击 Azure 门户右上角菜单上的“Cloud Shell”按钮。 |
![]() |
确定线路
登录到你的 Azure 帐户,选择要使用的订阅。
如果你使用 Azure Cloud Shell,则可在单击“试用”后自动登录到你的 Azure 帐户。 若要在本地登录,请使用提升的权限打开 PowerShell 控制台,并运行 cmdlet 以进行连接。
Connect-AzAccount
如果有多个订阅,请获取 Azure 订阅的列表。
Get-AzSubscription
指定要使用的订阅。
Select-AzSubscription -SubscriptionName "Name of subscription"
确定要使用的 ExpressRoute 线路。 可以在任意两条 ExpressRoute 线路的专用对等互连之间启用 ExpressRoute Global Reach,只要它们位于受支持的国家/地区并且是在不同的对等互连位置创建的。
- 如果你的订阅同时拥有这两条线路,则可以选择其中任一条线路来运行以下各部分中的配置。
- 如果两个线路位于不同的 Azure 订阅中,则你需要获得一个 Azure 订阅的授权。 然后,你在另一个 Azure 订阅中运行配置命令时传入授权密钥。
注意
只能在配置的线路中看到 ExpressRoute Global Reach 配置。
启用连接
启用本地网络之间的连接。 同一个 Azure 订阅中的线路以及不同订阅中的线路有单独的说明。
同一个 Azure 订阅中的 ExpressRoute 线路
使用以下命令来获取线路 1 和线路 2。 这两条线路位于同一订阅中。
$ckt_1 = Get-AzExpressRouteCircuit -Name "Your_circuit_1_name" -ResourceGroupName "Your_resource_group" $ckt_2 = Get-AzExpressRouteCircuit -Name "Your_circuit_2_name" -ResourceGroupName "Your_resource_group"
针对线路 1 运行以下命令并传入线路 2 的专用对等互连 ID。
专用对等互连 ID 看起来类似于以下示例:
/subscriptions/{your_subscription_id}/resourceGroups/{your_resource_group}/providers/Microsoft.Network/expressRouteCircuits/{your_circuit_name}/peerings/AzurePrivatePeering
-AddressPrefix 必须是一个 /29 IPv4 子网,例如
10.0.0.0/29
。 我们使用此子网中的 IP 地址在两条 ExpressRoute 线路之间建立连接。 不应当在 Azure 虚拟网络或本地网络中使用此子网中的地址。Add-AzExpressRouteCircuitConnectionConfig -Name 'Your_connection_name' -ExpressRouteCircuit $ckt_1 -PeerExpressRouteCircuitPeering $ckt_2.Peerings[0].Id -AddressPrefix '__.__.__.__/29'
注意
如果要为 ExpressRoute Global Reach 启用 IPv6 支持,必须为 -AddressPrefix 指定 /125 IPv6 子网,为 -AddressPrefixType 指定“IPv6”。
Add-AzExpressRouteCircuitConnectionConfig -Name 'Your_connection_name' -ExpressRouteCircuit $ckt_1 -PeerExpressRouteCircuitPeering $ckt_2.Peerings[0].Id -AddressPrefix '__.__.__.__/125' -AddressPrefixType IPv6
如下所示保存线路 1 上的配置:
Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt_1
当上面的操作完成后,将通过两条 ExpressRoute 线路在两端的本地网络之间创建连接。
不同 Azure 订阅中的 ExpressRoute 线路
如果两个线路位于不同的 Azure 订阅中,则你需要获得授权。 要配置连接,请执行以下步骤:
在线路 2 的订阅中生成授权密钥:
$ckt_2 = Get-AzExpressRouteCircuit -Name "Your_circuit_2_name" -ResourceGroupName "Your_resource_group" Add-AzExpressRouteCircuitAuthorization -ExpressRouteCircuit $ckt_2 -Name "Name_for_auth_key" Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt_2
记下线路 2 的专用对等互连 ID 以及授权密钥。
配置线路 1 订阅中的连接:
针对线路 1 运行以下命令,并传入线路 2 的专用对等互连 ID 以及授权密钥。
Add-AzExpressRouteCircuitConnectionConfig -Name 'Your_connection_name' -ExpressRouteCircuit $ckt_1 -PeerExpressRouteCircuitPeering "circuit_2_private_peering_id" -AddressPrefix '__.__.__.__/29' -AuthorizationKey '########-####-####-####-############'
注意
若要为 ExpressRoute Global Reach 启用 IPv6 支持,请为 -AddressPrefix 指定 /125 IPv6 子网,为 -AddressPrefixType 指定 IPv6。
Add-AzExpressRouteCircuitConnectionConfig -Name 'Your_connection_name' -ExpressRouteCircuit $ckt_1 -PeerExpressRouteCircuitPeering $ckt_2.Peerings[0].Id -AddressPrefix '__.__.__.__/125' -AddressPrefixType IPv6 -AuthorizationKey '########-####-####-####-############'
保存线路 1 的配置:
Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt_1
完成这些操作后,本地网络之间通过两个 ExpressRoute 线路进行连接。
验证配置
使用以下命令验证在其中进行了配置的线路(例如,上例中的线路 1)的配置。
$ckt_1 = Get-AzExpressRouteCircuit -Name "Your_circuit_1_name" -ResourceGroupName "Your_resource_group"
若要检查 CircuitConnectionStatus,请在 PowerShell 中运行 $ckt_1
。 它指示连接是“已连接”还是“已断开连接”。
禁用连接
若要禁用本地网络之间的连接,请针对在其中进行了配置的线路(例如,上例中的线路 1)运行以下命令。
$ckt_1 = Get-AzExpressRouteCircuit -Name "Your_circuit_1_name" -ResourceGroupName "Your_resource_group"
Remove-AzExpressRouteCircuitConnectionConfig -Name "Your_connection_name" -ExpressRouteCircuit $ckt_1
Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt_1
注意
要删除 IPv6 Global Reach 连接,请为 -AddressPrefixType 指定 IPv6,如下所示。
$ckt_1 = Get-AzExpressRouteCircuit -Name "Your_circuit_1_name" -ResourceGroupName "Your_resource_group"
Remove-AzExpressRouteCircuitConnectionConfig -Name "Your_connection_name" -ExpressRouteCircuit $ckt_1 -AddressPrefixType IPv6
Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt_1
可以运行 GET
操作来验证状态。
完成这些操作后,本地网络之间不再通过 ExpressRoute 线路进行连接。
更新连接配置
若要更新 Global Reach 连接配置,请执行以下步骤:
检索 ExpressRoute 线路:
$ckt_1 = Get-AzExpressRouteCircuit -Name "Your_circuit_1_name" -ResourceGroupName "Your_resource_group" $ckt_2 = Get-AzExpressRouteCircuit -Name "Your_circuit_2_name" -ResourceGroupName "Your_resource_group"
定义新的地址空间和地址前缀类型:
$addressSpace = 'aa:bb::0/125' $addressPrefixType = 'IPv6'
更新连接配置:
Set-AzExpressRouteCircuitConnectionConfig -Name "Your_connection_name" -ExpressRouteCircuit $ckt_1 -PeerExpressRouteCircuitPeering $ckt_2.Peerings[0].Id -AddressPrefix $addressSpace -AddressPrefixType $addressPrefixType
保存最新的配置:
Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt_1