使用 PowerShell 创建和修改 ExpressRoute 线路Create and modify an ExpressRoute circuit using PowerShell

本文可帮助你使用 PowerShell cmdlet 和 Azure 资源管理器部署模型创建 ExpressRoute 线路。This article helps you create an ExpressRoute circuit using PowerShell cmdlets and the Azure Resource Manager deployment model. 还可以检查线路状态、更新、删除或取消预配线路。You can also check the status, update, delete, or deprovision a circuit.

准备阶段Before you begin

在开始配置之前,请查看先决条件工作流Before you begin, review the prerequisites and workflows before you begin configuration.

使用 Azure PowerShellWorking with Azure PowerShell

本文中的步骤和示例使用 Azure PowerShell Az 模块。The steps and examples in this article use Azure PowerShell Az modules. 若要在计算机上本地安装 Az 模块,请参阅安装 Azure PowerShellTo install the Az modules locally on your computer, see Install Azure PowerShell. 若要详细了解新 Az 模块,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module, see Introducing the new Azure PowerShell Az module. PowerShell cmdlet 经常更新。PowerShell cmdlets are updated frequently. 如果未运行最新版本,在说明中指定的值可能无法使用。If you are not running the latest version, the values specified in the instructions may fail. 若要在系统上查找已安装的 PowerShell 版本,请使用 Get-Module -ListAvailable Az cmdlet。To find the installed versions of PowerShell on your system, use the Get-Module -ListAvailable Az cmdlet.

创建和预配 ExpressRoute 线路Create and provision an ExpressRoute circuit

1.登录到 Azure 帐户,然后选择订阅1. Sign in to your Azure account and select your subscription

要开始配置,请登录到 Azure 帐户。To begin your configuration, sign in to your Azure account. 使用下面的示例来帮助连接:Use the following examples to help you connect:

Login-AzureRmAccount -Environment $(Get-AzureRmEnvironment -Name AzureChinaCloud)

检查该帐户的订阅:Check the subscriptions for the account:

Get-AzureRmSubscription

选择要为其创建 ExpressRoute 线路的订阅:Select the subscription that you want to create an ExpressRoute circuit for:

Select-AzureRmSubscription -SubscriptionId "<subscription ID>"

2.获取支持的提供商、位置和带宽的列表2. Get the list of supported providers, locations, and bandwidths

在创建 ExpressRoute 线路之前,需要支持的连接服务提供商、位置和带宽选项的列表。Before you create an ExpressRoute circuit, you need the list of supported connectivity providers, locations, and bandwidth options.

PowerShell cmdlet Get-AzExpressRouteServiceProvider 会返回此信息,将在后续步骤中使用此信息:The PowerShell cmdlet Get-AzExpressRouteServiceProvider returns this information, which you’ll use in later steps:

Get-AzExpressRouteServiceProvider

检查连接服务提供商是否已在该处列出。Check to see if your connectivity provider is listed there. 请记下以下信息,稍后在创建线路时需要用到:Make a note of the following information, which you need later when you create a circuit:

  • NameName
  • PeeringLocationsPeeringLocations
  • BandwidthsOfferedBandwidthsOffered

现在,已经准备创建 ExpressRoute 线路。You're now ready to create an ExpressRoute circuit.

3.创建 ExpressRoute 线路3. Create an ExpressRoute circuit

如果还没有资源组,则在创建 ExpressRoute 线路前必须创建一个资源组。If you don't already have a resource group, you must create one before you create your ExpressRoute circuit. 为此,可以运行以下命令:You can do so by running the following command:

New-AzResourceGroup -Name "ExpressRouteResourceGroup" -Location "China North"

以下示例演示如何通过位于北京的 Beijing Telecom Ethernet 创建 200-Mbps 的 ExpressRoute 线路。The following example shows how to create a 200-Mbps ExpressRoute circuit through Beijing Telecom Ethernet in Beijing. 如果使用其他提供商和其他设置,请在发出请求时替换该信息。If you're using a different provider and different settings, substitute that information when you make your request. 使用以下示例请求新的服务密钥:Use the following example to request a new service key:

New-AzExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup" -Location "China North" -SkuTier Standard -SkuFamily MeteredData -ServiceProviderName "Beijing Telecom Ethernet" -PeeringLocation "Beijing" -BandwidthInMbps 200

请确保指定合适的 SKU 层和 SKU 系列:Make sure that you specify the correct SKU tier and SKU family:

  • SKU 层决定是否启用 ExpressRoute 标准版或 ExpressRoute 高级版外接程序。SKU tier determines whether an ExpressRoute standard or an ExpressRoute premium add-on is enabled. 可以指定“Standard” 以获取标准 SKU,或指定“Premium” 以获取高级版外接程序。You can specify Standard to get the standard SKU or Premium for the premium add-on.

  • SKU 系列确定计费类型。SKU family determines the billing type. 可以指定“Metereddata” 以获取数据流量套餐,指定“Unlimiteddata” 以获取无限制流量套餐。You can specify Metereddata for a metered data plan and Unlimiteddata for an unlimited data plan. 可以将计费类型从“Metereddata”更改为“Unlimiteddata”,但不能将类型从“Unlimiteddata”更改为“Metereddata”。 You can change the billing type from Metereddata to Unlimiteddata, but you can't change the type from Unlimiteddata to Metereddata.

Important

从发布服务密钥的那一刻起,会对 ExpressRoute 线路进行计费。Your ExpressRoute circuit is billed from the moment a service key is issued. 确保连接服务提供商准备好预配线路后就执行此操作。Ensure that you perform this operation when the connectivity provider is ready to provision the circuit.

响应将包含服务密钥。The response contains the service key. 可以通过运行以下命令获取所有这些参数的详细说明:You can get detailed descriptions of all the parameters by running the following command:

get-help New-AzExpressRouteCircuit -detailed

4.列出所有 ExpressRoute 线路4. List all ExpressRoute circuits

若要获取已创建的所有 ExpressRoute 线路的列表,请运行 Get-AzExpressRouteCircuit 命令:To get a list of all the ExpressRoute circuits that you created, run the Get-AzExpressRouteCircuit command:

Get-AzExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

响应类似于以下示例:The response looks similar to the following example:

Name                             : ExpressRouteARMCircuit
ResourceGroupName                : ExpressRouteResourceGroup
Location                         : chinanorth
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-AzExpressRouteCircuit cmdlet 检索此信息。You can retrieve this information at any time by using the Get-AzExpressRouteCircuit cmdlet. 如果调用不带任何参数,则列出所有线路。Making the call with no parameters lists all the circuits. 服务密钥会在 ServiceKey 字段中列出:Your service key is listed in the ServiceKey field:

Get-AzExpressRouteCircuit

响应类似于以下示例:The response looks similar to the following example:

Name                             : ExpressRouteARMCircuit
ResourceGroupName                : ExpressRouteResourceGroup
Location                         : chinanorth
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                         : []

5.将服务密钥发送给连接服务提供商进行预配5. Send the service key to your connectivity provider for provisioning

ServiceProviderProvisioningState 提供有关服务提供商端当前预配状态的信息。ServiceProviderProvisioningState provides information about the current state of provisioning on the service-provider side. “状态”提供 Microsoft 端的状态。Status provides the state on the Microsoft side. 有关线路预配状态的详细信息,请参阅工作流For more information about circuit provisioning states, see Workflows.

创建新的 ExpressRoute 线路时,线路处于以下状态:When you create a new ExpressRoute circuit, the circuit is in the following state:

ServiceProviderProvisioningState : NotProvisioned
CircuitProvisioningState         : Enabled

当连接服务提供商正在为你启用线路时,线路将更改为以下状态:The circuit changes to the following state when the connectivity provider is in the process of enabling it for you:

ServiceProviderProvisioningState : Provisioning
Status                           : Enabled

只有 ExpressRoute 线路处于以下状态时,才能使用它。For you to be able to use an ExpressRoute circuit, it must be in the following state:

ServiceProviderProvisioningState : Provisioned
CircuitProvisioningState         : Enabled

6.定期检查线路密钥的状态6. Periodically check the status and the state of the circuit key

检查线路密钥的状态,可以通过此状态了解提供商何时启用了线路。Checking the status and the state of the circuit key lets you know when your provider has enabled your circuit. 配置线路后,ServiceProviderProvisioningState 将显示为“已预配” ,如以下示例所示:After the circuit has been configured, ServiceProviderProvisioningState appears as Provisioned, as shown in the following example:

Get-AzExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

响应类似于以下示例:The response looks similar to the following example:

Name                             : ExpressRouteARMCircuit
ResourceGroupName                : ExpressRouteResourceGroup
Location                         : chinanorth
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.创建路由配置7. Create your routing configuration

有关分步说明,请参阅 ExpressRoute 线路路由配置一文,了解如何创建和修改线路对等互连。For step-by-step instructions, see the ExpressRoute circuit routing configuration article to create and modify circuit peerings.

Important

这些说明仅适用于由提供第 2 层连接服务的服务提供商创建的线路。These instructions only apply to circuits that are created with service providers that offer layer 2 connectivity services. 如果服务提供商提供第 3 层托管服务(通常是 IP VPN,如 MPLS),则连接服务提供商会配置和管理路由。If you're using a service provider that offers managed layer 3 services (typically an IP VPN, like MPLS), your connectivity provider configures and manages routing for you.

