使用 PowerShell 创建和修改 ExpressRoute 线路

时间:2023-03-08 23:58:09
使用 PowerShell 创建和修改 ExpressRoute 线路

开始之前

创建和预配 ExpressRoute 线路

1.登录到 Azure 帐户,并选择订阅

要开始配置,请登录到 Azure 帐户。 使用下面的示例来帮助你连接:

PowerShell复制
Login-AzureRmAccount -Environment $(Get-AzureRmEnvironment -Name AzureChinaCloud)

检查该帐户的订阅:

PowerShell复制
Get-AzureRmSubscription

选择要为其创建 ExpressRoute 线路的订阅:

PowerShell复制
Select-AzureRmSubscription -SubscriptionId "<subscription ID>"

2.获取支持的提供商、位置和带宽的列表

在创建 ExpressRoute 线路之前,需要支持的连接服务提供商、位置和带宽选项的列表。

PowerShell cmdlet Get-AzureRmExpressRouteServiceProvider 会返回此信息,将在后续步骤中使用此信息:

PowerShell复制
Get-AzureRmExpressRouteServiceProvider

检查连接服务提供商是否已在该处列出。 记下以下信息。 以后在创建线路时,需要该信息。

  • 名称
  • PeeringLocations
  • BandwidthsOffered

现在,已经准备创建 ExpressRoute 线路。

3.创建 ExpressRoute 线路

如果还没有资源组,则在创建 ExpressRoute 线路前必须创建一个资源组。 为此,可以运行以下命令:

PowerShell复制
New-AzureRmResourceGroup -Name "ExpressRouteResourceGroup" -Location "China east"

以下示例演示如何通过北京中的 Beijing Telecom Ethernet 创建 200-Mbps 的 ExpressRoute 线路。 如果使用其他提供商和其他设置,请在发出请求时替换该信息。 下面是请求新的服务密钥的示例:

PowerShell复制
New-AzureRmExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup" -Location "China east" -SkuTier Standard -SkuFamily MeteredData -ServiceProviderName "Beijing Telecom Ethernet" -PeeringLocation "Beijing" -BandwidthInMbps 200

请确保指定合适的 SKU 层和 SKU 系列:

  • SKU 层决定是否启用 ExpressRoute 标准版或 ExpressRoute 高级版外接程序。 可以指定“Standard”以获取标准 SKU,或指定“Premium”以获取高级版外接程序。

  • SKU 系列确定计费类型。 可以指定“Metereddata”以获取数据流量套餐,指定“Unlimiteddata”以获取无限制流量套餐。 可以将计费类型从“Metereddata”更改为“Unlimiteddata”,但不能将类型从“Unlimiteddata”更改为“Metereddata”。

Important

从发布服务密钥的那一刻起,便会对 ExpressRoute 线路进行计费。 确保连接服务提供商准备好预配线路后就执行此操作。

响应包含服务密钥。 可以通过运行以下命令获取所有这些参数的详细说明:

PowerShell复制
get-help New-AzureRmExpressRouteCircuit -detailed

4.列出所有 ExpressRoute 线路

若要获取已创建的所有 ExpressRoute 线路的列表,请运行 Get-AzureRmExpressRouteCircuit 命令:

PowerShell复制
Get-AzureRmExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

响应如以下示例中所示:

复制
Name                             : ExpressRouteARMCircuit
ResourceGroupName : ExpressRouteResourceGroup
Location : chinaeast
Id : /subscriptions/***************************/resourceGroups/ExpressRouteResourceGroup/providers/Microsoft.Network/expressRouteCircuits/ExpressRouteARMCircuit
Etag : W/"################################"
ProvisioningState : Succeeded
Sku : {
"Name": "Standard_MeteredData",
"Tier": "Standard",
"Family": "MeteredData"
}
CircuitProvisioningState : Enabled
ServiceProviderProvisioningState : NotProvisioned
ServiceProviderNotes :
ServiceProviderProperties : {
"ServiceProviderName": "Beijing Telecom Ethernet",
"PeeringLocation": "Beijing",
"BandwidthInMbps": 200
}
ServiceKey : **************************************
Peerings : []

可以随时使用 Get-AzureRmExpressRouteCircuit cmdlet 检索此信息。 如果调用不带任何参数,则列出所有线路。 你的服务密钥会在 ServiceKey 字段中列出:

PowerShell复制
Get-AzureRmExpressRouteCircuit

响应如以下示例中所示:

复制
Name                             : ExpressRouteARMCircuit
ResourceGroupName : ExpressRouteResourceGroup
Location : chinaeast
Id : /subscriptions/***************************/resourceGroups/ExpressRouteResourceGroup/providers/Microsoft.Network/expressRouteCircuits/ExpressRouteARMCircuit
Etag : W/"################################"
ProvisioningState : Succeeded
Sku : {
"Name": "Standard_MeteredData",
"Tier": "Standard",
"Family": "MeteredData"
}
CircuitProvisioningState : Enabled
ServiceProviderProvisioningState : NotProvisioned
ServiceProviderNotes :
ServiceProviderProperties : {
"ServiceProviderName": "Beijing Telecom Ethernet",
"PeeringLocation": "Beijing",
"BandwidthInMbps": 200
}
ServiceKey : **************************************
Peerings : []

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

