Azure Windows VM 代理程式概觀

Microsoft Azure Windows VM 代理程式是一個安全的輕量型處理程序,可管理虛擬機器 (VM) 與 Azure 網狀架構控制器的互動。 Azure Windows VM 代理程式已啟用主要角色並執行 Azure 虛擬機器擴充功能。 VM 擴充功能可啟用 VM 的部署後組態,例如安裝和設定軟體。 VM 擴充功能也會啟用復原功能,例如重設 VM 的系統管理密碼。 如果沒有 Azure Windows VM 代理程式,您就無法執行 VM 擴充功能。

本文說明如何安裝和偵測 Azure Windows VM 代理程式。

必要條件

Azure Windows VM 代理程式支援下列 Windows 作業系統的 x64 架構:

  • Windows 10
  • Windows 11
  • Windows Server 2008 SP2
  • Windows Server 2008 R2
  • Windows Server 2012
  • Windows Server 2012 R2
  • Windows Server 2016
  • Windows Server 2016 Core
  • Windows Server 2019
  • Windows Server 2019 Core
  • Windows Server 2022
  • Windows Server 2022 Core

重要

  • Azure Windows VM 代理程式至少需要 Windows Server 2008 SP2 (64 位元),才能使用 .NET Framework 4.0 來執行。 請參閱虛擬機器代理程式在 Azure 中的最低版本支援

  • 請確定您的 VM 可以存取 IP 位址 168.63.129.16。 如需相關資訊,請參閱什麼是 IP 位址 168.63.129.16?

  • 確定已在客體 VM 內啟用 DHCP。 必須從 DHCP 取得主機或網狀架構位址,Azure Windows VM 代理程式與擴充功能才能運作。 如果您需要靜態私人 IP 位址,則應透過 Azure 入口網站或 PowerShell 加以設定,並確定已啟用 VM 內的 DHCP 選項。 深入了解如何使用 PowerShell 設定靜態 IP 位址。

  • 在「巢狀虛擬化」VM 中執行 Azure Windows VM 代理程式可能會導致無法預期的行為,因此在該開發/測試案例中不支援。

安裝 Azure Windows VM 代理程式

Azure Marketplace 映像

根據預設,Azure Windows VM 代理程式會安裝在從 Azure Marketplace 映像部署的任何 Windows VM 上。 從 Azure 入口網站、PowerShell、Azure CLI 或 Azure Resource Manager 範本部署 Azure Marketplace 映像時,也會安裝 Azure Windows VM 代理程式。

Azure Windows VM 代理程式套件有兩個部分:

  • Azure Windows 佈建代理程式 (PA)
  • Azure Windows 客體代理程式 (WinGA)

若要開機 VM,您必須在 VM 上安裝 PA。 不過,不需要安裝 WinGA。 在 VM 部署時,您可以選擇不安裝 WinGA。 下列範例示範如何使用 Azure Resource Manager 範本選取 provisionVmAgent 選項:

{
	"resources": [{
		"name": ["parameters('virtualMachineName')"],
		"type": "Microsoft.Compute/virtualMachines",
		"apiVersion": "2016-04-30-preview",
		"location": ["parameters('location')"],
		"dependsOn": ["[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]"],
		"properties": {
			"osProfile": {
				"computerName": ["parameters('virtualMachineName')"],
				"adminUsername": ["parameters('adminUsername')"],
				"adminPassword": ["parameters('adminPassword')"],
				"windowsConfiguration": {
					"provisionVmAgent": "false"
				}
			}
		}
	}]
}

如果您沒有安裝代理程式,就無法使用部分 Azure 服務,例如 Azure 備份或 Azure 安全性。 這些服務需要安裝擴充功能。 如果您部署不含 WinGA 的 VM,之後就可以安裝最新版的代理程式。

手動安裝

Azure Windows VM 代理程式可以使用 Windows Installer 套件來手動安裝。 當您建立部署至 Azure 的自訂 VM 映像時,可能需要手動安裝。

若要手動安裝 Azure Windows VM 代理程式,請下載安裝程式,然後選擇最新版本。 您也可以在 Azure Windows VM 代理程式版本的 GitHub 頁面中搜尋特定版本。 Windows Server 2008 (64 位元) 和更新版本支援 Azure Windows VM 代理程式。

