快速入门:创建虚拟网络 - 资源管理器模板Quickstart: Create a virtual network - Resource Manager template

在本快速入门中,你将了解如何使用 Azure 资源管理器模板创建具有两个子网的虚拟网络。In this quickstart, you learn how to create a virtual network with two subnets using the Azure Resource Manager template. 虚拟网络是 Azure 中专用网络的基本构建块。A virtual network is the fundamental building block for your private network in Azure. 它能让 Azure 资源(例如 VM)互相安全通信以及与 Internet 通信。It enables Azure resources, like VMs, to securely communicate with each other and with the internet.

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.

还可以使用 Azure 门户Azure PowerShellAzure CLI 完成本快速入门。You can also complete this quickstart using the Azure portal, Azure PowerShell, or Azure CLI.

先决条件Prerequisites

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

查看模板Review the template

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

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vnetName": {
      "type": "string",
      "defaultValue": "VNet1",
      "metadata": {
        "description": "VNet name"
      }
    },
    "vnetAddressPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/16",
      "metadata": {
        "description": "Address prefix"
      }
    },
    "subnet1Prefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/24",
      "metadata": {
        "description": "Subnet 1 Prefix"
      }
    },
    "subnet1Name": {
      "type": "string",
      "defaultValue": "Subnet1",
      "metadata": {
        "description": "Subnet 1 Name"
      }
    },
    "subnet2Prefix": {
      "type": "string",
      "defaultValue": "10.0.1.0/24",
      "metadata": {
        "description": "Subnet 2 Prefix"
      }
    },
    "subnet2Name": {
      "type": "string",
      "defaultValue": "Subnet2",
      "metadata": {
        "description": "Subnet 2 Name"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2020-05-01",
      "name": "[parameters('vnetName')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('vnetAddressPrefix')]"
          ]
        }
      },
      "resources": [
        {
          "type": "subnets",
          "apiVersion": "2020-05-01",
          "location": "[parameters('location')]",
          "name": "[parameters('subnet1Name')]",
          "dependsOn": [
            "[parameters('vnetName')]"
          ],
          "properties": {
            "addressPrefix": "[parameters('subnet1Prefix')]"
          }
        },
        {
          "type": "subnets",
          "apiVersion": "2020-05-01",
          "location": "[parameters('location')]",
          "name": "[parameters('subnet2Name')]",
          "dependsOn": [
            "[parameters('vnetName')]",
            "[parameters('subnet1Name')]"
          ],
          "properties": {
            "addressPrefix": "[parameters('subnet2Prefix')]"
          }
        }
      ]
    }

该模板中已定义了以下 Azure 资源:The following Azure resources have been defined in the template:

  • Microsoft.Network/virtualNetworks:创建 Azure 虚拟网络。Microsoft.Network/virtualNetworks : create an Azure virtual network.
  • Microsoft.Network/virtualNetworks/subnets:创建子网。Microsoft.Network/virtualNetworks/subnets : create a subnet.

部署模板Deploy the template

将资源管理器模板部署到 Azure:Deploy Resource Manager template to Azure:

  1. 选择“部署到 Azure”,登录到 Azure 并打开模板。Select Deploy to Azure to sign in to Azure and open the template. 该模板创建包含两个子网的虚拟网络。The template creates a virtual network with two subnets.

    部署到 Azure Deploy to Azure

    备注

    当我们从 https://raw.githubusercontent.com/ 网站下载特定模板并尝试从自定义模板进行部署时,有时会遇到某些问题。When we download the specific template from https://raw.githubusercontent.com/ website and try to deploy from custom template, there will be encounter certain issue sometime.

    githubusercontent 前缀模板部署问题

    我们可以按照以下指示在 Azure 中国云世纪互联中部署模板:We can follow the directions below to deploy template on Azure China Cloud 21Vianet:

    1. 复制模板 URI,通过更改前缀、中缀和模板文件名来转换 URI。Copy the template URI, convert the URI by changing the prefix, infix, and tempalte file name. 例如,源 URI 是 https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-cosmosdb-sql-autoscale/azuredeploy.jsonFor exsample: the origin URI is https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-cosmosdb-sql-autoscale/azuredeploy.json

      类别Category 原始值Original value 转换后的值Converted value 操作Action
      前缀Prefix https://raw.githubusercontent.com https://github.com 更新Update
      中辍Infix blob master 之前添加(Git 存储库的默认分支名称)Add before master(default branch name of git repository)
      模板文件名Template file name azuredeploy.jsonazuredeploy.json 你的下载模板文件名your download tempalte file name updateupdate

      修改后,转换后的 URI 看起来将类似于 https://github.com/Azure/azure-quickstart-templates/blob/master/101-cosmosdb-sql-autoscale/azuredeploy.jsonAfter modified, the converted URI will show like 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。Please be kindly noticed that some templates URI have been moved to https://github.com/Azure/azure-quickstart-template/quickstarts/{Microsoft_Resource_Provider_Name}/, you can follow the corresponding path regulation to update the original URI.

    2. 复制转换后的 URI,并在 Internet 浏览器中手动下载特定的模板内容。Copy the converted URI and download the specific template content in Internet browsers manully.

    3. 在门户的“自定义部署”页中,选择“在编辑器中生成自己的模板”。Select Build your own template in the editor in the Custom deployment page of portal.

    4. 将下载的模板内容复制到“编辑模板”页中,并按照 Azure 中国云的要求更新参数,例如 Azure 中国云环境不支持的终结点、位置、VM 映像、VM 大小、SKU 和资源提供程序的 API 版本。Copy the downloaded template content in the Edit template page and update the parameters to meet Azure China Cloud, such as endpoint, Location, VM images, VM sizes, SKU , and resource-provider's API Version that is not supported on Azure China Cloud environment.

    5. 选择“保存”以返回“自定义部署”页。Select save to return the Custom deployment page.

    6. 选择“我同意上述条款和条件”。Select I agree to the terms and condition stated above.

    7. 选择“购买”。Select Purchase.

  2. 在门户中的“创建具有两个子网的虚拟网络”页上,键入或选择以下值:In the portal, on the Create a Virtual Network with two Subnets page, type or select the following values:

    • 资源组:选择“新建”,键入资源组的名称,然后选择“确定”。Resource group: Select Create new, type a name for the resource group, and select OK.
    • 虚拟网络名称:键入新虚拟网络的名称。Virtual Network Name: Type a name for the new virtual network.
  3. 选择“查看 + 创建”,然后选择“创建”。Select Review + create, and then select Create.

查看已部署的资源Review deployed resources

浏览使用虚拟网络创建的资源。Explore the resources that were created with the virtual network.

若要了解模板中虚拟网络的 JSON 语法和属性,请参阅 Microsoft.Network/virtualNetworksTo learn about the JSON syntax and properties for a virtual network in a template, see Microsoft.Network/virtualNetworks.

清理资源Clean up resources

如果不再需要使用虚拟网络创建的资源,请删除资源组。When you no longer need the resources that you created with the virtual network, delete the resource group. 这会删除该虚拟网络和所有相关资源。This removes the virtual network 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

在本快速入门中,你部署了具有两个子网的 Azure 虚拟网络。In this quickstart, you deployed an Azure virtual network with two subnets. 若要详细了解 Azure 虚拟网络,请继续学习虚拟网络的教程。To learn more about Azure virtual networks, continue to the tutorial for virtual networks.