Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
本快速入门介绍如何使用 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",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.25.53.49325",
"templateHash": "17662726020644193974"
}
},
"parameters": {
"uniqueDnsName": {
"type": "string",
"metadata": {
"description": "Relative DNS name for the traffic manager profile, must be globally unique."
}
}
},
"resources": [
{
"type": "Microsoft.Network/trafficmanagerprofiles",
"apiVersion": "2022-04-01",
"name": "ExternalEndpointExample",
"location": "global",
"properties": {
"profileStatus": "Enabled",
"trafficRoutingMethod": "Performance",
"dnsConfig": {
"relativeName": "[parameters('uniqueDnsName')]",
"ttl": 30
},
"monitorConfig": {
"protocol": "HTTPS",
"port": 443,
"path": "/",
"expectedStatusCodeRanges": [
{
"min": 200,
"max": 202
},
{
"min": 301,
"max": 302
}
]
},
"endpoints": [
{
"type": "Microsoft.Network/TrafficManagerProfiles/ExternalEndpoints",
"name": "endpoint1",
"properties": {
"target": "www.microsoft.com",
"endpointStatus": "Enabled",
"endpointLocation": "chinaeast2"
}
},
{
"type": "Microsoft.Network/TrafficManagerProfiles/ExternalEndpoints",
"name": "endpoint2",
"properties": {
"target": "docs.microsoft.com",
"endpointStatus": "Enabled",
"endpointLocation": "chinaeast"
}
}
]
}
}
],
"outputs": {
"name": {
"type": "string",
"value": "ExternalEndpointExample"
},
"resourceGroupName": {
"type": "string",
"value": "[resourceGroup().name]"
},
"resourceId": {
"type": "string",
"value": "[resourceId('Microsoft.Network/trafficmanagerprofiles', 'ExternalEndpointExample')]"
}
}
}
模板中定义了一个 Azure 资源:
若要查找与 Azure 流量管理器相关的更多模板,请参阅 Azure 快速入门模板。
以管理员权限打开本地 PowerShell 控制台,并运行以下脚本。
Connect-AzAccount -Environment AzureChinaCloud $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names" $location = Read-Host -Prompt "Enter the location (i.e. chinaeast)" $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.network/traffic-manager-external-endpoint/azuredeploy.json" $resourceGroupName = "${projectName}rg" New-AzResourceGroup -Name $resourceGroupName -Location "$location" New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri Read-Host -Prompt "Press [ENTER] to continue ..."
等到控制台中显示提示。
Nota
当我们使用以
https://raw.githubusercontent.com/
开头的指定模板文件 URI 部署资源时,控制台有时会生成错误,如Unable to download deployment content
。可以执行以下操作来解决相应问题。
复制模板 URI,通过更改前缀、中缀和模板文件名来转换 URI。 例如,源 URI 是
https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-cosmosdb-sql-autoscale/azuredeploy.json
类别 原始值 转换后的值 操作 前缀 https://raw.githubusercontent.com
https://github.com
更新 中辍 blob
在 master
或main
之前添加分支名称模板文件名 azuredeploy.json 你的下载模板文件名 update 修改后,转换后的 URI 看起来将类似于
https://github.com/Azure/azure-quickstart-templates/blob/master/101-cosmosdb-sql-autoscale/azuredeploy.json
。请注意,某些模板 URI 已更新为 https://github.com/Azure/azure-quickstart-template/quickstarts/{Microsoft_Resource_Provider_Name}/ ,你可以按照相应的路径规定来更新原始 URI。
复制转换后的 URI,并在 Internet 浏览器中手动下载特定的模板内容。
修改从 GitHub 存储库下载或引用的模板,以适应 Azure 中国世纪互联环境。 例如,替换某些终结点(将“blob.core.windows.net”替换为“blob.core.chinacloudapi.cn”,将“cloudapp.azure.com”替换为“chinacloudapp.cn”);必要时更改某些不受支持的位置、VM 映像、VM 大小、SKU 以及资源提供程序的 API 版本。
将参数
-TemplateUri
替换为-TemplateFile
(对于 powershell)或将参数--template-uri
替换为--template-file
(针对 CLI),然后用已下载的实际文件名称更新指定的 URI,然后重新运行脚本。语言类别 参考链接 操作 PowerShell New-AzResourceGroupDeployment
将 -TemplateUri
替换为-TemplateFile
如有必要,请按照前面的步骤下载-TemplateParameterUri
内容并在 cmdlet 中替换为-TemplateParameterFile
。Azure CLI az deployment group create
将 --template-uri
替换为--template-file
从上一个代码块中选择“复制”,以复制 PowerShell 脚本。
右键单击 shell 控制台窗格,然后选择“粘贴”。
输入相应的值。
模板部署将创建包含两个外部终结点的配置文件。 Endpoint1 使用位于“中国北部”的目标终结点
www.microsoft.com
。 Endpoint2 使用位于“中国东部”的目标终结点learn.microsoft.com
。资源组名称是追加了 rg 的项目名称。
Nota
“uniqueDNSname”需要是全局唯一名称,才能成功部署模板。 如果部署失败,请从步骤 1 重新开始。
部署模板需要几分钟时间。 完成后,输出类似于:
使用 Azure PowerShell 部署模板。 除了 Azure PowerShell,还可以使用 Azure 门户、Azure CLI 和 REST API。 若要了解其他部署方法,请参阅部署模板。
使用 Get-AzTrafficManagerProfile 确定流量管理器配置文件的 DNS 名称。
Get-AzTrafficManagerProfile -Name ExternalEndpointExample -ResourceGroupName $resourceGroupName | Select RelativeDnsName
复制 RelativeDnsName 值。 流量管理器配置文件的 DNS 名称为
<relativednsname>.trafficmanager.cn
。在本地 PowerShell 中,运行以下命令,将 {relativeDNSname} 变量替换为
<relativednsname>.trafficmanager.cn
。Resolve-DnsName -Name {relativeDNSname} | Select-Object NameHost | Select -First 1
你应该获得的 NameHost 为
www.microsoft.com
或learn.microsoft.com
,具体取决于哪个区域离你更近。若要检查是否可以解析为其他终结点,请禁用在上一步中获得的目标的终结点。 将 {endpointName} 替换为 endpoint1 或 endpoint2,分别禁用
www.microsoft.com
或learn.microsoft.com
的目标 。Disable-AzTrafficManagerEndpoint -Name {endpointName} -Type ExternalEndpoints -ProfileName ExternalEndpointExample -ResourceGroupName $resourceGroupName -Force
在本地 PowerShell 中再次运行步骤 2 中的命令。 这一次你应该获得其他终结点的其他 NameHost。
如果不再需要流量管理器配置文件,请删除资源组。 这会删除流量管理器配置文件和所有相关资源。
若要删除资源组,请调用 Remove-AzResourceGroup
cmdlet:
Remove-AzResourceGroup -Name <your resource group name>
本快速入门介绍了如何创建流量管理器配置文件,
若要详细了解如何路由流量,请继续学习流量管理器教程。