接下来,将虚拟网络链接到 ExpressRoute 线路。Next, link a virtual network to your ExpressRoute circuit. 使用资源管理器部署模式时,请参阅将虚拟网络链接到 ExpressRoute 线路一文。Use the Linking virtual networks to ExpressRoute circuits article when you work with the Resource Manager deployment model.

获取 ExpressRoute 线路的状态Getting the status of an ExpressRoute circuit

可以随时使用 Get-AzExpressRouteCircuit cmdlet 检索此信息。You can retrieve this information at any time by using the Get-AzExpressRouteCircuit cmdlet. 如果调用不带任何参数,则列出所有线路。Making the call with no parameters lists all the circuits.

Get-AzExpressRouteCircuit

其响应类似于如下示例:The response is similar to the following example:

Name                             : ExpressRouteARMCircuit
ResourceGroupName                : ExpressRouteResourceGroup
Location                         : chinanorth
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 线路的信息:You can get information on a specific ExpressRoute circuit by passing the resource group name and circuit name as a parameter to the call:

Get-AzExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

响应类似于以下示例:The response looks similar to the following example:

Name                             : ExpressRouteARMCircuit
ResourceGroupName                : ExpressRouteResourceGroup
Location                         : chinanorth
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                         : []

可以通过运行以下命令获取所有这些参数的详细说明:You can get detailed descriptions of all the parameters by running the following command:

get-help get-azurededicatedcircuit -detailed

修改 ExpressRoute 线路Modifying an ExpressRoute circuit

可以在不影响连接的情况下修改 ExpressRoute 线路的某些属性。You can modify certain properties of an ExpressRoute circuit without impacting connectivity.

可以在不停机的情况下执行以下任务:You can do the following tasks with no downtime:

  • 为 ExpressRoute 线路启用或禁用 ExpressRoute 高级版外接程序。Enable or disable an ExpressRoute premium add-on for your ExpressRoute circuit.
  • 增加 ExpressRoute 线路的带宽,前提是端口上有可用容量。Increase the bandwidth of your ExpressRoute circuit provided there is capacity available on the port. 不支持对线路的带宽进行降级。Downgrading the bandwidth of a circuit is not supported.
  • 将计量套餐从数据流量套餐更改为无限制流量套餐。Change the metering plan from Metered Data to Unlimited Data. 不支持将计量套餐从无限制流量套餐更改为数据流量套餐。Changing the metering plan from Unlimited Data to Metered Data is not supported.
  • 可以启用和禁用允许经典操作 。You can enable and disable Allow Classic Operations.

有关限制和局限性的详细信息,请参阅 ExpressRoute 常见问题解答For more information on limits and limitations, see the ExpressRoute FAQ.

启用 ExpressRoute 高级版外接程序To enable the ExpressRoute premium add-on

可以使用以下 PowerShell 代码段为现有线路启用 ExpressRoute 高级版外接程序:You can enable the ExpressRoute premium add-on for your existing circuit by using the following PowerShell snippet:

$ckt = Get-AzExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

$ckt.Sku.Tier = "Premium"
$ckt.sku.Name = "Premium_MeteredData"

Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt

线路现已启用 ExpressRoute 高级版外接程序功能。The circuit now has the ExpressRoute premium add-on features enabled. 该命令成功运行后,我们就会开始对高级版外接程序功能进行计费。We begin billing you for the premium add-on capability as soon as the command has successfully run.

禁用 ExpressRoute 高级版外接程序To disable the ExpressRoute premium add-on

Important

如果使用的资源超出了标准线路允许的范围,此操作可能会失败。If you're using resources that are greater than what is permitted for the standard circuit, this operation can fail.

请注意以下信息:Note the following information:

  • 从高级版降级到标准版之前,必须确保链接到线路的虚拟网络数少于 10 个。Before you downgrade from premium to standard, you must ensure that the number of virtual networks that are linked to the circuit is less than 10. 否则,更新请求会失败,并且我们将按高级版费率向你收费。If you don't, your update request fails, and we bill you at premium rates.
  • 必须取消其他地理政治区域的所有虚拟网络的链接。You must unlink all virtual networks in other geopolitical regions. 否则,更新请求会失败,并且我们将按高级版费率向你收费。If you don't do this, your update request fails, and we bill you at premium rates.
  • 路由表中专用对等互连的路由必须少于 4,000。Your route table must be less than 4,000 routes for private peering. 如果路由表大小超出 4,000 个路由,则会删除 BGP 会话且不会重新启用它,除非已播发前缀的数目低于 4,000。If your route table size is greater than 4,000 routes, the BGP session drops and won't be reenabled until the number of advertised prefixes goes below 4,000.

可以使用以下 PowerShell cmdlet 为现有线路禁用 ExpressRoute 高级版外接程序:You can disable the ExpressRoute premium add-on for the existing circuit by using the following PowerShell cmdlet:

$ckt = Get-AzExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

$ckt.Sku.Tier = "Standard"
$ckt.sku.Name = "Standard_MeteredData"

Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt

更新 ExpressRoute 线路带宽To update the ExpressRoute circuit bandwidth

有关提供商支持的带宽选项,请查看 ExpressRoute 常见问题解答For supported bandwidth options for your provider, check the ExpressRoute FAQ. 可以选取大于现有线路大小的任何大小。You can pick any size greater than the size of your existing circuit.

Important

如果现有端口上的容量不足,可能需要重新创建 ExpressRoute 线路。You may have to recreate the ExpressRoute circuit if there is inadequate capacity on the existing port. 如果该位置没有额外的可用容量,则不能升级线路。You cannot upgrade the circuit if there is no additional capacity available at that location.

但是,无法在不中断的情况下降低 ExpressRoute 线路的带宽。You cannot reduce the bandwidth of an ExpressRoute circuit without disruption. 带宽降级需要取消对 ExpressRoute 线路的预配,并重新预配新的 ExpressRoute 线路。Downgrading bandwidth requires you to deprovision the ExpressRoute circuit and then reprovision a new ExpressRoute circuit.

确定所需的大小后,可以使用以下命令调整线路的大小:After you decide what size you need, use the following command to resize your circuit:

$ckt = Get-AzExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

$ckt.ServiceProviderProperties.BandwidthInMbps = 1000

Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt

会在 Microsoft 端调整线路的大小。Your circuit will be sized up on the Microsoft side. 然后,必须联系连接提供商,让他们在那一边根据此更改更新配置。Then you must contact your connectivity provider to update configurations on their side to match this change. 在你发出此通知后,我们开始向你计收更新后的带宽选项费用。After you make this notification, we will begin billing you for the updated bandwidth option.

将 SKU 从按流量计费转为不受限制To move the SKU from metered to unlimited

通过使用下面的 PowerShell 代码片段,可以更改 ExpressRoute 线路的 SKU:You can change the SKU of an ExpressRoute circuit by using the following PowerShell snippet:

$ckt = Get-AzExpressRouteCircuit -Name "ExpressRouteARMCircuit" -ResourceGroupName "ExpressRouteResourceGroup"

$ckt.Sku.Family = "UnlimitedData"
$ckt.sku.Name = "Premium_UnlimitedData"

Set-AzExpressRouteCircuit -ExpressRouteCircuit $ckt

控制对经典环境和 Resource Manager 环境的访问To control access to the classic and Resource Manager environments

查看将 ExpressRoute 线路从经典部署模型转移到资源管理器部署模型中的说明。Review the instructions in Move ExpressRoute circuits from the classic to the Resource Manager deployment model.

取消设置和删除 ExpressRoute 线路Deprovisioning and deleting an ExpressRoute circuit

请注意以下信息:Note the following information:

  • 必须取消所有虚拟网络与 ExpressRoute 线路的链接。You must unlink all virtual networks from the ExpressRoute circuit. 如果此操作失败,请查看是否有虚拟网络链接到了该线路。If this operation fails, check to see if any virtual networks are linked to the circuit.
  • 如果 ExpressRoute 线路服务提供商预配状态为“正在预配” 或“已预配” ,则必须与服务提供商合作,在他们一端取消预配线路。If the ExpressRoute circuit service provider provisioning state is Provisioning or Provisioned you must work with your service provider to deprovision the circuit on their side. 在服务提供商取消对线路的预配并通知我们之前,我们会继续保留资源并收费。We continue to reserve resources and bill you until the service provider completes deprovisioning the circuit and notifies us.
  • 如果服务提供商已取消设置线路(服务提供商预配状态设置为“未预配” ),可以删除线路。If the service provider has deprovisioned the circuit (the service provider provisioning state is set to Not provisioned), you can delete the circuit. 这样就会停止对线路的计费。This stops billing for the circuit.

可以通过运行以下命令删除 ExpressRoute 线路:You can delete your ExpressRoute circuit by running the following command:

Remove-AzExpressRouteCircuit -ResourceGroupName "ExpressRouteResourceGroup" -Name "ExpressRouteARMCircuit"

后续步骤Next steps

创建线路后,请务必执行以下后续步骤:After you create your circuit, make sure that you do the following next steps: