適用於:Azure Local 2311.2 和更新版本
本文說明如何從您在 Azure 本機實例上建立的 VM 映射開始,建立 Azure Arc 所啟用的 Azure 本機虛擬機(VM)。 您可以使用 Azure CLI、Azure 入口網站或 Azure Resource Manager 範本來建立 Azure 本機 VM。
關於 Azure 本地資源
使用 Azure 本機資源頁面 進行下列作業:
- 建立和管理 Azure 本機 VM 資源,例如 VM 映射、磁碟、網路介面。
- 檢視及存取與 Azure 本機實例相關聯的 Azure Arc 資源網橋和自定義位置。
- 布建和管理 VM。
下一節將說明建立 VM 的程式。
必要條件
建立 Azure 本機 VM 之前,請確定下列必要條件已完成:
- 存取具有適當 RBAC 角色和權限指派的 Azure 訂閱。 如需詳細資訊,請參閱 Azure 本機 VM 管理的 RBAC 角色。
- 想要佈建 VM 的資源群組的存取權限。
- 存取 Azure 本機上的一或多個 VM 映像。 下列其中一個程式可以建立這些 VM 映射:
- 您將用來布建虛擬機 (VM) 的 Azure Local 自訂位置。 自定義位置也會顯示在 Azure 本機的 [概 觀 ] 頁面中。
如果使用用戶端連線到您的 Azure 本機,請參閱 透過 Azure CLI 用戶端連線到 Azure 本機。
存取您在與您的 Azure 本地資源相關聯的邏輯網路上所建立的網路介面。 您可以選擇具有靜態 IP 的網路介面,或是具有動態 IP 配置的網路介面。 如需詳細資訊,請參閱如何 建立網路介面。
建立 Azure 本機虛擬機器
請遵循下列步驟,在您的 Azure 本機上建立 VM。
在執行連線至 Azure Local 的 az CLI 用戶端上,請遵循下列步驟。
登入並設定訂用帳戶
連接至 在你的 Azure 本機環境中的機器。
登入。 類型:
az login --use-device-code
設定您的訂用帳戶。
az account set --subscription <Subscription ID>
建立 Windows VM
視您建立的網路介面類型而定,您可以建立具有具有靜態 IP 網路介面的 VM,或是具有動態 IP 配置的 VM。
注意
如果您需要一個以上的網路介面搭配 VM 的靜態 IP,請先建立一或多個介面,再建立 VM。 不支援在布建 VM 之後新增具有靜態 IP 的網路介面。
在這裡,我們會建立一個 VM,使用指定存儲路徑上的特定記憶體和處理器數量。
設定部分參數。
$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 的參數會以下列方式表化:
參數 描述 名字 您為 Azure 本機環境建立的 VM 名稱。 請務必提供遵循 Azure 資源規則的名稱。 admin-username 您在 Azure 本機環境中部署的 VM 上的使用者名稱。 admin-password 您正在 Azure 本地部署的 VM 上用戶的密碼。 image-name 用來布建 VM 的 VM 映像名稱。 位置 Azure 區域,如 az locations
所指定。 例如,這可能是eastus
、westeurope
。資源群組 您在其中建立 VM 的資源群組名稱。 為了方便管理,我們建議您使用與 Azure 本機相同的資源群組。 訂閱 部署 Azure Local 的訂用帳戶名稱或識別碼。 這可能是您在 Azure 本地上用於 VM 的另一個訂用帳戶。 自定義位置 使用此項目來提供與您正在建立此 VM 的 Azure 環境相關聯的自訂位置。 驗證類型 要與 VM 搭配使用的驗證類型。 接受的值為 all
、password
與ssh
。 預設值是適用於Linux的 Windows 和 SSH 公鑰的密碼。 使用all
來啟用ssh
和password
驗證。尼克斯 與您的 VM 相關聯的網路介面名稱或識別碼。 建立 VM 時,您至少必須有一個網路介面,才能啟用客體管理。 memory-mb 配置給您 VM 的記憶體量(以 Megabytes 表示)。 如果未指定,則會使用預設值。 處理器 配置給 VM 的處理器數目。 如果未指定,則會使用預設值。 storage-path-id VM 組態和數據儲存所在的相關聯記憶體路徑。 proxy-configuration 使用此選擇性參數來設定 VM 的 Proxy 伺服器。 如需詳細資訊,請參閱 建立已設定 Proxy 的 VM。 執行下列命令來建立適用的 VM。
若要建立具有受信任啟動功能的 Azure 本機 VM:
指定其他旗標以啟用安全開機、啟用虛擬 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"
建立 VM 之後,若要確認 VM 的安全性類型
Trusted launch
,請執行下列動作。執行下列 Cmdlet(在其中一個叢集節點上),以尋找 VM 的擁有者節點:
Get-ClusterGroup $vmName
在 VM 的擁有者節點上執行下列 Cmdlet:
(Get-VM $vmName).GuestStateIsolationType
確保返回值為
TrustedLaunch
。
若要建立標準 Azure 本機 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 後遵循 在 Azure 本機 VM 上啟用來賓管理 中的步驟來啟用它。
在此範例中,已使用 --storage-path-id
旗標指定記憶體路徑,並確保工作負載數據(包括 VM、VM 映射、非 OS 數據磁碟)都放在指定的記憶體路徑中。
如果未指定旗標,工作負載(VM、VM 映像、非 OS 數據磁碟)會自動放在高可用性記憶體路徑中。
Windows Server 2012 和 Windows Server 2012 R2 映像檔的其他參數
使用 Windows Server 2012 和 Windows Server 2012 R2 映射建立 VM 時,請指定下列其他參數來建立 VM:
-
--enable-agent
:將此參數設定為true
,以將 VM 上的 Azure 連線機器代理程序上線。 -
--enable-vm-config-agent
:將此參數設定為false
,以防止透過 Hyper-V 套接字通道從主機將 VM 代理安裝到 VM。 Windows Server 2012 和 Windows Server 2012 R2 不支援 Hyper-V 套接字。 在支援 Hyper-V 套接字的較新映像版本中,VM 代理程式會用來將 VM 上的 Azure 連線機器代理程序上線。 如需了解 Hyper-V 套接字的詳細資訊,請參閱 自行建立整合服務。
建立 Linux VM
若要建立Linux VM,請使用您用來建立 Windows VM 的相同命令。
- 指定的圖庫映像應該是Linux映像。
- 用戶名稱和密碼適用於
authentication-type-all
參數。 - 對於 SSH 金鑰,您必須傳遞
ssh-key-values
和authentication-type-all
參數一起使用。
重要
Ubuntu Server VM 支援在建立 VM 期間設定 Proxy 伺服器。
建立已設定 Proxy 的 VM
使用此選擇性參數 Proxy 組態 來設定 VM 的 Proxy 伺服器。
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"
注意
- VM 布建期間,會在 Azure 本機 VM 中建立及使用兩部 DVD 磁碟驅動器。 成功建立 VM 之後,會移除布建期間所使用的 ISO 檔案。 不過,您可能會看到 VM 顯示的空白磁碟機。
- 若要刪除 Windows VM 中的這些磁碟驅動器,請使用設備管理員來卸載磁碟驅動器。 視您使用的 Linux 類別而定,您也可以針對 Linux VM 刪除它們。
使用受控身份識別來驗證 Azure 本地 VM
透過 Azure CLI 或 Azure 入口網站在您的 Azure 本機上建立 VM 時,也會建立系統指派的受控識別,以持續 VM 存留期。
Azure 本地上的虛擬機器 (VMs) 是從已啟用 Arc 的伺服器延伸,且可以使用系統指派的受控識別來存取支援 Microsoft Entra ID 型驗證的其他 Azure 資源。 例如,VM 可以使用系統指派的受控識別來存取 Azure Key Vault。
如需詳細資訊,請參閱 系統指派的受控識別 和 使用已啟用 Azure Arc 的伺服器對 Azure 資源進行驗證。