快速入门:使用 ARM 模板创建具有专用对等互连的 ExpressRoute 线路Quickstart: Create an ExpressRoute circuit with private peering using an ARM template

本快速入门介绍如何使用 Azure 资源管理器模板(ARM 模板)来创建具有专用对等互连的 ExpressRoute 线路。This quickstart describes how to use an Azure Resource Manager template (ARM Template) to create an ExpressRoute circuit with private peering.

ARM 模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. 该模板使用声明性语法,使你可以声明要部署的内容,而不需要编写一系列编程命令来进行创建。The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

如果你的环境满足先决条件,并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮。If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. Azure 门户中会打开模板。The template will open in the Azure portal.

部署到 AzureDeploy to Azure

先决条件Prerequisites

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

查看模板Review the template

本快速入门中使用的模板来自 Azure 快速启动模板The template used in this quickstart is from Azure Quickstart Templates.

在本快速入门中,你将创建一个以 Equinix 为服务提供商的 ExpressRoute 线路。In this quickstart, you'll create an ExpressRoute circuit with Equinix as the service provider. 该线路将使用高级 SKU,其带宽为 50 Mbps,对等互连位置为华盛顿特区 。The circuit will be using a Premium SKU, with a bandwidth of 50 Mbps, and the peering location of Washington DC. 将使用主要子网 192.168.10.16/30 和辅助子网 192.168.10.20/30 来启用专用对等互连 。Private peering will be enabled with a primary and secondary subnet of 192.168.10.16/30 and 192.168.10.20/30 respectively. 还将创建虚拟网络以及 HighPerformance ExpressRoute 网关。A virtual network will also be created along with a HighPerformance ExpressRoute gateway.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources deployed in the ARM template"
      }
    },
    "erpeeringLocation": {
      "type": "string",
      "defaultValue": "Shanghai",
      "metadata": {
        "description": "ExpressRoute peering location"
      }
    },
    "erCircuitName": {
      "type": "string",
      "defaultValue": "er-ckt01",
      "metadata": {
        "description": "Name of the ExpressRoute circuit"
      }
    },
    "serviceProviderName": {
      "type": "string",
      "defaultValue": "Shanghai Telecom Ethernet",
      "metadata": {
        "description": "Name of the ExpressRoute provider"
      }
    },
    "erSKU_Tier": {
      "type": "string",
      "defaultValue": "Premium",
      "allowedValues": [
        "Premium",
        "Standard"
      ],
      "metadata": {
        "description": "Tier ExpressRoute circuit"
      }
    },
    "erSKU_Family": {
      "type": "string",
      "defaultValue": "MeteredData",
      "allowedValues": [
        "MeteredData",
        "UnlimitedData"
      ],
      "metadata": {
        "description": "Billing model ExpressRoute circuit"
      }
    },
    "bandwidthInMbps": {
      "type": "int",
      "defaultValue": 50,
      "allowedValues": [
        50,
        100,
        200,
        500,
        1000,
        2000,
        5000,
        10000
      ],
      "metadata": {
        "description": "Bandwidth ExpressRoute circuit"
      }
    },
    "peerASN": {
      "type": "int",
      "defaultValue": 65001,
      "metadata": {
        "description": "autonomous system number used to create private peering between the customer edge router and MSEE routers"
      }
    },
    "primaryPeerAddressPrefix": {
      "type": "string",
      "defaultValue": "192.168.10.16/30",
      "metadata": {
        "description": "point-to-point network prefix of primary link between the customer edge router and MSEE router"
      }
    },
    "secondaryPeerAddressPrefix": {
      "type": "string",
      "defaultValue": "192.168.10.20/30",
      "metadata": {
        "description": "point-to-point network prefix of secondary link between the customer edge router and MSEE router"
      }
    },
    "vlanId": {
      "type": "int",
      "defaultValue": 100,
      "metadata": {
        "description": "VLAN Id used between the customer edge routers and MSEE routers. primary and secondary link have the same VLAN Id"
      }
    },
    "vnetName": {
      "type": "string",
      "defaultValue": "vnet1",
      "metadata": {
        "description": "name of the Virtual Network"
      }
    },
    "subnet1Name": {
      "type": "string",
      "defaultValue": "subnet1",
      "metadata": {
        "description": "name of the subnet"
      }
    },
    "vnetAddressSpace": {
      "type": "string",
      "defaultValue": "10.10.10.0/24",
      "metadata": {
        "description": "address space assigned to the Virtual Network"
      }
    },
    "subnet1Prefix": {
      "type": "string",
      "defaultValue": "10.10.10.0/25",
      "metadata": {
        "description": "network prefix assigned to the subnet"
      }
    },
    "gatewaySubnetPrefix": {
      "type": "string",
      "defaultValue": "10.10.10.224/27",
      "metadata": {
        "description": "network prefixes assigned to the gateway subnet. It has to be a network prefix with mask /27 or larger"
      }
    },
    "gatewayName": {
      "type": "string",
      "defaultValue": "er-gw",
      "metadata": {
        "description": "name of the ExpressRoute Gateway"
      }
    },
    "gatewaySku": {
      "type": "string",
      "defaultValue": "HighPerformance",
      "allowedValues": [
        "Standard",
        "HighPerformance",
        "UltraPerformance",
        "ErGw1AZ",
        "ErGw2AZ",
        "ErGw3AZ"
      ],
      "metadata": {
        "description": "ExpressRoute Gateway SKU"
      }
    }
  },
  "variables": {
    "location": "[parameters('location')]",
    "erlocation": "[parameters('location')]",
    "erCircuitName": "[parameters('erCircuitName')]",
    "serviceProviderName": "[parameters('serviceProviderName')]",
    "erpeeringLocation": "[parameters('erpeeringLocation')]",
    "erSKU_Tier": "[parameters('erSKU_Tier')]",
    "erSKU_Family": "[parameters('erSKU_Family')]",
    "erSKU_Name": "[concat(variables('erSKU_Tier'),'_',variables('erSKU_Family'))]",
    "bandwidthInMbps": "[parameters('bandwidthInMbps')]",
    "peerASN": "[parameters('peerASN')]",
    "primaryPeerAddressPrefix": "[parameters('primaryPeerAddressPrefix')]",
    "secondaryPeerAddressPrefix": "[parameters('secondaryPeerAddressPrefix')]",
    "vlanId": "[parameters('vlanId')]",
    "vnetName": "[parameters('vnetName')]",
    "subnet1Name": "[parameters('subnet1Name')]",
    "vnetAddressSpace": "[parameters('vnetAddressSpace')]",
    "subnet1Prefix": "[parameters('subnet1Prefix')]",
    "gatewaySubnetPrefix": "[parameters('gatewaySubnetPrefix')]",
    "gatewayName": "[parameters('gatewayName')]",
    "gatewayPublicIPName": "[concat(variables('gatewayName'),'-pubIP')]",
    "gatewaySku": "[parameters('gatewaySku')]",
    "nsg": "nsg"
  },
  "resources": [
    {
      "comments": "Create the ER circuit",
      "type": "Microsoft.Network/expressRouteCircuits",
      "apiVersion": "2020-06-01",
      "name": "[variables('erCircuitName')]",
      "location": "[variables('erlocation')]",
      "sku": {
        "name": "[variables('erSKU_Name')]",
        "tier": "[variables('erSKU_Tier')]",
        "family": "[variables('erSKU_Family')]"
      },
      "properties": {
        "serviceProviderProperties": {
          "serviceProviderName": "[variables('serviceProviderName')]",
          "peeringLocation": "[variables('erpeeringLocation')]",
          "bandwidthInMbps": "[variables('bandwidthInMbps')]"
        },
        "allowClassicOperations": false
      }
    },
    {
      "comments": "Create ER private peering",
      "type": "Microsoft.Network/expressRouteCircuits/peerings",
      "apiVersion": "2020-06-01",
      "name": "[concat(variables('erCircuitName'),'/','AzurePrivatePeering')]",
      "location": "[variables('erlocation')]",
      "dependsOn": [
        "[resourceId('Microsoft.Network/expressRouteCircuits', variables('erCircuitName'))]"
      ],
      "properties": {
        "peeringType": "AzurePrivatePeering",
        "peerASN": "[variables('peerASN')]",
        "primaryPeerAddressPrefix": "[variables('primaryPeerAddressPrefix')]",
        "secondaryPeerAddressPrefix": "[variables('secondaryPeerAddressPrefix')]",
        "vlanId": "[variables('vlanId')]"
      }
    },
    {
      "comments": "NSG applied to the subnets in VNet1",
      "type": "Microsoft.Network/networkSecurityGroups",
      "apiVersion": "2020-06-01",
      "name": "[variables('nsg')]",
      "location": "[variables('location')]",
      "properties": {
        "securityRules": [
          {
            "name": "SSH-rule",
            "properties": {
              "description": "allow SSH",
              "protocol": "Tcp",
              "sourcePortRange": "*",
              "destinationPortRange": "22",
              "sourceAddressPrefix": "*",
              "destinationAddressPrefix": "VirtualNetwork",
              "access": "Allow",
              "priority": 500,
              "direction": "Inbound"
            }
          },
          {
            "name": "RDP-rule",
            "properties": {
              "description": "allow RDP",
              "protocol": "Tcp",
              "sourcePortRange": "*",
              "destinationPortRange": "3389",
              "sourceAddressPrefix": "*",
              "destinationAddressPrefix": "VirtualNetwork",
              "access": "Allow",
              "priority": 600,
              "direction": "Inbound"
            }
          }
        ]
      }
    },
    {
      "comments": "it builds a Virtual Network with GatewaySubnet",
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2020-06-01",
      "name": "[variables('vnetName')]",
      "location": "[variables('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsg'))]"
      ],
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[variables('vnetAddressSpace')]"
          ]
        },
        "subnets": [
          {
            "name": "[variables('subnet1Name')]",
            "properties": {
              "addressPrefix": "[variables('subnet1Prefix')]",
              "networkSecurityGroup": {
                "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsg'))]"
              }
            }
          },
          {
            "name": "GatewaySubnet",
            "properties": {
              "addressPrefix": "[variables('gatewaySubnetPrefix')]"
            }
          }
        ]
      }
    },
    {
      "comments": "public IP of the ExpressRoute Gateway. Only public IP Dynamic allocation is supported",
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2020-06-01",
      "name": "[variables('gatewayPublicIPName')]",
      "location": "[variables('location')]",
      "properties": {
        "publicIPAllocationMethod": "Dynamic"
      }
    },
    {
      "comments": "ExpressRoute Gateway in the GatewaySubnet",
      "type": "Microsoft.Network/virtualNetworkGateways",
      "apiVersion": "2020-06-01",
      "name": "[variables('gatewayName')]",
      "location": "[variables('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Network/publicIPAddresses', variables('gatewayPublicIPName'))]",
        "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
      ],
      "properties": {
        "ipConfigurations": [
          {
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "subnet": {
                "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vnetName'), 'GatewaySubnet')]"
              },
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('gatewayPublicIPName'))]"
              }
            },
            "name": "gwIPconf"
          }
        ],
        "gatewayType": "ExpressRoute",
        "sku": {
          "name": "[variables('gatewaySku')]",
          "tier": "[variables('gatewaySku')]"
        },
        "vpnType": "RouteBased"
      }
    }
  ],
  "outputs": {
    "erCircuitName": {
      "type": "string",
      "value": "[variables('erCircuitName')]"
    },
    "gatewayName": {
      "type": "string",
      "value": "[variables('gatewayName')]"
    },
    "gatewaySku": {
      "type": "string",
      "value": "[variables('gatewaySku')]"
    }
  }
}

该模板中已定义了多个 Azure 资源:Multiple Azure resources have been defined in the template:

若要查找与 ExpressRoute 相关的更多模板,请参阅 Azure 快速启动模板To find more templates that are related to ExpressRoute, see Azure Quickstart Templates.

部署模板Deploy the template

  1. 按照说明登录到 Azure。Follow the instructions to sign in to Azure.

    $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
    $location = Read-Host -Prompt "Enter the location"
    $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-expressroute-private-peering-vnet/azuredeploy.json"
    
    $resourceGroupName = "${projectName}rg"
    
    New-AzResourceGroup -Name $resourceGroupName -Location "$location"
    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri
    
    Read-Host -Prompt "Press [ENTER] to continue ..."
    

    等到控制台中显示提示。Wait until you see the prompt from the console.

  2. 从上一个代码块中选择“复制”,以复制 PowerShell 脚本。Select Copy from the previous code block to copy the PowerShell script.

  3. 右键单击 shell 控制台窗格,然后选择“粘贴”。Right-click the shell console pane and then select Paste.

  4. 输入相应的值。Enter the values.

    资源组名称是追加了 rg 的项目名称。The resource group name is the project name with rg appended.

    部署模板大约需要 20 分钟。It takes about 20 minutes to deploy the template. 完成后,输出类似于:When completed, the output is similar to:

    ExpressRoute 资源管理器模板 PowerShell 部署输出

使用 Azure PowerShell 部署模板。Azure PowerShell is used to deploy the template. 除了 Azure PowerShell,还可以使用 Azure 门户、Azure CLI 和 REST API。In addition to Azure PowerShell, you can also use the Azure portal, Azure CLI, and REST API. 若要了解其他部署方法,请参阅部署模板To learn other deployment methods, see Deploy templates.

验证部署Validate the deployment

  1. 登录 Azure 门户Sign in to the Azure portal.

  2. 从左侧窗格中选择“资源组”。Select Resource groups from the left pane.

  3. 选择你在上一部分中创建的资源组。Select the resource group that you created in the previous section. 默认资源组名称是追加了 rg 的项目名称。The default resource group name is the project name with rg appended.

  4. 资源组应包含以下资源:The resource group should contain the following resources seen here:

    ExpressRoute 部署资源组

  5. 选择 ExpressRoute 线路 er-ck01 来验证线路状态是否为“已启用”,提供程序状态是否为“未预配”,专用对等互连的状态是否为“已预配” 。Select the ExpressRoute circuit er-ck01 to verify that the circuit status is Enabled, provider status is Not provisioned and private peering has the status of Provisioned.

    ExpressRoute 部署线路

备注

你将需要调用提供程序来完成预配过程,然后才能将虚拟网络链接到线路。You will need to call the provider to complete the provisioning process before you can link the virtual network to the circuit.

清理资源Clean up resources

如果不再需要通过 ExpressRoute 线路创建的资源,请删除该资源组。When you no longer need the resources that you created with the ExpressRoute circuit, delete the resource group. 这会删除 ExpressRoute 线路和所有相关资源。This removes the ExpressRoute circuit and all the related resources.

若要删除资源组,请调用 Remove-AzResourceGroup cmdlet:To delete the resource group, call the Remove-AzResourceGroup cmdlet:

Remove-AzResourceGroup -Name <your resource group name>

后续步骤Next steps

在本快速入门中,我们创建了:In this quickstart, you created a:

  • ExpressRoute 线路ExpressRoute circuit
  • 虚拟网络Virtual Network
  • VPN 网关VPN Gateway
  • 公共 IPPublic IP
  • 网络安全组network security groups

若要了解如何将虚拟网络链接到线路,请继续学习 ExpressRoute 教程。To learn how to link a virtual network to a circuit, continue to the ExpressRoute tutorials.