快速入门:创建虚拟网络 - 资源管理器模板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 account 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')]"
          }
        }
      ]
    }
  ]  
}

部署模板Deploy the template

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

  1. 登录 Azure 并在“自定义部署”页上保存以上模板。Sign in to Azure and save above template on the Custom deployment page. 该模板创建包含两个子网的虚拟网络。The template creates a virtual network with two subnets.
  1. 在门户中的“自定义部署”页上,键入或选择以下值:In the portal, on the Custom deployment 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.
  2. 单击“我同意上述条款和条件”,并选择“购买”。 Click on I agree to the terms and conditions stated above, and then select Purchase.

查看已部署的资源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.