你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

快速入门:使用 Azure 资源管理器 模板创建 Azure 操作员 Nexus 虚拟机(ARM 模板)

  • 使用 Azure 资源管理器 模板部署 Azure Nexus 虚拟机。

本快速入门指南旨在帮助你开始使用 Nexus 虚拟机托管虚拟网络功能 (VNF)。 按照本指南中所述的步骤操作,可以快速轻松地创建满足特定需求和要求的自定义 Nexus 虚拟机。 无论你是 Nexus 网络的初学者还是专家,本指南都可以帮助你。 你将了解创建和自定义用于托管虚拟网络功能的 Nexus 虚拟机所需的全部知识。

开始之前

如果没有 Azure 订阅,请在开始之前创建一个 Azure 免费帐户

  • 安装必需的 Azure CLI 扩展的最新版本。

  • 本文需要 2.49.0 或更高版本的 Azure CLI。 如果使用 Azure Cloud Shell,则最新版本已安装。

  • 如果你有多个 Azure 订阅,请使用 az account 命令选择应在其中计收资源费用的相应订阅 ID。

  • 在继续创建虚拟机之前,请确保根据说明创建要使用的容器映像。

  • 使用 az group create 命令创建资源组。 Azure 资源组是用于部署和管理 Azure 资源的逻辑组。 创建资源组时,系统会提示你指定一个位置。 此位置是资源组元数据的存储位置,也是资源在 Azure 中运行的位置(如果你在创建资源期间未指定其他区域)。 以下示例在“eastus”位置创建名为“myResourceGroup”的资源组。

    az group create --name myResourceGroup --location eastus
    

    以下输出示例类似于成功创建资源组:

    {
      "id": "/subscriptions/<guid>/resourceGroups/myResourceGroup",
      "location": "eastus",
      "managedBy": null,
      "name": "myResourceGroup",
      "properties": {
        "provisioningState": "Succeeded"
      },
      "tags": null
    }
    
  • 若要部署 Bicep 文件或 ARM 模板,需要对要部署的资源具有写入权限,并且需要对 Microsoft.Resources/deployments 资源类型的所有操作具有访问权限。 例如,若要部署群集,需要 Microsoft.NetworkCloud/virtualMachines/write 和 Microsoft.Resources/deployments/* 权限。 有关角色和权限的列表,请参阅 Azure 内置角色

  • 需要 Azure Operator Nexus 群集的 custom location 资源 ID。

  • 需要根据特定的工作负载要求创建各种网络,并且必须具有适用于工作负载的相应 IP 地址。 为确保顺利实施,建议咨询相关支持团队以获取帮助。

查看模板

在部署虚拟机模板之前,让我们查看内容以了解其结构。

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vmName": {
            "type": "string",
            "metadata": {
                "description": "The name of Nexus virtual machine"
            }
        },
        "location": {
            "type": "string",
            "metadata": {
                "description": "The Azure region where the VM is to be deployed"
            },
            "defaultValue": "[resourceGroup().location]"
        },
        "extendedLocation": {
            "type": "string",
            "metadata": {
                "description": "The custom location of the Nexus instance"
            }
        },
        "tags": {
            "type": "object",
            "metadata": {
                "description": "The metadata tags to be associated with the cluster resource"
            },
            "defaultValue": {}
        },
        "adminUsername": {
            "type": "string",
            "defaultValue": "azureuser",
            "maxLength": 32,
            "minLength": 1,
            "metadata": {
                "description": "The name of the administrator to which the ssh public keys will be added into the authorized keys."
            }
        },
        "bootMethod": {
            "type": "string",
            "defaultValue": "UEFI",
            "allowedValues": ["UEFI", "BIOS"],
            "metadata": {
                "description": "Selects the boot method for the virtual machine."
            }
        },
        "cloudServicesNetworkId": {
            "type": "string",
            "metadata": {
                "description": "The Cloud Services Network attachment ARM ID to attach to virtual machine."
            }
        },
        "cpuCores": {
            "type": "int",
            "defaultValue": 2,
            "metadata": {
                "description": "Number of CPU cores for the virtual machine. Choose a value between 2 and 46."
            }
        },
        "memorySizeGB": {
            "type": "int",
            "defaultValue": 4,
            "metadata": {
                "description": "The memory size of the virtual machine in GB (max 224 GB)"
            }
        },
        "networkAttachments": {
            "type": "array",
            "metadata": {
                "description": "The list of network attachments to the virtual machine."
            }
            /*
            {
                "attachedNetworkId": "string",
                "defaultGateway": "True"/"False",
                "ipAllocationMethod": "Dynamic"/"Static"/"Disabled",
                "ipv4Address": "string",
                "ipv6Address": "string",
                "networkAttachmentName": "string"
            }
            */
        },
        "networkData": {
            "type": "string",
            "metadata": {
                "description": "The Base64 encoded cloud-init network data."
            },
            "defaultValue": ""
        },
        "placementHints": {
            "type": "array",
            "metadata": {
                "description": "The placement hints for the virtual machine."
            },
            "defaultValue": []
            /*
            {
                "hintType": "Affinity",
                "resourceId": "string",
                "schedulingExecution": "Hard",
                "scope": "Rack"
            }
            */
        },
        "sshPublicKeys": {
            "type": "array",
            "metadata": {
                "description": "The list of SSH public keys for the virtual machine."
            }
            /*
            {
                "keyData": "string"
            }
            */
        },
        "storageProfile": {
            "type": "object",
            "metadata": {
                "description": "StorageProfile represents information about a disk."
            },
            "defaultValue": {
                "osDisk": {
                    "createOption": "Ephemeral",
                    "deleteOption": "Delete",
                    "diskSizeGB": 64
                }
            }
        },
        "userData": {
            "type": "string",
            "metadata": {
                "description": "The Base64 encoded cloud-init user data."
            },
            "defaultValue": ""
        },
        "vmDeviceModel": {
            "type": "string",
            "defaultValue": "T2",
            "allowedValues": ["T1", "T2"],
            "metadata": {
                "description": "The type of the device model to use."
            }
        },
        "vmImage": {
            "type": "string",
            "metadata": {
                "description": "The virtual machine image that is currently provisioned to the OS disk, using the full URL and tag notation used to pull the image."
            }
        },
        "vmImageRepositoryCredentials": {
            "type": "object",
            "metadata": {
                "description": "Credentials used to login to the image repository."
            }
            /*
                "password": "string",
                "registryUrl": "string",
                "username": "string"
            */
        }
    },
    "resources": [
        {
            "type": "Microsoft.NetworkCloud/virtualMachines",
            "apiVersion": "2023-07-01",
            "name": "[parameters('vmName')]",
            "location": "[parameters('location')]",
            "extendedLocation": {
                "type": "CustomLocation",
                "name": "[parameters('extendedLocation')]"
            },
            "tags": "[parameters('tags')]",
            "properties": {
                "adminUsername": "[if(empty(parameters('adminUsername')), json('null'), parameters('adminUsername'))]",
                "bootMethod": "[if(empty(parameters('bootMethod')), json('null'), parameters('bootMethod'))]",
                "cloudServicesNetworkAttachment": {
                    "attachedNetworkId": "[parameters('cloudServicesNetworkId')]",
                    "defaultGateway": "False",
                    "ipAllocationMethod": "Dynamic"
                },
                "cpuCores": "[parameters('cpuCores')]",
                "memorySizeGB": "[parameters('memorySizeGB')]",
                "networkData": "[if(empty(parameters('networkData')), json('null'), parameters('networkData'))]",
                "networkAttachments": "[if(empty(parameters('networkAttachments')), json('null'), parameters('networkAttachments'))]",
                "placementHints": "[if(empty(parameters('placementHints')), json('null'), parameters('placementHints'))]",
                "sshPublicKeys": "[if(empty(parameters('sshPublicKeys')), json('null'), parameters('sshPublicKeys'))]",
                "storageProfile": "[if(empty(parameters('storageProfile')), json('null'), parameters('storageProfile'))]",
                "userData": "[if(empty(parameters('userData')), json('null'), parameters('userData'))]",
                "vmDeviceModel": "[if(empty(parameters('vmDeviceModel')), json('null'), parameters('vmDeviceModel'))]",
                "vmImage": "[if(empty(parameters('vmImage')), json('null'), parameters('vmImage'))]",
                "vmImageRepositoryCredentials": "[if(empty(parameters('vmImageRepositoryCredentials')), json('null'), parameters('vmImageRepositoryCredentials'))]"
            }
        }
    ]
  }

