本快速入门介绍如何使用 Azure 资源管理器模板(ARM 模板)来创建 DNS 区域以及其中的 A
记录。
Azure 资源管理器模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。 模板使用声明性语法。 你可以在不编写用于创建部署的编程命令序列的情况下,描述预期部署。
如果你的环境满足先决条件,并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮。 Azure 门户中会打开模板。
如果没有 Azure 订阅,可在开始前创建一个试用帐户。
本快速入门中使用的模板来自 Azure 快速启动模板。
本快速入门将使用后缀 azurequickstart.org
创建唯一的 DNS 区域。 指向两个 IP 地址的 A
记录也将放置在该区域中。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.8.9.13224",
"templateHash": "3207741835848035910"
}
},
"parameters": {
"zoneName": {
"type": "string",
"defaultValue": "[format('{0}.azurequickstart.org', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "The name of the DNS zone to be created. Must have at least 2 segments, e.g. hostname.org"
}
},
"recordName": {
"type": "string",
"defaultValue": "www",
"metadata": {
"description": "The name of the DNS record to be created. The name is relative to the zone, not the FQDN."
}
}
},
"resources": [
{
"type": "Microsoft.Network/dnsZones",
"apiVersion": "2018-05-01",
"name": "[parameters('zoneName')]",
"location": "global"
},
{
"type": "Microsoft.Network/dnsZones/A",
"apiVersion": "2018-05-01",
"name": "[format('{0}/{1}', parameters('zoneName'), parameters('recordName'))]",
"properties": {
"TTL": 3600,
"ARecords": [
{
"ipv4Address": "1.2.3.4"
},
{
"ipv4Address": "1.2.3.5"
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/dnsZones', parameters('zoneName'))]"
]
}
],
"outputs": {
"nameServers": {
"type": "array",
"value": "[reference(resourceId('Microsoft.Network/dnsZones', parameters('zoneName'))).nameServers]"
}
}
}
该模板中已定义了两个 Azure 资源:
- Microsoft.Network/dnsZones
- Microsoft.Network/dnsZones/A:用于在区域中创建
A
记录。
按照说明登录到 Azure。
$projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names" $location = Read-Host -Prompt "Enter the location (i.e. chinaeast2)" $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.network/azure-dns-new-zone/azuredeploy.json" $resourceGroupName = "${projectName}rg" New-AzResourceGroup -Name $resourceGroupName -Location "$location" New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri Read-Host -Prompt "Press [ENTER] to continue ..."
等到控制台中显示提示。
从上一个代码块中选择“复制”,以复制 PowerShell 脚本。
右键单击 shell 控制台窗格,然后选择“粘贴”。
输入相应的值。
模板部署使用指向两个 IP 地址的
A
记录创建一个区域。 资源组名称是追加了rg
的项目名称。部署模板需要几秒钟时间。 完成后,输出类似于:
使用 Azure PowerShell 部署模板。 除了 Azure PowerShell,还可以使用 Azure 门户、Azure CLI 和 REST API。 若要了解其他部署方法,请参阅部署模板。
登录 Azure 门户。
从左侧窗格中选择“资源组”。
选择你在上一部分中创建的资源组。 默认资源组名称是追加了
rg
的项目名称。资源组应包含以下资源:
选择带有后缀
azurequickstart.org
的 DNS 区域,验证该区域是否使用引用值203.0.113.1
和203.0.113.2
的A
记录正确创建。复制上一步中其中一个名称服务器名称。
打开一个命令提示符,并运行以下命令:
nslookup www.<dns zone name> <name server name>
例如:
nslookup www.2lwynbseszpam.azurequickstart.org ns1-01.azure-dns.cn.
应会看到类似以下屏幕截图的内容:
主机名 www.2lwynbseszpam.azurequickstart.org
解析为 203.0.113.1
和 203.0.113.2
,正如你配置的那样。 此结果表明名称解析正常工作。
当不再需要使用 DNS 区域创建的资源时,请删除资源组。 此操作会删除该 DNS 区域和所有相关资源。
若要删除资源组,请调用 Remove-AzResourceGroup
cmdlet:
Remove-AzResourceGroup -Name <your resource group name>
在本快速入门中,我们创建了:
- DNS 区域
A
记录
使用 ARM 模板创建第一个 DNS 区域和记录之后,接下来即可在自定义域中为 Web 应用创建记录。