共用方式為


在 Azure 本地環境上建立 Arc 虛擬機器

適用於:Azure Local 2311.2 和更新版本

本文說明如何從您在 Azure 本機實例上建立的 VM 映射開始建立 Arc 虛擬機(VM)。 您可以使用 Azure CLI、Azure 入口網站 或 Azure Resource Manager 範本來建立 Arc VM。

關於 Azure 本機資源

使用 Azure 本機資源頁面 進行下列作業:

  • 建立和管理 Arc VM 資源,例如 VM 映像、磁碟、網路介面。
  • 檢視及存取與 Azure 本機實例相關聯的 Azure Arc 資源網橋和自定義位置。
  • 布建和管理Arc VM。

下一節將說明建立Arc VM的程式。

必要條件

建立已啟用 Azure Arc 的 VM 之前,請確定下列必要條件已完成。

  • 如果使用用戶端連線到您的 Azure 本機,請參閱 透過 Azure CLI 用戶端連線到 Azure 本機。

  • 存取您在與您的 Azure 本地資源相關聯的邏輯網路上所建立的網路介面。 您可以選擇具有靜態 IP 的網路介面,或是具有動態 IP 配置的網路介面。 如需詳細資訊,請參閱如何 建立網路介面

建立 Arc VM

請遵循下列步驟,在您的 Azure 本機上建立 Arc VM。

在執行連線至 Azure Local 的 az CLI 用戶端上,請遵循下列步驟。

登入並設定訂用帳戶

  1. 連接至 Azure 本機上的設備

  2. 登入。 類型:

    az login --use-device-code
    
  3. 設定您的訂用帳戶。

    az account set --subscription <Subscription ID>
    

建立 Windows VM

視您建立的網路介面類型而定,您可以建立具有具有靜態 IP 網路介面的 VM,或是具有動態 IP 配置的 VM。

注意

如果您需要一個以上的網路介面搭配 VM 的靜態 IP,請先建立一或多個介面,再建立 VM。 不支援在布建 VM 之後新增具有靜態 IP 的網路介面。

在這裡,我們會建立一個 VM,使用指定存儲路徑上的特定記憶體和處理器數量。

  1. 設定部分參數。

    $vmName ="local-vm"
    $subscription =  "<Subscription ID>"
    $resource_group = "local-rg"
    $customLocationName = "local-cl"
    $customLocationID ="/subscriptions/$subscription/resourceGroups/$resource_group/providers/Microsoft.ExtendedLocation/customLocations/$customLocationName"
    $location = "eastus"
    $computerName = "mycomputer"
    $userName = "local-user"
    $password = "<Password for the VM>"
    $imageName ="ws22server"
    $nicName ="local-vnic" 
    $storagePathName = "local-sp" 
    $storagePathId = "/subscriptions/<Subscription ID>/resourceGroups/local-rg/providers/Microsoft.AzureStackHCI/storagecontainers/local-sp" 
    

    建立 VM 的參數會以下列方式表化:

    參數 描述
    name 您為 Azure 本機環境建立的 VM 名稱。 請務必提供遵循 Azure 資源規則的名稱。
    admin-username 您要在 Azure 本機上部署之 VM 上使用者的使用者名稱。
    admin-password 您要在 Azure 本機上部署之 VM 上的用戶密碼。
    image-name 用來布建 VM 的 VM 映像名稱。
    位置 Azure 區域,如 az locations 所指定。 例如,這可能是 eastuswesteurope
    資源群組 您在其中建立 VM 的資源群組名稱。 為了方便管理,我們建議您使用與 Azure 本機相同的資源群組。
    訂閱 此為部署 Azure Local 的訂用帳戶名稱或識別碼。 這可能是您在 Azure 本地上用於 VM 的另一個訂用帳戶。
    自訂位置 使用此項目來提供與您正在建立此 VM 的 Azure 環境相關聯的自訂位置。
    驗證類型 要與 VM 搭配使用的驗證類型。 接受的值為 allpasswordssh。 預設值是適用於Linux的 Windows 和 SSH 公鑰的密碼。 使用 all 來啟用 sshpassword 驗證。
    nics 與您的 VM 相關聯的網路介面名稱或識別碼。 建立 VM 時,您至少必須有一個網路介面,才能啟用客體管理。
    memory-mb 配置給您 VM 的記憶體量(以 Megabytes 表示)。 如果未指定,則會使用預設值。
    處理器 配置給 VM 的處理器數目。 如果未指定,則會使用預設值。
    storage-path-id VM 組態和數據儲存所在的相關聯記憶體路徑。
    proxy-configuration 使用此選擇性參數來設定 VM 的 Proxy 伺服器。 如需詳細資訊,請參閱 建立已設定代理伺服器的 VM
  2. 執行下列命令來建立適用的 VM。

    若要建立受信任的啟動Arc VM:

    1. 指定其他旗標以啟用安全開機、啟用虛擬 TPM,然後選擇安全性類型。 請注意,當您將安全性類型指定為 [信任啟動] 時,您必須啟用安全開機和 vTPM,否則信任啟動 VM 建立將會失敗。

      az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --enable-secure-boot true --enable-vtpm true --security-type "TrustedLaunch"
      
    2. 建立 VM 之後,若要確認 VM 的安全性類型 Trusted launch,請執行下列動作。

    3. 執行下列 Cmdlet(在其中一個叢集節點上),以尋找 VM 的擁有者節點:

      Get-ClusterGroup $vmName
      
    4. 在 VM 的擁有者節點上執行下列 Cmdlet:

      (Get-VM $vmName).GuestStateIsolationType
      
    5. 確保返回值為 TrustedLaunch

    若要建立標準 Arc VM:

     az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId 
    

