快速入门:使用 ARM 模板创建 Azure 路由服务器

本快速入门帮助你了解如何使用 Azure 资源管理器模板(ARM 模板)将 Azure 路由服务器部署到新的或现有的虚拟网络中。

资源管理器模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。 模板使用声明性语法。 在声明性语法中,你可以在不编写创建部署的编程命令序列的情况下,描述预期部署。

如果环境满足先决条件并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮以在 Azure 门户中打开模板。

用于将资源管理器模板部署到 Azure 的按钮。

先决条件

查看模板

本快速入门中使用的模板来自 Azure 快速启动模板

借助此模版,你可以将 Azure 路由服务器部署到新的或现有的虚拟网络中。 系统会创建一个名为 RouteServerSubnet 的专用子网,用于托管路由服务器。 路由服务器还将配置为使用对等 ASN 和对等 IP 以建立 BGP 对等互连。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.5.6.12127",
      "templateHash": "3572840517141664306"
    }
  },
  "parameters": {
    "vnetName": {
      "type": "string",
      "defaultValue": "routeservervnet",
      "metadata": {
        "description": "Name of new or existing vnet to which Azure Route Server should be deployed."
      }
    },
    "vnetIpPrefix": {
      "type": "string",
      "defaultValue": "10.1.0.0/16",
      "metadata": {
        "description": "IP prefix for available addresses in vnet address space."
      }
    },
    "vnetNew_or_Existing": {
      "type": "string",
      "defaultValue": "New",
      "allowedValues": [
        "New",
        "Existing"
      ],
      "metadata": {
        "description": "Specify whether to provision new vnet or deploy to existing vnet."
      }
    },
    "routeServerSubnetIpPrefix": {
      "type": "string",
      "defaultValue": "10.1.1.0/27",
      "metadata": {
        "description": "Route Server subnet IP prefix MUST be within vnet IP prefix address space."
      }
    },
    "publicIpNew_or_Existing": {
      "type": "string",
      "defaultValue": "New",
      "allowedValues": [
        "New",
        "Existing"
      ],
      "metadata": {
        "description": "Specify whether to provision new standard public IP or deploy using existing standard public IP."
      }
    },
    "publicIpName": {
      "type": "string",
      "defaultValue": "routeserverpip",
      "metadata": {
        "description": "Name of the standard Public IP used for the Route Server"
      }
    },
    "firstRouteServerName": {
      "type": "string",
      "defaultValue": "routeserver",
      "metadata": {
        "description": "Name of Route Server."
      }
    },
    "routeServerBgpConnectionName": {
      "type": "string",
      "defaultValue": "conn1",
      "metadata": {
        "description": "Name of BGP connection."
      }
    },
    "peerAsn": {
      "type": "int",
      "defaultValue": 65002,
      "metadata": {
        "description": "Peer ASN connecting to."
      }
    },
    "peerIp": {
      "type": "string",
      "defaultValue": "10.0.1.4",
      "metadata": {
        "description": "Peer IP connecting to."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Azure region for Route Server and virtual network."
      }
    }
  },
  "variables": {
    "ipconfigName": "ipconfig1",
    "routeServerSubnetName": "RouteServerSubnet"
  },
  "resources": [
    {
      "condition": "[equals(parameters('vnetNew_or_Existing'), 'New')]",
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2020-05-01",
      "name": "[parameters('vnetName')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('vnetIpPrefix')]"
          ]
        }
      }
    },
    {
      "type": "Microsoft.Network/virtualNetworks/subnets",
      "apiVersion": "2020-05-01",
      "name": "[format('{0}/{1}', parameters('vnetName'), variables('routeServerSubnetName'))]",
      "properties": {
        "addressPrefix": "[parameters('routeServerSubnetIpPrefix')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
      ]
    },
    {
      "condition": "[equals(parameters('publicIpNew_or_Existing'), 'New')]",
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2020-05-01",
      "name": "[parameters('publicIpName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard"
      },
      "properties": {
        "publicIPAllocationMethod": "Static",
        "publicIPAddressVersion": "IPv4",
        "idleTimeoutInMinutes": 4
      }
    },
    {
      "type": "Microsoft.Network/virtualHubs",
      "apiVersion": "2020-06-01",
      "name": "[parameters('firstRouteServerName')]",
      "location": "[parameters('location')]",
      "properties": {
        "sku": "Standard"
      }
    },
    {
      "type": "Microsoft.Network/virtualHubs/ipConfigurations",
      "apiVersion": "2020-06-01",
      "name": "[format('{0}/{1}', parameters('firstRouteServerName'), variables('ipconfigName'))]",
      "properties": {
        "subnet": {
          "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), variables('routeServerSubnetName'))]"
        },
        "publicIPAddress": {
          "id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpName'))]"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/virtualHubs', parameters('firstRouteServerName'))]",
        "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpName'))]",
        "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), variables('routeServerSubnetName'))]"
      ]
    },
    {
      "type": "Microsoft.Network/virtualHubs/bgpConnections",
      "apiVersion": "2020-06-01",
      "name": "[format('{0}/{1}', parameters('firstRouteServerName'), parameters('routeServerBgpConnectionName'))]",
      "properties": {
        "peerAsn": "[parameters('peerAsn')]",
        "peerIp": "[parameters('peerIp')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Network/virtualHubs', parameters('firstRouteServerName'))]",
        "[resourceId('Microsoft.Network/virtualHubs/ipConfigurations', parameters('firstRouteServerName'), variables('ipconfigName'))]"
      ]
    }
  ]
}

该模板中已定义了多个 Azure 资源:

若要查找更多模板,请参阅 Azure 快速入门模板

部署模板

  1. 打开本地 PowerShell,然后运行 Connect-AzAccount -Environment AzureChinaCloud 以创建与 Azure 的连接。

  2. 从以下代码块中选择“复制”以复制 PowerShell 脚本。

    $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
    $location = Read-Host -Prompt "Enter the location (i.e. chinanorth3)"
    $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.network/route-server/azuredeploy.json"
    
    $resourceGroupName = "${projectName}rg"
    
    New-AzResourceGroup -Name $resourceGroupName -Location "$location"
    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri
    
    Read-Host -Prompt "Press [ENTER] to continue ..."
    
  3. 右键单击 shell 控制台窗格,然后选择“粘贴”

  4. 输入相应的值。

    资源组名称是追加了 rg 的项目名称。

    部署模板大约需要 20 分钟。 完成后,输出类似于:

    路由服务器资源管理器模板 PowerShell 部署输出。

使用 Azure PowerShell 部署模板。 除了 Azure PowerShell,还可以使用 Azure 门户、Azure CLI 和 REST API。 若要了解其他部署方法,请参阅部署模板

验证部署

  1. 登录 Azure 门户

  2. 从左侧窗格中选择“资源组”。

  3. 选择你在上一部分中创建的资源组。 默认资源组名称是追加了 rg 的项目名称。

  4. 资源组应只包含虚拟网络:

    通过虚拟网络的路由服务器部署资源组。

  5. 转到 https://portal.azure.cn/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.Network%2FvirtualHubs/kind/RouteServer

  6. 选择名为 routeserver 的路由服务器,以验证是否成功部署。

    路由服务器“概述”页的屏幕截图。

清理资源

如果不再需要使用路由服务器创建的资源,请删除资源组以删除路由服务器和所有相关资源。

若要删除资源组,请调用 Remove-AzResourceGroup cmdlet:

Remove-AzResourceGroup -Name <your resource group name>

后续步骤

在本快速入门中,我们创建了:

  • 虚拟网络
  • 子网
  • 路由服务器

在创建 Azure 路由服务器后,请继续了解 Azure 路由服务器如何与 ExpressRoute 和 VPN 网关进行交互: