Azure 網路監看員的某些功能需有網路監看員代理程式的虛擬機器延伸模組來擷取網路流量,才能診斷和監看 Azure 虛擬機器 (VM)。 如需詳細資訊,請參閱什麼是 Azure 網路監看員?
在本文中,您將學習如何安裝、更新及卸載 網路監看員 Agent for Windows 和 Linux。 安裝代理程式不會讓虛擬機器中斷或需要重新開機。 如果虛擬機是由 Azure 服務部署的,請查看該服務的文件,以判斷該服務是否允許在虛擬機器中安裝擴充功能。
Note
網路監看員 Agent 擴充功能在 AKS 叢集上不被支援。
先決條件
一個運行支援作業系統的 Azure 虛擬機(VM)。 欲了解更多資訊,請參閱 支援作業系統。
輸出 TCP 連線至 169.254.169.254 (透過 port 80) 以及連線至 168.63.129.16 (透過 port 8037) 的連線能力。 代理程式會使用這些 IP 位址,來與 Azure 平台進行通訊。
網際網路連線:網路監看員 Agent 需要網路連線才能正常運作。 例如,它需要連線至您的儲存體帳戶,才能上傳封包擷取。
一個運行支援作業系統的 Azure 虛擬機(VM)。 欲了解更多資訊,請參閱 支援作業系統。
輸出 TCP 連線至 169.254.169.254 (透過 port 80) 以及連線至 168.63.129.16 (透過 port 8037) 的連線能力。 代理程式會使用這些 IP 位址,來與 Azure 平台進行通訊。
網際網路連線:網路監看員 Agent 需要網路連線才能正常運作。 例如,它需要連線至您的儲存體帳戶,才能上傳封包擷取。
Azure Cloud Shell 或 Azure PowerShell。
本文中的步驟會在 Azure Cloud Shell 中以互動方式執行 Azure PowerShell Cmdlet。 要執行 Cloud Shell 中的指令,請在程式碼區塊右上角選擇 Open Cloud Shell。 選擇 Copy 複製程式碼,然後貼上到 Cloud Shell 執行。 你也可以在 Azure 入口網站內執行 Cloud Shell。
你也可以將 Azure PowerShell 安裝到本地來運行命令。 如果你在本地執行 PowerShell,請使用 Connect-AzAccount cmdlet 登入Azure。
一個運行支援作業系統的 Azure 虛擬機(VM)。 欲了解更多資訊,請參閱 支援作業系統。
輸出 TCP 連線至 169.254.169.254 (透過 port 80) 以及連線至 168.63.129.16 (透過 port 8037) 的連線能力。 代理程式會使用這些 IP 位址,來與 Azure 平台進行通訊。
網際網路連線:網路監看員 Agent 需要網路連線才能正常運作。 例如,它需要連線至您的儲存體帳戶,才能上傳封包擷取。
Azure Cloud Shell 或 Azure CLI。
本文中的步驟會在 Azure Cloud Shell 中以互動方式執行 Azure CLI 命令。 要執行 Cloud Shell 中的指令,請在程式碼區塊右上角選擇 Open Cloud Shell。 選擇 Copy 來複製程式碼,然後貼上到 Cloud Shell 執行。 你也可以在 Azure 入口網站內執行 Cloud Shell。
您也可以在本機安裝 Azure CLI 以執行命令。 如果您在本機執行 Azure CLI,請使用 az login 命令登入 Azure。
一個運行支援作業系統的 Azure 虛擬機(VM)。 欲了解更多資訊,請參閱 支援作業系統。
輸出 TCP 連線至 169.254.169.254 (透過 port 80) 以及連線至 168.63.129.16 (透過 port 8037) 的連線能力。 代理程式會使用這些 IP 位址,來與 Azure 平台進行通訊。
網際網路連線:網路監看員 Agent 需要網路連線才能正常運作。 例如,它需要連線至您的儲存體帳戶,才能上傳封包擷取。
在本機安裝 Azure PowerShell 或 Azure CLI 以部署範本。
支援的作業系統
你可以在以下作業系統上安裝 網路監看員 Agent for Windows 擴充功能:
- Windows Server 2012、2012 R2、2016、2019、2022 及 2025 版本。
- Windows 10 和 Windows 11 作業系統版本。
你可以在以下 Linux 發行版上安裝 網路監看員 Agent 擴充功能:
| 散發 |
版本 |
| 阿爾瑪Linux |
9.2 |
| Azure Linux |
2.0 |
| CentOS 1作業系統 |
6.10 和 7 |
| Debian |
7 和 8 |
| openSUSE Leap |
42.3+ |
| Oracle Linux |
6.10 2、7、8 與 9+ |
| Red Hat Enterprise Linux (RHEL) |
6.10 3、7、8 與 9.2 |
| 洛基Linux |
9.1 |
| SUSE Linux Enterprise Server (SLES) |
12 和 15 (SP2、SP3 和 SP4) |
| Ubuntu |
16+ |
1 CentOS Linux 於 2024 年 6 月 30 日結束其生命週期(EOL)。 欲了解更多資訊,請參閱 CentOS 終止服務指引。
2 Oracle Linux 6.X 版的延長生命週期 (ELS) 支援於 2024 年 7 月 1 日結束。
3 Red Hat Enterprise Linux 6.X 版的延長生命週期 (ELS) 支援於 2024 年 6 月 30 日結束。
Note
由於發行版特有的核心層級限制,目前 Oracle Linux 的 網路監看員 代理程式不支援網際網路控制訊息協定(ICMP)監控功能。
擴展架構
下列 JSON 顯示網路監看員代理程式擴充功能的結構描述。 這個擴充功能不需要也不支援任何使用者提供的設定,且依賴其預設設定。
{
"name": "[concat(parameters('vmName'), '/AzureNetworkWatcherExtension')]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2023-03-01",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"
],
"properties": {
"autoUpgradeMinorVersion": true,
"publisher": "Microsoft.Azure.NetworkWatcher",
"type": "NetworkWatcherAgentWindows",
"typeHandlerVersion": "1.4"
}
}
{
"name": "[concat(parameters('vmName'), '/AzureNetworkWatcherExtension')]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2023-03-01",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('vmName'))]"
],
"properties": {
"autoUpgradeMinorVersion": true,
"publisher": "Microsoft.Azure.NetworkWatcher",
"type": "NetworkWatcherAgentLinux",
"typeHandlerVersion": "1.4"
}
}
列出已安裝的延伸模組
從 Azure 入口網站的虛擬機頁面,你可以依照以下步驟查看已安裝的擴充功能:
在 [設定] 下方,選取 [擴充功能 + 應用程式]。
在 [延伸模組] 索引標籤中,您可以看到虛擬機器上所有已安裝的延伸模組。 如果清單很長,請使用搜尋框來篩選。
使用 Get-AzVMExtension 指令檔來列出虛擬機器上所有已安裝的擴充功能。
# List the installed extensions on the virtual machine.
Get-AzVMExtension -ResourceGroupName 'myResourceGroup' -VMName 'myVM' | format-table Name, Publisher, ExtensionType, AutoUpgradeMinorVersion, EnableAutomaticUpgrade
Cmdlet 的輸出內容會列出已安裝的延伸模組:
Name Publisher ExtensionType AutoUpgradeMinorVersion EnableAutomaticUpgrade
---- --------- ------------- ----------------------- ----------------------
AzureNetworkWatcherExtension Microsoft.Azure.NetworkWatcher NetworkWatcherAgentWindows True True
Name Publisher ExtensionType AutoUpgradeMinorVersion EnableAutomaticUpgrade
---- --------- ------------- ----------------------- ----------------------
AzureNetworkWatcherExtension Microsoft.Azure.NetworkWatcher NetworkWatcherAgentLinux True True
使用 az vm 擴充功能清單 指令,列出虛擬機器上所有已安裝的擴充功能。
# List the installed extensions on the virtual machine.
az vm extension list --resource-group 'myResourceGroup' --vm-name 'myVM' --out table
該命令的輸出內容會列出已安裝的延伸模組:
Name ProvisioningState Publisher Version AutoUpgradeMinorVersion
---------------------------- ------------------- ------------------------------ --------- -------------------------
AzureNetworkWatcherExtension Succeeded Microsoft.Azure.NetworkWatcher 1.4 True
安裝網路監看員代理程式 VM 延伸模組
從 Azure 入口網站中的虛擬機器頁面,您可以遵循下列步驟來安裝網路監看員代理程式 VM 延伸模組:
在 [設定] 下方,選取 [擴充功能 + 應用程式]。
選擇 + Add,搜尋 網路監看員 Agent,然後安裝。 若已安裝延伸模組,您可以在延伸模組清單中看到該項目。
在「安裝擴充功能」的搜尋框中,輸入 網路監看員 Agent,從列表中選擇與你作業系統相符的擴充功能,然後選擇「下一步」。
選取 檢閱 + 建立,然後選取 建立。
使用 Set-AzVMExtension cmdlet 在虛擬機器上安裝 網路監看員 Agent VM 擴充功能:
# Install Network Watcher Agent for Windows on the virtual machine.
Set-AzVMExtension -Name 'AzureNetworkWatcherExtension' -Publisher 'Microsoft.Azure.NetworkWatcher' -ExtensionType 'NetworkWatcherAgentWindows' -EnableAutomaticUpgrade 1 -TypeHandlerVersion '1.4' -ResourceGroupName 'myResourceGroup' -VMName 'myVM'
# Install Network Watcher Agent for Linux on the virtual machine.
Set-AzVMExtension -Name 'AzureNetworkWatcherExtension' -Publisher 'Microsoft.Azure.NetworkWatcher' -ExtensionType 'NetworkWatcherAgentLinux' -EnableAutomaticUpgrade 1 -TypeHandlerVersion '1.4' -ResourceGroupName 'myResourceGroup' -VMName 'myVM'
安裝完成後,你會看到以下輸出:
RequestId IsSuccessStatusCode StatusCode ReasonPhrase
--------- ------------------- ---------- ------------
True OK
使用 az vm extension set 指令,在虛擬機器上安裝 網路監看員 Agent VM 擴充功能:
# Install Network Watcher Agent for Windows on the virtual machine.
az vm extension set --name 'NetworkWatcherAgentWindows' --extension-instance-name 'AzureNetworkWatcherExtension' --publisher 'Microsoft.Azure.NetworkWatcher' --enable-auto-upgrade 'true' --version '1.4' --resource-group 'myResourceGroup' --vm-name 'myVM'
# Install Network Watcher Agent for Linux on the virtual machine.
az vm extension set --name 'NetworkWatcherAgentLinux' --extension-instance-name 'AzureNetworkWatcherExtension' --publisher 'Microsoft.Azure.NetworkWatcher' --enable-auto-upgrade 'true' --version '1.4' --resource-group 'myResourceGroup' --vm-name 'myVM'
請使用以下 Azure Resource Manager 範本(ARM 範本)在虛擬機上安裝 網路監看員 Agent VM 擴充功能:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
}
},
"resources": [
{
"name": "[concat(parameters('vmName'), '/AzureNetworkWatcherExtension')]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2024-07-01",
"location": "[resourceGroup().location]",
"properties": {
"autoUpgradeMinorVersion": true,
"publisher": "Microsoft.Azure.NetworkWatcher",
"type": "NetworkWatcherAgentWindows",
"typeHandlerVersion": "1.4"
}
}
]
}
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
}
},
"resources": [
{
"name": "[concat(parameters('vmName'), '/AzureNetworkWatcherExtension')]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2024-07-01",
"location": "[resourceGroup().location]",
"properties": {
"autoUpgradeMinorVersion": true,
"publisher": "Microsoft.Azure.NetworkWatcher",
"type": "NetworkWatcherAgentLinux",
"typeHandlerVersion": "1.4"
}
}
]
}
您可以使用 Azure PowerShell 或 Azure CLI 來部署 Resource Manager 範本:
# Deploy the JSON template file using Azure PowerShell.
New-AzResourceGroupDeployment -ResourceGroupName 'myResourceGroup' -TemplateFile 'agent.json'
# Deploy the JSON template file using the Azure CLI.
az deployment group create --resource-group 'myResourceGroup' --template-file 'agent.json'
更新 網路監看員 代理虛擬機擴充功能
檢查擴充功能版本
您可以使用 Azure 入口網站、Azure CLI 或 PowerShell 來檢查擴充功能版本。
在 Azure 入口網站中,前往 VM 的擴充功能 + 應用程式。
在擴充功能列表中,請檢查 AzureNetworkWatcherExtension 的版本欄位。 若有新版本可用,最新版本欄會顯示(更新可用)。
使用 Get-AzVM 指令檔檢查已安裝的擴充套件版本:
(Get-AzVM -ResourceGroupName 'myResourceGroup' -Name 'myVM' -Status).Extensions | Where-Object { $_.Name -eq 'AzureNetworkWatcherExtension' } | Select-Object Name, TypeHandlerVersion
使用 Get-AzVMExtensionImage 指令檔來查找你虛擬機作業系統及區域中最新可用的擴充功能版本:
Get-AzVMExtensionImage -Location '<region>' -PublisherName 'Microsoft.Azure.NetworkWatcher' -Type 'NetworkWatcherAgentWindows' | Sort-Object -Property { [Version]$_.Version } -Descending | Select-Object -First 1
Get-AzVMExtensionImage -Location '<region>' -PublisherName 'Microsoft.Azure.NetworkWatcher' -Type 'NetworkWatcherAgentLinux' | Sort-Object -Property { [Version]$_.Version } -Descending | Select-Object -First 1
使用 az vm get-instance-view 指令檢查擴充套件已安裝的版本:
az vm get-instance-view --resource-group 'myResourceGroup' --name 'myVM' --query "extensions[?name=='AzureNetworkWatcherExtension'].typeHandlerVersion" --output tsv
請使用 az vm 擴充功能 image list 指令,找出你虛擬機作業系統中該擴充功能的最新可用版本:
az vm extension image list --name 'NetworkWatcherAgentWindows' --publisher 'Microsoft.Azure.NetworkWatcher' --latest
az vm extension image list --name 'NetworkWatcherAgentLinux' --publisher 'Microsoft.Azure.NetworkWatcher' --latest
Note
最新版的網路監看員擴充功能為 1.4.4011.1。
啟用自動升級
自動升級讓 Azure 平台無需手動介入即可將擴充功能更新到最新版本。 請依照以下步驟檢查自動升級是否啟用,若未啟用也請啟用。
在 Azure 入口網站的虛擬機設定中,選擇擴充功能 + 應用程式。
從擴充功能列表中選擇 AzureNetworkWatcherExtension ,並檢查 自動升級狀態 欄位。
如果顯示 為停用,請從工具列選擇 啟用自動升級 。
選取是以確認。
使用 Get-AzVMExtension cmdlet 檢查是否啟用自動升級:
Get-AzVMExtension -ResourceGroupName 'myResourceGroup' -VMName 'myVM' -Name 'AzureNetworkWatcherExtension' | Select-Object Name, EnableAutomaticUpgrade
若 EnableAutomaticUpgrade 為 False,請使用 Set-AzVMExtension Cmdlet 啟用。
Set-AzVMExtension -ResourceGroupName 'myResourceGroup' -VMName 'myVM' -Name 'AzureNetworkWatcherExtension' -Publisher 'Microsoft.Azure.NetworkWatcher' -ExtensionType 'NetworkWatcherAgentWindows' -EnableAutomaticUpgrade $true
Set-AzVMExtension -ResourceGroupName 'myResourceGroup' -VMName 'myVM' -Name 'AzureNetworkWatcherExtension' -Publisher 'Microsoft.Azure.NetworkWatcher' -ExtensionType 'NetworkWatcherAgentLinux' -EnableAutomaticUpgrade $true
使用 az vm 擴充功能 show 指令檢查是否啟用自動升級:
az vm extension show --resource-group 'myResourceGroup' --vm-name 'myVM' --name 'AzureNetworkWatcherExtension' --query 'enableAutomaticUpgrade'
如果該命令傳回 false,請使用 az vm extension set 命令加以啟用:
az vm extension set --resource-group 'myResourceGroup' --vm-name 'myVM' --name 'NetworkWatcherAgentWindows' --publisher 'Microsoft.Azure.NetworkWatcher' --enable-auto-upgrade 'true'
az vm extension set --resource-group 'myResourceGroup' --vm-name 'myVM' --name 'NetworkWatcherAgentLinux' --publisher 'Microsoft.Azure.NetworkWatcher' --enable-auto-upgrade 'true'
請使用以下 Azure Resource Manager 範本(ARM 範本)來啟用 網路監看員 Agent VM 擴充功能的自動升級:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
}
},
"resources": [
{
"name": "[concat(parameters('vmName'), '/AzureNetworkWatcherExtension')]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2024-07-01",
"location": "[resourceGroup().location]",
"properties": {
"autoUpgradeMinorVersion": true,
"enableAutomaticUpgrade": true,
"publisher": "Microsoft.Azure.NetworkWatcher",
"type": "NetworkWatcherAgentWindows",
"typeHandlerVersion": "1.4"
}
}
]
}
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
}
},
"resources": [
{
"name": "[concat(parameters('vmName'), '/AzureNetworkWatcherExtension')]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2024-07-01",
"location": "[resourceGroup().location]",
"properties": {
"autoUpgradeMinorVersion": true,
"enableAutomaticUpgrade": true,
"publisher": "Microsoft.Azure.NetworkWatcher",
"type": "NetworkWatcherAgentLinux",
"typeHandlerVersion": "1.4"
}
}
]
}
您可以使用 Azure PowerShell 或 Azure CLI 來部署 Resource Manager 範本:
# Deploy the JSON template file using Azure PowerShell.
New-AzResourceGroupDeployment -ResourceGroupName 'myResourceGroup' -TemplateFile 'agent.json'
# Deploy the JSON template file using the Azure CLI.
az deployment group create --resource-group 'myResourceGroup' --template-file 'agent.json'
Note
啟用自動升級後,Azure 會自動更新擴充功能,無需重啟虛擬機器。 這個流程在新版本發布後可能需要長達30天。
手動更新
在 Azure 入口網站的虛擬機設定中,選擇擴充功能 + 應用程式。
從擴充功能列表中選擇 AzureNetworkWatcherExtension ,然後從工具列選擇 「更新 」。
選取是以確認。
更新結束後, 版本 與 最新版本 欄位顯示相同的版本號。
如果更新後沒有套用最新版本,請移除擴充功能並重新安裝:
- 從延伸模組清單中選取 AzureNetworkWatcherExtension,然後選取 [解除安裝]。
- 選擇 + 新增,搜尋 網路監看員 Agent,然後重新安裝。 平台會自動安裝最新可用版本。 更多資訊請參閱安裝 網路監看員 Agent VM 擴充功能。
使用 Set-AzVMExtension-ForceRerun 指令檔搭配參數,即可重新套用擴充功能,且不卸載。 每次執行指令時,該 -ForceRerun 值必須與當前值不同,因此使用會變動的值,例如當前日期和時間:
Set-AzVMExtension -ResourceGroupName 'myResourceGroup' -VMName 'myVM' -Name 'AzureNetworkWatcherExtension' -Publisher 'Microsoft.Azure.NetworkWatcher' -Type 'NetworkWatcherAgentWindows' -ForceRerun (Get-Date -Format o)
Set-AzVMExtension -ResourceGroupName 'myResourceGroup' -VMName 'myVM' -Name 'AzureNetworkWatcherExtension' -Publisher 'Microsoft.Azure.NetworkWatcher' -Type 'NetworkWatcherAgentLinux' -ForceRerun (Get-Date -Format o)
如果這個條件沒有更新擴充功能,請移除它並重新安裝以取得最新版本:
Remove-AzVMExtension -ResourceGroupName 'myResourceGroup' -VMName 'myVM' -Name 'AzureNetworkWatcherExtension'
Set-AzVMExtension -ResourceGroupName 'myResourceGroup' -VMName 'myVM' -Name 'AzureNetworkWatcherExtension' -Publisher 'Microsoft.Azure.NetworkWatcher' -Type 'NetworkWatcherAgentWindows'
Set-AzVMExtension -ResourceGroupName 'myResourceGroup' -VMName 'myVM' -Name 'AzureNetworkWatcherExtension' -Publisher 'Microsoft.Azure.NetworkWatcher' -Type 'NetworkWatcherAgentLinux'
使用 az vm extension set 命令搭配 --force-update 參數,在不解除安裝擴充功能的情況下重新套用該擴充功能:
az vm extension set --resource-group 'myResourceGroup' --vm-name 'myVM' --name 'NetworkWatcherAgentWindows' --publisher 'Microsoft.Azure.NetworkWatcher' --force-update
az vm extension set --resource-group 'myResourceGroup' --vm-name 'myVM' --name 'NetworkWatcherAgentLinux' --publisher 'Microsoft.Azure.NetworkWatcher' --force-update
如果這個條件沒有更新擴充功能,請移除它並重新安裝以取得最新版本:
az vm extension delete --resource-group 'myResourceGroup' --vm-name 'myVM' --name 'AzureNetworkWatcherExtension'
az vm extension set --resource-group 'myResourceGroup' --vm-name 'myVM' --name 'NetworkWatcherAgentWindows' --publisher 'Microsoft.Azure.NetworkWatcher'
az vm extension set --resource-group 'myResourceGroup' --vm-name 'myVM' --name 'NetworkWatcherAgentLinux' --publisher 'Microsoft.Azure.NetworkWatcher'
請使用以下 Azure Resource Manager 範本(ARM 範本)重新套用擴充功能。 將 typeHandlerVersion 參數更新為你在 檢查你的擴充功能版本 中找出的最新版本,然後重新部署範本:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"typeHandlerVersion": {
"type": "string"
}
},
"resources": [
{
"name": "[concat(parameters('vmName'), '/AzureNetworkWatcherExtension')]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2024-07-01",
"location": "[resourceGroup().location]",
"properties": {
"autoUpgradeMinorVersion": true,
"publisher": "Microsoft.Azure.NetworkWatcher",
"type": "NetworkWatcherAgentWindows",
"typeHandlerVersion": "[parameters('typeHandlerVersion')]"
}
}
]
}
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string"
},
"typeHandlerVersion": {
"type": "string"
}
},
"resources": [
{
"name": "[concat(parameters('vmName'), '/AzureNetworkWatcherExtension')]",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2024-07-01",
"location": "[resourceGroup().location]",
"properties": {
"autoUpgradeMinorVersion": true,
"publisher": "Microsoft.Azure.NetworkWatcher",
"type": "NetworkWatcherAgentLinux",
"typeHandlerVersion": "[parameters('typeHandlerVersion')]"
}
}
]
}
您可以使用 Azure PowerShell 或 Azure CLI 來部署 Resource Manager 範本:
# Deploy the JSON template file using Azure PowerShell.
New-AzResourceGroupDeployment -ResourceGroupName 'myResourceGroup' -TemplateFile 'agent.json' -typeHandlerVersion '<version>'
# Deploy the JSON template file using the Azure CLI.
az deployment group create --resource-group 'myResourceGroup' --template-file 'agent.json' --parameters typeHandlerVersion='<version>'
使用 PowerShell 腳本進行大規模更新
如果你有大規模部署,可以用 PowerShell 腳本一次更新訂閱中的多個虛擬機。 以下腳本會更新訂閱中所有過時虛擬機的 網路監看員 擴充功能:
<#
.SYNOPSIS
This script scans all VMs in the provided subscription and upgrades any out-of-date AzureNetworkWatcherExtensions to the latest available version.
.DESCRIPTION
This script is a no-op if AzureNetworkWatcherExtensions are already up to date.
Requires Azure PowerShell 4.2 or higher to be installed.
.EXAMPLE
.\UpdateVMAgentsInSub.ps1 -SubID aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e -NoUpdate
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string] $SubID,
[Parameter(Mandatory=$false)]
[Switch] $NoUpdate = $false
)
function Get-LatestExtensionVersion($location, $extensionType)
{
$latestImage = Get-AzVMExtensionImage -Location $location -PublisherName "Microsoft.Azure.NetworkWatcher" -Type $extensionType |
Sort-Object -Property { [Version]$_.Version } -Descending |
Select-Object -First 1
return $latestImage.Version
}
Write-Host "Scanning all VMs in the subscription: $($SubID)"
Set-AzContext -SubscriptionId $SubID
$vms = Get-AzVM
$foundVMs = $false
Write-Host "Starting VM search, this may take a while"
foreach ($vmName in $vms)
{
# Get Detailed VM info
$vm = Get-AzVM -ResourceGroupName $vmName.ResourceGroupName -Name $vmName.name -Status
$isitWindows = $vm.OsName -like "*Windows*"
$type = if ($isitWindows) { "NetworkWatcherAgentWindows" } else { "NetworkWatcherAgentLinux" }
$latestVersion = Get-LatestExtensionVersion -location $vmName.Location -extensionType $type
foreach ($extension in $vm.Extensions)
{
if ($extension.Name -eq "AzureNetworkWatcherExtension")
{
if ([Version]$extension.TypeHandlerVersion -lt [Version]$latestVersion)
{
$foundVMs = $true
if (-not ($NoUpdate))
{
Write-Host "Found VM that needs to be updated: subscriptions/$($SubID)/resourceGroups/$($vm.ResourceGroupName)/providers/Microsoft.Compute/virtualMachines/$($vm.Name) -> Updating to $latestVersion " -NoNewline
Remove-AzVMExtension -ResourceGroupName $vm.ResourceGroupName -VMName $vm.Name -Name "AzureNetworkWatcherExtension" -Force
Write-Host "... " -NoNewline
Set-AzVMExtension -ResourceGroupName $vm.ResourceGroupName -Location $vmName.Location -VMName $vm.Name -Name "AzureNetworkWatcherExtension" -Publisher "Microsoft.Azure.NetworkWatcher" -Type $type -TypeHandlerVersion $latestVersion
Write-Host "Done"
}
else
{
Write-Host "Found $(if ($isitWindows) {"Windows"} else {"Linux"}) VM that needs to be updated to $($latestVersion): subscriptions/$($SubID)/resourceGroups/$($vm.ResourceGroupName)/providers/Microsoft.Compute/virtualMachines/$($vm.Name)"
}
}
}
}
}
if ($foundVMs)
{
Write-Host "Finished $(if ($NoUpdate) {"searching"} else {"updating"}) out of date AzureNetworkWatcherExtension on VMs"
}
else
{
Write-Host "All AzureNetworkWatcherExtensions up to date"
}
解除安裝網路監看員代理程式 VM 延伸模組
從 Azure 入口網站中的虛擬機器頁面,您可以遵循下列步驟來解除安裝網路監看員代理程式 VM 延伸模組:
在 [設定] 下方,選取 [擴充功能 + 應用程式]。
從延伸模組清單中選取 AzureNetworkWatcherExtension,然後選取 [解除安裝]。
Note
您可能會看到網路監看員代理程式 VM 延伸模組的名稱與 AzureNetworkWatcherExtension 不同。
使用 Remove-AzVMExtension 指令檔,將虛擬機中的 網路監看員 Agent VM 擴充功能移除:
# Uninstall Network Watcher Agent VM extension.
Remove-AzVMExtension -Name 'AzureNetworkWatcherExtension' -ResourceGroupName 'myResourceGroup' -VMName 'myVM'
使用 az vm 擴充功能 delete 指令,將虛擬機器中的 網路監看員 Agent VM 擴充功能移除:
# Uninstall Network Watcher Agent VM extension.
az vm extension delete --name 'AzureNetworkWatcherExtension' --resource-group 'myResourceGroup' --vm-name 'myVM'
常見問題 (FAQ)
欲獲得關於 網路監看員 Agent 最常見問題的解答,請參閱 網路監看員 Agent 常見問題集。
相關內容