PowerShell复制
get-help Get-AzureRmExpressRouteCircuit -detailed

5.将服务密钥发送给连接服务提供商进行预配

ServiceProviderProvisioningState 提供有关服务提供商端当前预配状态的信息。 “状态”提供 Microsoft 端的状态。 有关线路预配状态的详细信息,请参阅工作流一文。

创建新的 ExpressRoute 线路时,线路处于以下状态:

复制
ServiceProviderProvisioningState : NotProvisioned
CircuitProvisioningState : Enabled

当连接提供商正在为你启用线路时,线路将转为以下状态:

复制
ServiceProviderProvisioningState : Provisioning
Status : Enabled

ExpressRoute 线路必须处于以下状态时才能使用:

复制
ServiceProviderProvisioningState : Provisioned
CircuitProvisioningState : Enabled

6.定期检查线路密钥的状态

检查线路密钥的状态,可以通过此状态了解提供商何时启用了线路。 配置线路后,ServiceProviderProvisioningState 将显示为“已预配”,如以下示例所示:

PowerShell复制
Get-AzureRmExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

响应如以下示例中所示:

复制
Name                             : ExpressRouteARMCircuit
ResourceGroupName : ExpressRouteResourceGroup
Location : chinaeast
Id : /subscriptions/***************************/resourceGroups/ExpressRouteResourceGroup/providers/Microsoft.Network/expressRouteCircuits/ExpressRouteARMCircuit
Etag : W/"################################"
ProvisioningState : Succeeded
Sku : {
"Name": "Standard_MeteredData",
"Tier": "Standard",
"Family": "MeteredData"
}
CircuitProvisioningState : Enabled
ServiceProviderProvisioningState : Provisioned
ServiceProviderNotes :
ServiceProviderProperties : {
"ServiceProviderName": "Beijing Telecom Ethernet",
"PeeringLocation": "Beijing",
"BandwidthInMbps": 200
}
ServiceKey : **************************************
Peerings : []

7.创建路由配置

有关分步说明,请参阅 ExpressRoute 线路路由配置一文,了解如何创建和修改线路对等互连。

Important

这些说明只适用于由提供第 2 层连接服务的服务提供商创建的线路。 如果服务提供商提供第 3 层托管服务(通常是 IP VPN,如 MPLS),则连接服务提供商将配置和管理路由。

8.将虚拟网络链接到 ExpressRoute 线路

接下来,将虚拟网络链接到 ExpressRoute 线路。 使用 Resource Manager 部署模型时,请参阅将虚拟网络链接到 ExpressRoute 线路一文。

获取 ExpressRoute 线路的状态

可以随时使用 Get-AzureRmExpressRouteCircuit cmdlet 检索此信息。 如果调用不带任何参数,则列出所有线路。

PowerShell复制
Get-AzureRmExpressRouteCircuit

响应将如以下示例中所示:

复制
Name                             : ExpressRouteARMCircuit
ResourceGroupName : ExpressRouteResourceGroup
Location : chinaeast
Id : /subscriptions/***************************/resourceGroups/ExpressRouteResourceGroup/providers/Microsoft.Network/expressRouteCircuits/ExpressRouteARMCircuit
Etag : W/"################################"
ProvisioningState : Succeeded
Sku : {
"Name": "Standard_MeteredData",
"Tier": "Standard",
"Family": "MeteredData"
}
CircuitProvisioningState : Enabled
ServiceProviderProvisioningState : Provisioned
ServiceProviderNotes :
ServiceProviderProperties : {
"ServiceProviderName": "Beijing Telecom Ethernet",
"PeeringLocation": "Beijing",
"BandwidthInMbps": 200
}
ServiceKey : **************************************
Peerings : []

可以通过将资源组名称和线路名称作为参数传递给调用来获取有关特定 ExpressRoute 线路的信息:

PowerShell复制
Get-AzureRmExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

响应将如以下示例中所示:

复制
Name                             : ExpressRouteARMCircuit
ResourceGroupName : ExpressRouteResourceGroup
Location : chinaeast
Id : /subscriptions/***************************/resourceGroups/ExpressRouteResourceGroup/providers/Microsoft.Network/expressRouteCircuits/ExpressRouteARMCircuit
Etag : W/"################################"
ProvisioningState : Succeeded
Sku : {
"Name": "Standard_MeteredData",
"Tier": "Standard",
"Family": "MeteredData"
}
CircuitProvisioningState : Enabled
ServiceProviderProvisioningState : Provisioned
ServiceProviderNotes :
ServiceProviderProperties : {
"ServiceProviderName": "Beijing Telecom Ethernet",
"PeeringLocation": "Beijing",
"BandwidthInMbps": 200
}
ServiceKey : **************************************
Peerings : []

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

