Share via


快速入門:使用 Bicep 建立 Azure 操作員 Nexus 虛擬機器

  • 使用 Bicep 部署 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 位址可供您的工作負載使用。 為了確保順利執行,建議您諮詢相關的支援小組以取得協助。

檢閱範本

在部署虛擬機器範本之前,讓我們先檢閱內容以瞭解其結構。

@description('The name of Nexus virtual machine')
param vmName string

@description('The Azure region where the VM is to be deployed')
param location string = resourceGroup().location

@description('The custom location of the Nexus instance')
param extendedLocation string

@description('The metadata tags to be associated with the cluster resource')
param tags object = {}

@description('The name of the administrator to which the ssh public keys will be added into the authorized keys.')
@minLength(1)
@maxLength(32)
param adminUsername string = 'azureuser'

@description('Selects the boot method for the virtual machine.')
@allowed([
  'UEFI'
  'BIOS'
])
param bootMethod string = 'UEFI'

@description('The Cloud Services Network attachment ARM ID to attach to virtual machine.')
param cloudServicesNetworkId string

@description('Number of CPU cores for the virtual machine. Choose a value between 2 and 46.')
param cpuCores int = 2

@description('The memory size of the virtual machine in GB (max 224 GB)')
param memorySizeGB int = 4

@description('The list of network attachments to the virtual machine.')
param networkAttachments array

// {
//   attachedNetworkId: "string"
//   defaultGateway: "True"/"False"
//   ipAllocationMethod: "Dynamic"/"Static","Disabled"
//   ipv4Address: "string"
//   ipv6Address: "string"
//   networkAttachmentName: "string"
// }

@description('The Base64 encoded cloud-init network data.')
param networkData string = ''

@description('The placement hints for the virtual machine.')
param placementHints array = []
// {
//   hintType: "Affinity/AntiAffinity"
//   resourceId: string
//   schedulingExecution: "Hard/Soft"
//   scope: "Rack/Machine"
// }

@description('The list of SSH public keys for the virtual machine.')
param sshPublicKeys array
// {
//   keyData: 'string'
// }

@description('StorageProfile represents information about a disk.')
param storageProfile object = {
  osDisk: {
    createOption: 'Ephemeral'
    deleteOption: 'Delete'
    diskSizeGB: 64
  }
}

@description('The Base64 encoded cloud-init user data.')
param userData string = ''

@description('The type of the device model to use.')
@allowed([
  'T1'
  'T2'
])
param vmDeviceModel string = 'T2'

@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.')
param vmImage string

@description('Credentials used to login to the image repository.')
param vmImageRepositoryCredentials object
// password: "string"
// registryUrl: "string"
// username: "string"

resource vm 'Microsoft.NetworkCloud/virtualMachines@2023-07-01' = {
  name: vmName
  location: location
  extendedLocation: {
    type: 'CustomLocation'
    name: extendedLocation
  }
  tags: tags
  properties: {
    adminUsername: (empty(adminUsername) ? null : adminUsername)
    bootMethod: (empty(bootMethod) ? null : bootMethod)
    cloudServicesNetworkAttachment: {
      attachedNetworkId: cloudServicesNetworkId
      defaultGateway: 'False'
      ipAllocationMethod: 'Dynamic'
    }
    cpuCores: cpuCores
    memorySizeGB: memorySizeGB
    networkData: (empty(networkData) ? null : networkData)
    networkAttachments: (empty(networkAttachments) ? null : networkAttachments)
    placementHints: (empty(placementHints) ? null : placementHints)
    sshPublicKeys: (empty(sshPublicKeys) ? null : sshPublicKeys)
    storageProfile: (empty(storageProfile) ? null : storageProfile)
    userData: (empty(userData) ? null : userData)
    vmDeviceModel: (empty(vmDeviceModel) ? null : vmDeviceModel)
    vmImage: (empty(vmImage) ? null : vmImage)
    vmImageRepositoryCredentials: (empty(vmImageRepositoryCredentials) ? null : vmImageRepositoryCredentials)
  }
}

檢閱並儲存名為 virtual-machine-bicep-template.bicep 的範本檔案之後,請繼續進行下一節來部署範本。

部署範本

  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-bicep-template.bicep --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)。