Share via


快速入門:使用 Azure Resource Manager 範本建立 Azure 操作員 Nexus 虛擬機器 (ARM 範本)

  • 使用 Azure Resource Manager 範本部署 Azure Nexus 虛擬機器。

本快速入門手冊旨在協助您開始使用 Nexus 虛擬機器來裝載虛擬網路功能(VNF)。 依照本指南中所述的步驟,您可以快速且輕鬆地建立符合您特定需求和需求的自訂 Nexus 虛擬機器。 無論您是初學者還是 Nexus 網路專家,本指南都在這裡提供協助。 您將瞭解建立和自訂裝載虛擬網路功能之 Nexus 虛擬機器所需的一切。

開始之前

如果您沒有 Azure 訂用帳戶,請在開始之前先建立 Azure 免費帳戶

  • 安裝最新版 的必要 Azure CLI 擴充功能

  • 本文需要 Azure CLI 2.49.0 版或更新版本。 如果您是使用 Azure Cloud Shell,就已安裝最新版本。

  • 如果您有多個 Azure 訂用帳戶,請選取適當的訂用帳戶識別碼,其中應該使用 az account 命令來計費資源。

  • 在繼續建立虛擬機器之前,請確定會根據 指示 建立要使用的容器映射。

  • 使用 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/部署資源類型上的所有作業。 例如,若要部署叢集,您需要 Microsoft.NetworkCloud/virtualMachines/write 和 Microsoft.Resources/deployments/* 許可權。 如需角色與權限的清單,請參閱 Azure 內建角色

  • 您需要 custom location Azure 操作員 Nexus 叢集的資源識別碼。

  • 您必須根據特定的工作負載需求建立 各種網路 ,而且必須有適當的 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. 建立名為 virtual-machine-parameters.json 的檔案,並以 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 命令來移除資源群組、虛擬機器,以及操作員 Nexus 網路資源以外的所有相關資源。

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

下一步

您已成功建立 Nexus 虛擬機器。 您現在可以使用虛擬機器來裝載虛擬網路功能(VNFs)。