查看并保存命名 virtual-machine-arm-template.json的模板文件后,请转到下一部分来部署模板。

部署模板

  1. 创建以 JSON 格式命名 virtual-machine-parameters.json 并添加所需参数的文件。 可以使用以下示例作为起点。 将值替换成自己的值。
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "vmName": {
        "value": "myNexusVirtualMachine"
      },
      "location": {
        "value": "eastus"
      },
      "extendedLocation": {
        "value": "/subscriptions/<subscription>/resourcegroups/<cluster-managed-resource-group>/providers/microsoft.extendedlocation/customlocations/<custom-location-name>"
      },
      "cloudServicesNetworkId": {
          "value": "/subscriptions/<subscription>/resourceGroups/<network-resource-group>/providers/Microsoft.NetworkCloud/cloudServicesNetworks/<csn-name>"
      },
      "networkAttachments": {
          "value": [
            {
                "attachedNetworkId": "/subscriptions/<subscription>/resourceGroups/<network-resource-group>/providers/Microsoft.NetworkCloud/l3Networks/<l3network-name>",
                "ipAllocationMethod": "Dynamic",
                "defaultGateway": "True",
                "networkAttachmentName": "mgmt0"
            }
        ]
      },
      "sshPublicKeys": {
          "value": [
            {
                "keyData": "ssh-rsa AAAAB3...."
            }
        ]
      },
      "vmImage": {
          "value": "<Image ACR URL>"
      },
      "vmImageRepositoryCredentials": {
          "value": {
              "password": "********************",
              "registryUrl": "<ACR registry URL>",
              "username": "<ACR user name>"
          }
      }
    }
  }
  1. 部署模板。
    az deployment group create --resource-group myResourceGroup --template-file virtual-machine-arm-template.json --parameters @virtual-machine-parameters.json

查看已部署的资源

部署完成后,可以使用 CLI 或 Azure 门户查看资源。

若要查看资源组中myResourceGroup群集的详细信息myNexusVirtualMachine,请执行以下操作

az networkcloud virtualmachine show --name myNexusVirtualMachine --resource-group myResourceGroup

清理资源

不再需要资源组时,可将其删除。 资源组和资源组中的所有资源都会被删除。

使用 az group delete 命令可删除资源组、虚拟机以及除 Operator Nexus 网络资源外的所有相关资源。

az group delete --name myResourceGroup --yes --no-wait

后续步骤

已成功创建 Nexus 虚拟机。 现在,可以使用虚拟机托管虚拟网络功能 (VNF)。