你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

使用 PowerShell 创建或修改直接对等互连

本文介绍如何使用 PowerShell cmdlet 和 Azure 资源管理器部署模型创建 Microsoft 直接对等互连。 本文还介绍如何查看资源状态,以及如何更新、删除和取消预配资源。

如果需要,可以使用 Azure 门户完成本指南。

开始之前

使用 Azure PowerShell

若要运行 cmdlet,可以使用 Azure Cloud Shell(一个免费的交互式 shell)。 它预安装有常用 Azure 工具并将其配置与帐户一起使用。 选择“复制”以复制代码,并将其粘贴到 Cloud Shell。 然后选择 Enter 运行此代码。 可通过多种方式来启动 Cloud Shell:

启动方法 屏幕快照
在浏览器中打开 Cloud Shell。 https://shell.azure.com/powershell
选择 Azure 门户右上角工具栏上的“Cloud Shell”按钮。 Cloud Shell in the portal

如果不想使用 Azure Cloud Shell,则可以改为在本地安装 PowerShell。 如果选择在本地安装和使用 PowerShell,请务必安装最新版本的 Azure 资源管理器 PowerShell cmdlet。 PowerShell cmdlet 经常更新。 你通常需要更新 PowerShell cmdlet 才能获取最新的功能。 否则,可能会遇到问题。

若要查找你在本地运行的 PowerShell 版本,请使用“Get-Module -ListAvailable Az”cmdlet。 若要更新,请参阅安装 Azure PowerShell 模块。 有关详细信息,请参阅如何安装和配置 Azure PowerShell

如果在 macOS 上使用 PowerShell,请按照在 macOS 上安装 PowerShell 中的步骤操作。

创建和预配直接对等互连

登录到 Azure 帐户,然后选择订阅

在开始配置之前,请安装并导入所需的模块。 你需要具有管理员权限才能在 PowerShell 中安装模块。

  1. 安装并导入 Az 模块。

    Install-Module Az -AllowClobber
    Import-Module Az
    
  2. 安装并导入 Az.Peering 模块。

    Install-Module -Name Az.Peering -AllowClobber
    Import-Module Az.Peering
    
  3. 使用此命令验证是否已正确导入模块:

    Get-Module
    
  4. 使用以下命令登录到 Azure 帐户:

    Connect-AzAccount
    
  5. 查看帐户的订阅,并选择要在其中创建对等互连的订阅。

    Get-AzSubscription
    Select-AzSubscription -SubscriptionId "subscription-id"
    
  6. 如果尚未有资源组,则在创建对等互连之前,必须先创建一个资源组。 为此,可以运行以下命令:

    New-AzResourceGroup -Name "PeeringResourceGroup" -Location "Central US"
    

重要

如果尚未关联 ASN 和订阅,请按照关联对等 ASN 中的步骤进行操作。 请求对等互连时需要此操作。

注意

资源组的位置与选择设置对等互连的位置无关。  

获取直接对等互连支持的对等互连位置的列表

PowerShell cmdlet Get-AzPeeringLocation 返回具有必需参数 Kind 的对等互连位置的列表,你将在后续步骤中用到该参数

Get-AzPeeringLocation -Kind Direct

直接对等互连位置包含以下字段:

  • PeeringLocation
  • Country
  • PeeringDBFacilityId
  • PeeringDBFacilityLink
  • BandwidthOffers

请参阅 PeeringDB,验证你是否在所需的对等互连设施中。

此示例演示如何使用西雅图作为对等互连位置创建直接对等互连。

$peeringLocations = Get-AzPeeringLocation -Kind Direct
$peeringLocation = $peeringLocations | where {$_.PeeringLocation -contains "Seattle"}
$peeringLocation

PeeringLocation       : Seattle
Address               : 2001 Sixth Avenue
Country               : US
PeeringDBFacilityId   : 71
PeeringDBFacilityLink : https://www.peeringdb.com/fac/71
BandwidthOffers       : {10Gbps, 100Gbps}

创建直接对等互连

下面的示例演示如何在西雅图创建 10 Gbps 的直接对等互连。

使用 PowerShell cmdlet New-AzPeeringDirectConnectionObject 创建要在新对等互连请求中使用的 DirectConnection 对象

此示例演示如何创建 DirectConnection 对象。

$connection1 = New-AzPeeringDirectConnectionObject `
    -PeeringDBFacilityId $peeringLocation[0].PeeringDBFacilityId `
    -SessionPrefixV4 10.21.31.0/31 `
    -SessionPrefixV6 fe01::3e:0/127 `
    -MaxPrefixesAdvertisedIPv4 1000 `
    -MaxPrefixesAdvertisedIPv6 100 `
    -BandwidthInMbps 10000

注意

上一示例中 $peeringLocation[] 的值应对应于所选的对等互连位置

如果在给定对等互连位置需要冗余,请另创建一个连接。

$connection2 = New-AzPeeringDirectConnectionObject `
    -PeeringDBFacilityId $peeringLocation[0].PeeringDBFacilityId `
    -SessionPrefixV4 10.21.33.0/31 `
    -SessionPrefixV6 fe01::3f:0/127 `
    -MaxPrefixesAdvertisedIPv4 1000 `
    -MaxPrefixesAdvertisedIPv6 100 `
    -BandwidthInMbps 10000

使用 PowerShell cmdlet New-AzPeering 创建新的直接对等互连。 此命令需要 ASN 资源 ID,你可通过如下所示的方式检索此 ID。

$asn = Get-AzPeerAsn
New-AzPeering `
    -Name "SeattleDirectPeering" `
    -ResourceGroupName "PeeringResourceGroup" `
    -PeeringLocation  $peeringLocation[0].PeeringLocation `
    -PeerAsnResourceId $asn.Id `
    -DirectConnection $connection1 [, $connection2]

 

此示例显示成功处理请求时的响应。


    Name                 : SeattleDirectPeering
    Sku.Name             : Basic_Direct_Free
    Kind                 : Direct
    Connections          : 71
    PeerAsn.Id           : /subscriptions/{subscriptionId}/providers/Microsoft.Peering/peerAsns/SeattleDirectPeering
    UseForPeeringService : False
    PeeringLocation      : Seattle
    ProvisioningState    : Succeeded
    Location             : centralus
    Id                   : /subscriptions/{subscriptionId}/resourceGroups/PeeringResourceGroup/providers/Microsoft.Peering/peerings/SeattleDirectPeering
    Type                 : Microsoft.Peering/peerings
    Tags                 : {}

请注意,在此输出中替换 {subscriptionId},将显示实际的订阅 ID

验证直接对等互连

若要获取对等互连的列表,请运行 Get-AzPeering 命令

$directPeering = Get-AzPeering -ResourceGroupName "PeeringResourceGroup" -Name "SeattleDirectPeering"

下面的示例显示成功完成端到端预配时的响应。

    Name                 : SeattleDirectPeering
    Sku.Name             : Basic_Direct_Free
    Kind                 : Direct
    Connections          : {71}
    PeerAsn.Id           : /subscriptions/{subscriptionId}/providers/Microsoft.Peering/peerAsns/SeattleDirectPeering
    UseForPeeringService : False
    PeeringLocation      : Seattle
    ProvisioningState    : Succeeded
    Location             : centralus
    Id                   : /subscriptions/{subscriptionId}/resourceGroups/PeeringResourceGroup/providers/Microsoft.Peering/peerings/SeattleDirectPeering
    Type                 : Microsoft.Peering/peerings
    Tags                 : {}

修改直接对等互连

本部分介绍如何对直接对等互连执行以下修改操作:

  • 添加直接对等互连连接。
  • 删除直接对等互连连接。
  • 升级或降级活动连接上的带宽。
  • 在活动连接上添加 IPv4 或 IPv6 会话。
  • 删除活动连接上的 IPv4 或 IPv6 会话。

添加直接对等互连连接

此示例说明如何将连接添加到现有直接对等互连。


$directPeering = Get-AzPeering -Name "SeattleDirectPeering" -ResourceGroupName "PeeringResourceGroup"

$connection = New-AzPeeringDirectConnection `
    -PeeringDBFacilityId $peeringLocation.PeeringDBFacilityId `
    -SessionPrefixV4 "10.22.31.0/31" `
    -SessionPrefixV6 "fe02::3e:0/127" `
    -MaxPrefixesAdvertisedIPv4 1000 `
    -MaxPrefixesAdvertisedIPv6 100 `
    -BandwidthInMbps 10000

$directPeering.Connections.Add($connection)

$directPeering | Update-AzPeering

删除直接对等互连连接

PowerShell 当前不支持删除连接。 有关详细信息,请联系 Microsoft 对等互连团队。

升级或降级活动连接上的带宽

此示例说明如何将 10 Gbps 添加到现有的直接连接。


$directPeering = Get-AzPeering -Name "SeattleDirectPeering" -ResourceGroupName "PeeringResourceGroup"
$directPeering.Connections[0].BandwidthInMbps  = 20000
$directPeering | Update-AzPeering

在活动连接上添加 IPv4 或 IPv6 会话

此示例说明如何在只具有 IPv4 会话的现有直接连接上添加 IPv6 会话。


$directPeering = Get-AzPeering -Name "SeattleDirectPeering" -ResourceGroupName "PeeringResourceGroup"
$directPeering.Connections[0].BGPSession.SessionPrefixv6 = "fe01::3e:0/127"
$directPeering | Update-AzPeering

删除活动连接上的 IPv4 或 IPv6 会话

PowerShell 当前不支持从现有连接中删除 IPv4 或 IPv6 会话。 有关详细信息,请联系 Microsoft 对等互连团队。

取消预配直接对等互连

目前,不支持使用 Azure 门户或 PowerShell 取消设置。 若要取消设置,请联系 Microsoft 对等互连

其他资源

可以通过运行以下命令获取所有这些参数的详细说明:

Get-Help Get-AzPeering -detailed

后续步骤