PowerShell复制
get-help get-azurededicatedcircuit -detailed

修改 ExpressRoute 线路

可以在不影响连接的情况下修改 ExpressRoute 线路的某些属性。

可以在不停机的情况下执行以下操作:

  • 为 ExpressRoute 线路启用或禁用 ExpressRoute 高级版外接程序。
  • 增加 ExpressRoute 线路的带宽,前提是端口上有可用容量。 不支持对线路的带宽进行降级。
  • 将计量套餐从数据流量套餐更改为无限制流量套餐。 不支持将计量套餐从无限制流量套餐更改为数据流量套餐。
  • 可以启用和禁用允许经典操作。

有关限制和局限性的详细信息,请参阅 ExpressRoute 常见问题解答

启用 ExpressRoute 高级版外接程序

可以使用以下 PowerShell 代码段为现有线路启用 ExpressRoute 高级版外接程序:

PowerShell复制
$ckt = Get-AzureRmExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

$ckt.Sku.Tier = "Premium"
$ckt.sku.Name = "Premium_MeteredData" Set-AzureRmExpressRouteCircuit -ExpressRouteCircuit $ckt

线路现已启用 ExpressRoute 高级版外接程序功能。 该命令成功运行后,我们就会立即对高级版外接程序功能收费。

禁用 ExpressRoute 高级版外接程序

Important

如果使用的资源超出标准线路允许的范围,此操作可能会失败。

注意以下事项:

  • 从高级版降级到标准版之前,必须确保链接到线路的虚拟网络数少于 10 个。 否则,更新请求会失败,并且我们将按高级版费率向你收费。

  • 必须取消其他地理政治区域的所有虚拟网络的链接。 否则,更新请求会失败,并且我们将按高级版费率向你收费。

  • 路由表中专用对等互连的路由必须少于 4,000。 如果路由表大小超出 4,000 个路由,则会删除 BGP 会话且不会重新启用它,除非已播发前缀的数目低于 4,000。

可以使用以下 PowerShell cmdlet 为现有线路禁用 ExpressRoute 高级版外接程序:

PowerShell复制
$ckt = Get-AzureRmExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

$ckt.Sku.Tier = "Standard"
$ckt.sku.Name = "Standard_MeteredData" Set-AzureRmExpressRouteCircuit -ExpressRouteCircuit $ckt

更新 ExpressRoute 线路带宽

有关提供商支持的带宽选项,请查看 ExpressRoute 常见问题解答。 可以选取大于现有线路大小的任何大小。

Important

如果现有端口上的容量不足,可能需要重新创建 ExpressRoute 线路。 如果该位置没有额外的可用容量,则不能升级线路。

但是,无法在不中断的情况下降低 ExpressRoute 线路的带宽。 带宽降级需要取消对 ExpressRoute 线路的预配,并重新预配新的 ExpressRoute 线路。

确定所需的大小后,可以使用以下命令调整线路的大小:

PowerShell复制
$ckt = Get-AzureRmExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

$ckt.ServiceProviderProperties.BandwidthInMbps = 1000

Set-AzureRmExpressRouteCircuit -ExpressRouteCircuit $ckt

会在 Microsoft 端调整线路的大小。 然后,用户必须联系连接提供商,让他们在那一边根据此更改更新配置。 在你发出此通知后,我们开始向你计收更新后的带宽选项费用。

将 SKU 从按流量计费转为不受限制

通过使用下面的 PowerShell 代码片段,可以更改 ExpressRoute 线路的 SKU:

PowerShell复制
$ckt = Get-AzureRmExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

$ckt.Sku.Family = "UnlimitedData"
$ckt.sku.Name = "Premium_UnlimitedData" Set-AzureRmExpressRouteCircuit -ExpressRouteCircuit $ckt

控制对经典环境和 Resource Manager 环境的访问

查看将 ExpressRoute 线路从经典部署模型转移到 Resource Manager 部署模型中的说明。

取消预配和删除 ExpressRoute 线路

注意以下事项:

  • 必须取消所有虚拟网络与 ExpressRoute 线路的链接。 如果此操作失败,请查看是否有虚拟网络链接到了该线路。

  • 如果 ExpressRoute 线路服务提供商预配状态为“正在预配”或“已预配”,则必须与服务提供商合作,在他们一端取消预配线路。 在服务提供商取消对线路的预配并通知我们之前,我们会继续保留资源并向你收费。

  • 如果服务提供商已取消预配线路(服务提供商预配状态设置为“未预配”),则可以删除线路。 这样就会停止线路计费

可以通过运行以下命令删除 ExpressRoute 线路:

PowerShell复制
Remove-AzureRmExpressRouteCircuit -ResourceGroupName "ExpressRouteResourceGroup" -Name "ExpressRouteARMCircuit"

后续步骤

创建线路后,请确保执行以下操作: