使用 Azure 模板将外部终结点添加到现有配置文件

本文介绍如何使用 Azure 资源管理器模板(ARM 模板)将外部终结点添加到现有流量管理器配置文件。

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

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

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

先决条件

查看模板

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

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "existingTMProfileName": {
      "type": "string",
      "metadata": {
        "description": "Name of the traffic manager profile to add a endpoint to"
      }
    },
    "endpointName": {
      "type": "string",
      "metadata": {
        "description": "Name of the endpoint to add to traffic manager profile"
      }
    }
  },
  "variables": {
    "endpointStatus": "Enabled",
    "endpointMonitorStatus": "Degraded",
    "endpointLocation": "chinanorth",
    "target": "www.msn.com",
    "weight": "3",
    "priority": "3"
  },
  "resources": [
    {
            "apiVersion": "2018-04-01",
            "type": "Microsoft.Network/TrafficManagerProfiles/ExternalEndpoints",
            "name": "[concat(parameters('existingTMProfileName'), '/', parameters('endpointName'))]",
            "properties": {
              "endpointStatus": "[variables('endpointStatus')]",
              "endpointLocation": "[variables('endpointLocation')]",
              "endpointMonitorStatus": "[variables('endpointMonitorStatus')]",
              "target": "[variables('target')]",
              "weight": "[variables('weight')]",
              "priority":"[variables('priority')]"
            }
    }
  ]
}

模板中定义了一个 Azure 资源:

若要查找与 Azure 流量管理器相关的更多模板,请参阅 Azure 快速入门模板

部署模板

  1. 选择 Deploy to Azure 以在由世纪互联运营的 Azure 上部署模板。

    部署到 Azure

    注意

    必须修改从 GitHub 存储库“azure-quickstart-templates”下载或参考的模板,以适应由世纪互联运营的 Azure 环境。 例如,替换某些终结点(将“blob.core.windows.net”替换为“blob.core.chinacloudapi.cn”,将“cloudapp.azure.com”替换为“cloudapp.chinacloudapi.cn”);必要时更改某些不受支持的位置、VM 映像、VM 大小、SKU 以及资源提供程序的 API 版本。

    在本文中,请在 Azure 门户中选择“编辑模板”,并将 endpointLocation 的值替换为“变量”属性中的实际中国区域参数,然后选择“保存”按钮。

  2. 输入相应的值。

    模板部署会根据输入将另一个终结点添加到现有配置文件。

    资源组名称是包含现有配置文件的现有资源组。

    注意

    existingTMProfileName 必须与现有配置文件名称匹配才能成功部署模板。 如果部署失败,请从步骤 1 重新开始。

    部署模板需要几分钟时间。 完成后,输出类似于:

    Azure 流量管理器资源管理器模板 PowerShell 部署输出

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

验证部署

  1. 使用 Get-AzTrafficManagerProfile 验证是否向配置文件添加了另一个终结点。

    Get-AzTrafficManagerProfile -ResourceGroupName myResourceGroup -Name ExternalEndpointExample | Select Endpoints
    

    输出类似于:

    验证命令的输出

清理资源

如果不再需要流量管理器配置文件,请删除资源组。 此命令删除流量管理器配置文件和所有相关资源。

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

Remove-AzResourceGroup -Name <your resource group name>

后续步骤

在本快速入门中,你向现有流量管理器配置文件添加了一个终结点。

若要详细了解如何路由流量,请继续学习流量管理器教程。