使用 PowerShell 配置 ExpressRoute 的虚拟网络网关(经典)Configure a virtual network gateway for ExpressRoute using PowerShell (classic)

本文指导你完成为预先存在的 VNet 添加、重设大小和删除虚拟网络 (VNet) 网关的步骤。This article will walk you through the steps to add, resize, and remove a virtual network (VNet) gateway for a pre-existing VNet. 此配置的步骤专用于使用经典部署模型创建的、会在 ExpressRoute 配置中使用的 VNet。The steps for this configuration are specifically for VNets that were created using the classic deployment model and that will be used in an ExpressRoute configuration.

重要

从 2017 年 3 月 1 日开始,将无法在经典部署模型中创建新的 ExpressRoute 线路。As of March 1, 2017, you can't create new ExpressRoute circuits in the classic deployment model.

  • 可以将现有的 ExpressRoute 线路从经典部署模型移到 Resource Manager 部署模型,不会遇到连接中断问题。You can move an existing ExpressRoute circuit from the classic deployment model to the Resource Manager deployment model without experiencing any connectivity down time. 有关详细信息,请参阅移动现有线路For more information, see Move an existing circuit.
  • allowClassicOperations 设置为 TRUE 即可在经典部署模型中连接到虚拟网络。You can connect to virtual networks in the classic deployment model by setting allowClassicOperations to TRUE.

请使用以下链接在 Resource Manager 部署模型中创建和管理 ExpressRoute 线路:Use the following links to create and manage ExpressRoute circuits in the Resource Manager deployment model:

关于 Azure 部署模型About Azure deployment models

Azure 当前使用两种部署模型:Resource Manager 部署模型和经典部署模型。Azure currently works with two deployment models: Resource Manager and classic. 这两个模型相互不完全兼容。The two models are not completely compatible with each other. 在开始之前,需要知道所要使用的模型。Before you begin, you need to know which model that you want to work in. 有关部署模型的信息,请参阅了解部署模型For information about the deployment models, see Understanding deployment models. 如果不熟悉 Azure,建议使用 Resource Manager 部署模型。If you are new to Azure, we recommend that you use the Resource Manager deployment model.

开始之前Before beginning

确认已安装此配置所需的 Azure PowerShell cmdlet。Verify that you have installed the Azure PowerShell cmdlets needed for this configuration.

安装最新版本的 Azure 服务管理 (SM) PowerShell 模块和 ExpressRoute 模块。Install the latest versions of the Azure Service Management (SM) PowerShell modules and the ExpressRoute module.

  1. 按照安装服务管理模块一文中的说明安装 Azure 服务管理模块。Use the instructions in the Installing the Service Management module article to install the Azure Service Management Module. 如果已安装 Az 或 RM 模块,请确保使用“-AllowClobber”。If you have the Az or RM module already installed, be sure to use '-AllowClobber'.

  2. 导入已安装的模块。Import the installed modules. 使用以下示例时,请调整路径以反映已安装的 PowerShell 模块的位置和版本。When using the following example, adjust the path to reflect the location and version of your installed PowerShell modules.

    Import-Module 'C:\Program Files\WindowsPowerShell\Modules\Azure\5.3.0\Azure.psd1'
    Import-Module 'C:\Program Files\WindowsPowerShell\Modules\Azure\5.3.0\ExpressRoute\ExpressRoute.psd1'
    
  3. 若要登录到 Azure 帐户,请使用提升的权限打开 PowerShell 控制台,并连接到帐户。To sign in to your Azure account, open your PowerShell console with elevated rights and connect to your account. 使用以下示例帮助你通过服务管理模块进行连接:Use the following example to help you connect using the Service Management module:

    Add-AzureAccount
    

用户必须先创建 VNet 和网关子网,再处理以下任务。You must create a VNet and a gateway subnet first, before working on the following tasks.

备注

这些示例不适用于 S2S/ExpressRoute 共存配置。These examples do not apply to S2S/ExpressRoute coexist configurations. 有关使用共存配置中的网关的详细信息,请参阅配置共存连接For more information about working with gateways in a coexist configuration, see Configure coexisting connections.

添加网关Add a gateway

向使用经典资源模型的虚拟网络添加网关时,你在创建网关之前直接修改网络配置文件。When you add a gateway to a virtual network using the classic resource model, you modify the network configuration file directly before creating the gateway. 该文件中必须存在以下示例中的值才能创建网关。The values in the examples below must be present in the file to create a gateway. 如果虚拟网络之前有与之关联的网关,则其中某些值已经存在。If your virtual network previously had a gateway associated to it, some of these values will already be present. 请修改文件来反映下面的值。Modify the file to reflect the values below.

下载网络配置文件Download the network configuration file

  1. 使用网络配置文件一文中的步骤下载网络配置文件。Download the network configuration file using the steps in network configuration file article. 使用文本编辑器打开该文件。Open the file using a text editor.

  2. 向该文件中添加一个本地网络站点。Add a local network site to the file. 可以使用任何有效的地址前缀。You can use any valid address prefix. 可以为 VPN 网关添加任何有效的 IP 地址。You can add any valid IP address for the VPN gateway. 此部分中的地址值不用于 ExpressRoute 操作,但是在进行文件验证时需要使用它们。The address values in this section are not used for ExpressRoute operations, but are required for file validation. 在示例中,“branch1”是站点的名称。In the example, "branch1" is the name of the site. 你可以使用其他名称,但一定要在该文件的 Gateway 节中使用同一值。You may use a different name, but be sure to use the same value in the Gateway section of the file.

    <VirtualNetworkConfiguration>
     <Dns />
     <LocalNetworkSites>
       <LocalNetworkSite name="branch1">
         <AddressSpace>
           <AddressPrefix>165.3.1.0/27</AddressPrefix>
         </AddressSpace>
         <VPNGatewayAddress>3.2.1.4</VPNGatewayAddress>
     </LocalNetworkSite>
    
  3. 导航到 VirtualNetworkSites 并修改字段。Navigate to the VirtualNetworkSites and modify the fields.

    • 验证你的虚拟网络是否存在网关子网。Verify that the Gateway Subnet exists for your virtual network. 如果不存在,此时可以添加一个。If it does not, you can add one at this time. 该名称必须是“GatewaySubnet”。The name must be "GatewaySubnet".
    • 验证文件的 Gateway 节是否存在。Verify the Gateway section of the file exists. 如果不存在,请添加该节。If it doesn't, add it. 这是将虚拟网络与本地网络站点(它表示你要连接到的网络)进行关联所必需的。This is required to associate the virtual network with the local network site (which represents the network to which you are connecting).
    • 验证 connection type = Dedicated。Verify that the connection type = Dedicated. 对于 ExpressRoute 连接,这是必需的。This is required for ExpressRoute connections.
    </LocalNetworkSites>
     <VirtualNetworkSites>
       <VirtualNetworkSite name="myAzureVNET" Location="East US">
         <AddressSpace>
           <AddressPrefix>10.0.0.0/16</AddressPrefix>
         </AddressSpace>
         <Subnets>
           <Subnet name="default">
             <AddressPrefix>10.0.0.0/24</AddressPrefix>
           </Subnet>
           <Subnet name="GatewaySubnet">
             <AddressPrefix>10.0.1.0/27</AddressPrefix>
           </Subnet>
         </Subnets>
         <Gateway>
           <ConnectionsToLocalNetwork>
             <LocalNetworkSiteRef name="branch1">
               <Connection type="Dedicated" />
             </LocalNetworkSiteRef>
           </ConnectionsToLocalNetwork>
         </Gateway>
       </VirtualNetworkSite>
     </VirtualNetworkSites>
    </VirtualNetworkConfiguration>
    </NetworkConfiguration>
    
  4. 保存文件并将其上传到 Azure。Save the file and upload it to Azure.

创建网关Create the gateway

使用以下命令可创建网关。Use the command below to create a gateway. 将所有值替换成你自己的值。Substitute any values for your own.

New-AzureVNetGateway -VNetName "MyAzureVNET" -GatewayType DynamicRouting -GatewaySKU  Standard

验证是否已创建网关Verify the gateway was created

使用以下命令来验证是否已创建网关。Use the command below to verify that the gateway has been created. 此命令还会检索执行其他操作所需的网关 ID。This command also retrieves the gateway ID, which you need for other operations.

Get-AzureVNetGateway

重设网关大小Resize a gateway

有许多网关 SKUThere are a number of Gateway SKUs. 可以使用以下命令随时更改网关 SKU。You can use the following command to change the Gateway SKU at any time.

重要

此命令对 UltraPerformance 网关不起作用。This command doesn't work for UltraPerformance gateway. 要将网关更改为 UltraPerformance 网关,首先要删除现有的 ExpressRoute 网关,然后创建新的 UltraPerformance 网关。To change your gateway to an UltraPerformance gateway, first remove the existing ExpressRoute gateway, and then create a new UltraPerformance gateway. 要将网关从 UltraPerformance 网关降级,首先要删除 UltraPerformance 网关,然后创建新网关。To downgrade your gateway from an UltraPerformance gateway, first remove the UltraPerformance gateway, and then create a new gateway.

Resize-AzureVNetGateway -GatewayId <Gateway ID> -GatewaySKU HighPerformance

删除网关Remove a gateway

使用以下命令可删除网关Use the command below to remove a gateway

Remove-AzureVnetGateway -GatewayId <Gateway ID>

后续步骤Next steps

创建 VPN 网关之后,可以将 VNet 链接到 ExpressRoute 线路。After you have created the VPN Gateway, you can link your VNet to an ExpressRoute circuit. 请参阅将虚拟网络链接到 ExpressRoute 线路See Link a Virtual Network to an ExpressRoute circuit.