將 Azure 網路監看員 擴充功能更新為最新版本

Azure 網路監看員 是監視 Azure 網路的網路效能監視、診斷和分析服務。 網路監看員 代理程式虛擬機 (VM) 擴充功能是依需求擷取網路流量,以及在 Azure VM 上使用其他進階功能的需求。 線上監視器、連線疑難解答和封包擷取會使用它。

必要條件

  • 具有有效訂用帳戶的 Azure 帳戶。 如果您沒有訂用帳戶,請建立免費帳戶
  • 已安裝 網路監看員擴充功能的 Azure 虛擬機 (VM)。

最新版本

最新版的 網路監看員 延伸模組為 1.4.3206.1

識別最新版本

使用 az vm extension image list 命令來識別 VM 作業系統 網路監看員 延伸模組的最新版本。

# Identify latest version of Network Watcher extension for Linux.
az vm extension image list --name 'NetworkWatcherAgentLinux' --publisher 'Microsoft.Azure.NetworkWatcher' --latest --location 'eastus'

使用 PowerShell 腳本更新擴充功能

如果您有大型部署,請使用PowerShell腳本一次更新多個 VM。 下列 PowerShell 腳本會更新訂用帳戶中所有 Windows VM 的 網路監看員 擴充功能:

<# 
    .SYNOPSIS 
    This script will scan all VMs in the provided subscription and upgrade any out of date AzureNetworkWatcherExtensions  
    .DESCRIPTION 
    This script should be no-op if AzureNetworkWatcherExtensions are up to date 
    Requires Azure PowerShell 4.2 or higher to be installed (e.g. Install-Module AzureRM). 
    .EXAMPLE 
    .\UpdateVMAgentsInSub.ps1 -SubID F4BC4873-5DAB-491E-B713-1358EF4992F2 -NoUpdate 
#>
 
[CmdletBinding()] 
param( 
    [Parameter(Mandatory=$true)] 
    [string] $SubID, 
    [Parameter(Mandatory=$false)] 
    [Switch] $NoUpdate = $false, 
    [Parameter(Mandatory=$false)] 
    [string] $MinVersion = "1.4.2573.1" 
)  
function NeedsUpdate($version) 
{ 
    if ([Version]$version -lt [Version]$MinVersion)
	{ 
        $lessThan = $true 
    }else{ 
        $lessThan = $false 
    } 
    return $lessThan 
}   
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*"
 
    foreach ($extension in $vm.Extensions) 
    { 
        if ($extension.Name -eq "AzureNetworkWatcherExtension") 
        { 
            if (NeedsUpdate($extension.TypeHandlerVersion)) 
            { 
                $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 " -NoNewline 
                    Remove-AzVMExtension -ResourceGroupName $vm.ResourceGroupName -VMName $vm.Name -Name "AzureNetworkWatcherExtension" -Force 
                    Write-Host "... " -NoNewline 
                    $type = if ($isitWindows) { "NetworkWatcherAgentWindows" } else { "NetworkWatcherAgentLinux" } 
                    Set-AzVMExtension -ResourceGroupName $vm.ResourceGroupName -Location $vmName.Location -VMName $vm.Name -Name "AzureNetworkWatcherExtension" -Publisher "Microsoft.Azure.NetworkWatcher" -Type $type -typeHandlerVersion $MinVersion
                    Write-Host "Done" 
                } 
                else 
                { 
                    Write-Host "Found $(if ($isitWindows) {"Windows"} else {"Linux"}) VM that needs to be updated: 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" 
}

手動更新您的延伸模組

若要更新擴充功能,您必須知道您的延伸模組版本。

檢查您的擴充功能版本

您可以使用 Azure 入口網站、Azure CLI 或 PowerShell 來檢查擴充功能版本。

使用 Azure 入口網站

  1. 移至 Azure 入口網站 中 VM 的 [擴充功能] 窗格。
  2. 選取 AzureNetworkWatcher 延伸模組以查看詳細資料窗格。
  3. [版本 ] 欄位中找出版本號碼。  

使用 Azure CLI

從 Azure CLI 提示字元執行下列命令:

az vm get-instance-view --resource-group  "SampleRG" --name "Sample-VM"

在輸出中找出 「AzureNetworkWatcherExtension」,並從輸出中的 「TypeHandlerVersion」 字段中識別版本號碼。 

擴充功能的相關信息會出現在 JSON 輸出中多次。 擴充功能的完整版本號碼可在 [擴充功能] 區塊下取得。

您應該會看到如下所示的內容: Azure CLI 螢幕快照

使用 PowerShell

從 PowerShell 提示字元執行下列命令:

Get-AzVM -ResourceGroupName "SampleRG" -Name "Sample-VM" -Status

在輸出中找出 Azure 網路監看員 延伸模組,並從輸出中的 「TypeHandlerVersion」 欄位中識別版本號碼。  

您應該會看到如下所示的內容: PowerShell 螢幕快照

更新延伸模組

如果您的版本低於上述最新版本,請使用下列任何選項來更新您的擴充功能。

選項 1:使用 PowerShell

執行下列命令:

#Linux command
Set-AzVMExtension -ResourceGroupName "myResourceGroup1" -Location "WestUS" -VMName "myVM1" -Name "AzureNetworkWatcherExtension" -Publisher "Microsoft.Azure.NetworkWatcher" -Type "NetworkWatcherAgentLinux"

#Windows command
Set-AzVMExtension -ResourceGroupName "myResourceGroup1" -Location "WestUS" -VMName "myVM1" -Name " AzureNetworkWatcherExtension" -Publisher "Microsoft.Azure.NetworkWatcher" -Type "NetworkWatcherAgentWindows" -ForceRerun "True"

如果這無法運作。 使用下列步驟再次移除並安裝擴充功能,以安裝最新版本。

拿掉延伸模組

#Same command for Linux and Windows
Remove-AzVMExtension -ResourceGroupName "SampleRG" -VMName "Sample-VM" -Name "AzureNetworkWatcherExtension"

再次安裝擴充功能

#Linux command
Set-AzVMExtension -ResourceGroupName "SampleRG" -Location "centralus" -VMName "Sample-VM" -Name "AzureNetworkWatcherExtension" -Publisher "Microsoft.Azure.NetworkWatcher" -Type "NetworkWatcherAgentLinux" -typeHandlerVersion "1.4"

#Windows command
Set-AzVMExtension -ResourceGroupName "SampleRG" -Location "centralus" -VMName "Sample-VM" -Name "AzureNetworkWatcherExtension" -Publisher "Microsoft.Azure.NetworkWatcher" -Type "NetworkWatcherAgentWindows" -typeHandlerVersion "1.4"

選項 2:使用 Azure CLI

強制升級。

#Linux command
az vm extension set --resource-group "myResourceGroup1" --vm-name "myVM1" --name "NetworkWatcherAgentLinux" --publisher "Microsoft.Azure.NetworkWatcher" --force-update

#Windows command
az vm extension set --resource-group "myResourceGroup1" --vm-name "myVM1" --name "NetworkWatcherAgentWindows" --publisher "Microsoft.Azure.NetworkWatcher" --force-update

如果無法運作,請再次移除並安裝擴充功能,並遵循下列步驟來自動新增最新版本。

拿掉延伸模組。

#Same for Linux and Windows
az vm extension delete --resource-group "myResourceGroup1" --vm-name "myVM1" -n "AzureNetworkWatcherExtension"

再次安裝擴充功能。

#Linux command
az vm extension set --resource-group "DALANDEMO" --vm-name "Linux-01" --name "NetworkWatcherAgentLinux" --publisher "Microsoft.Azure.NetworkWatcher"

#Windows command
az vm extension set --resource-group "DALANDEMO" --vm-name "Linux-01" --name "NetworkWatcherAgentWindows" --publisher "Microsoft.Azure.NetworkWatcher"

選項3:重新啟動 VM

如果您已將 網路監看員 擴充功能的自動升級設定為 true,請將 VM 安裝重新啟動至最新的擴充功能。

支援

如果您在本文中的任何時間點需要更多協助,請參閱適用於LinuxWindows 的 網路監看員擴充功能檔。 您也可以連絡 MSDN Azure 和 Stack Overflow 論壇上的 Azure 專家。 或者,提出 Azure 支援 事件。 移至 Azure 支援 網站,然後選取 [取得支援]。 如需使用 Azure 支援的資訊,請參閱 Microsoft Azure 支援常見問題集