provisioningState在輸出中顯示為succeeded時,VM已成功建立。

注意

建立的 VM 預設會啟用來賓管理。 如果因為任何原因,客體管理在 VM 建立期間失敗,您可以遵循在建立 VM 之後在 Arc VM 上啟用客體管理中的步驟。

在此範例中,已使用 --storage-path-id 旗標指定記憶體路徑,並確保工作負載數據(包括 VM、VM 映射、非 OS 數據磁碟)都放在指定的記憶體路徑中。

如果未指定旗標,工作負載(VM、VM 映像、非 OS 數據磁碟)會自動放在高可用性記憶體路徑中。

Windows Server 2012 和 Windows Server 2012 R2 映像檔的其他參數

使用 Windows Server 2012 和 Windows Server 2012 R2 映射建立 Arc VM 時,請指定下列其他參數來建立 VM:

  • --enable-agent:將此參數設定為 true,以將Arc VM上的 Azure 連線機器代理程序上線。
  • --enable-vm-config-agent:將此參數設定為 false,以防止透過 Hyper-V 套接字通道從主機將 VM 代理安裝到 VM。 Windows Server 2012 和 Windows Server 2012 R2 不支援 Hyper-V 套接字。 在支援 Hyper-V 套接字的較新映像版本中,VM 代理程式用於將 Azure Connected 機器代理程式載入到 Arc 虛擬機器中。 如需有關 Hyper-V 套接字的詳細資訊,請參閱 建立您自己的整合服務

建立 Linux VM

若要建立Linux VM,請使用您用來建立 Windows VM 的相同命令。

  • 指定的圖庫映像應該是Linux映像。
  • 用戶名稱和密碼適用於 authentication-type-all 參數。
  • 對於 SSH 金鑰,您必須傳遞 ssh-key-valuesauthentication-type-all 參數一起使用。

重要

Ubuntu Server VM 支援在建立 VM 期間設定 Proxy 伺服器。

建立已設定 Proxy 的 VM

使用此選擇性參數 Proxy 組態 來設定 VM 的 Proxy 伺服器。

Arc VM 的 Proxy 組態只會套用至 Azure 連線機器代理程式的上線,並設定為客體 VM 操作系統內的環境變數。 VM 上的瀏覽器和應用程式不一定都啟用此 Proxy 設定。

因此,如果應用程式未引用在 VM 內設定的環境變數,您可能需要特別設定應用程式的代理伺服器設定。

如果在 Proxy 伺服器後方建立 VM,請執行下列命令:

az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --proxy-configuration http_proxy="<Http URL of proxy server>" https_proxy="<Https URL of proxy server>" no_proxy="<URLs which bypass proxy>" cert_file_path="<Certificate file path for your machine>"

您可以為 proxy-server-configuration 輸入下列參數:

參數 描述
http_proxy Proxy 伺服器的 HTTP URL。 範例 URL 為:http://proxy.example.com:3128
https_proxy Proxy 伺服器的 HTTPS URL。 伺服器仍可使用 HTTP 位址,如下列範例所示: http://proxy.example.com:3128
no_proxy URL,可繞過代理伺服器。 典型的範例是 localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.0.0.0/8
cert_file_path 選取用來與 Proxy 伺服器建立信任的憑證檔案。 例如:C:\Users\Palomino\proxycert.crt

以下是命令範例:

az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --location $location --authentication-type all --nics $nicName --custom-location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --proxy-configuration http_proxy="http://ubuntu:ubuntu@192.168.200.200:3128" https_proxy="http://ubuntu:ubuntu@192.168.200.200:3128" no_proxy="localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.0.0.0/8,s-cluster.test.contoso.com" cert_file_path="C:\ClusterStorage\UserStorage_1\server.crt"

針對代理伺服器驗證,您可以在 URL 中傳遞結合的使用者名稱和密碼,如下所示:"http://username:password@proxyserver.contoso.com:3128"

使用受控識別來驗證Arc VM

當您透過 Azure CLI 或 Azure 入口網站 在 Azure 本機上建立 Arc VM 時,也會建立系統指派的受控識別,以持續 Arc VM 的存留期。

Azure 本機上的 Arc VM 會從已啟用 Arc 的伺服器延伸,而且可以使用系統指派的受控識別來存取支援Microsoft Entra ID 型驗證的其他 Azure 資源。 例如,Arc VM 可以使用系統指派的受控識別來存取 Azure 金鑰保存庫。

如需詳細資訊,請參閱 系統指派的受控識別使用已啟用 Azure Arc 的伺服器對 Azure 資源進行驗證。

下一步