注意

請務必在從未啟用 ProvisionVMAgent 的映像部署的 VM 上手動安裝 Azure Windows VM 代理程式,之後再更新 AllowExtensionOperations 選項。

$vm.OSProfile.AllowExtensionOperations = $true
$vm | Update-AzVM

偵測 Azure Windows VM 代理程式

PowerShell

您可使用 Azure Resource Manager PowerShell 模組取得 Azure VM 的相關資訊。 若要查看 VM 的相關資訊,例如 Azure Windows VM 代理程式的佈建狀態,請使用 Get-AzVM

Get-AzVM

下列緊縮的範例輸出顯示 ProvisionVMAgent 屬性會以巢狀方式置於 OSProfile 內。 這個屬性可用來判斷 VM 代理程式是否已部署至 VM。

OSProfile                  :
  ComputerName             : myVM
  AdminUsername            : myUserName
  WindowsConfiguration     :
    ProvisionVMAgent       : True
    EnableAutomaticUpdates : True

下列指令碼可以用來傳回簡明的 VM 名稱 (執行 Windows OS) 清單和 Azure Windows VM 代理程式的狀態:

$vms = Get-AzVM

foreach ($vm in $vms) {
    $agent = $vm | Select -ExpandProperty OSProfile | Select -ExpandProperty Windowsconfiguration | Select ProvisionVMAgent
    Write-Host $vm.Name $agent.ProvisionVMAgent
}

下列指令碼可以用來傳回簡明的 VM 名稱 (執行 Linux OS) 清單和 Azure Windows VM 代理程式的狀態:

$vms = Get-AzVM

foreach ($vm in $vms) {
    $agent = $vm | Select -ExpandProperty OSProfile | Select -ExpandProperty Linuxconfiguration | Select ProvisionVMAgent
    Write-Host $vm.Name $agent.ProvisionVMAgent
}

手動偵測

登入 Windows VM 時,可以使用工作管理員來檢查執行中的程序。 若要檢查 Azure Windows VM 代理程式,請開啟 [工作管理員]、選取 [詳細資料] 索引標籤,然後尋找程序名稱 WindowsAzureGuestAgent.exe。 此程序的目前狀態表示已安裝 VM 代理程式。

升級 Azure Windows VM 代理程式

適用於 Windows 的 Azure Windows VM 代理程式會從 Azure Marketplace 部署的映像上自動進行升級。 新版本會儲存在 Azure 儲存體中,因此請確定您沒有防火牆封鎖存取。 當新的 VM 部署至 Azure 時,這些 VM 在 VM 佈建時,會收到最新的 VM 代理程式。 如果您已手動安裝代理程式,或正在部署自訂 VM 映像,您必須手動更新,才能在映像建立時,包含新的 VM 代理程式。

Azure Windows 客體代理程式自動收集記錄

Azure Windows 客體代理程式具有自動收集某些記錄的功能。 CollectGuestLogs.exe 程序控制此功能。 它同時存在於平台即服務 (PaaS) 雲端服務和基礎結構即服務 (IaaS) VM。 其目標是從 VM 快速自動收集診斷記錄,以便用於離線分析。

收集的記錄包括事件記錄、OS 記錄、Azure 記錄和一些登錄機碼。 代理程式會產生 ZIP 檔案,可傳送至 VM 主機。 然後,工程小組和支援專業人員可以用此 ZIP 檔案來調查擁有 VM 的客戶所要求的問題。

Azure Windows 客體代理程式和 OSProfile 憑證

Azure Windows VM 代理程式將安裝 VM 或虛擬機器擴展集的 OSProfile 值中所參考的憑證。 如果您從客體 VM 內的 Microsoft Management Console (MMC) 憑證嵌入式管理單元手動移除這些憑證,則 Azure Windows 客體代理程式預期會將其加回。 若要永久移除憑證,您必須將其從 OSProfile 中移除,然後從客體作業系統內將其移除。

針對虛擬機器,請使用 Remove-AzVMSecretOSProfile 移除憑證。

如需虛擬機器擴展集憑證的詳細資訊,請參閱 Azure 虛擬機器擴展集 - 如何移除已被取代的憑證?

下一步

如需 VM 延伸模組的詳細資訊,請參閱 Azure 虛擬機器延伸模組和功能