在将修补程序或扩展应用到 ESX/ESXi 主机之前,可能要通过将修补程序或扩展应用到测试环境中的主机来测试修补程序和扩展。然后,可以使用 Update Manager PowerCLI 将已测试过的基准导出到另一 Update Manager 服务器实例,并将修补程序和扩展应用到其他主机。
Update Manager PowerCLI 是在 Windows PowerShell 基础上构建的命令行和脚本工具,它提供了一组用于管理和自动化 Update Manager 的 cmdlet。有关安装和使用 Update Manager PowerCLI 的详细信息,请参见《VMware vSphere Update Manager PowerCLI 安装和管理指南》。
此工作流程描述了如何使用一个 Update Manager 实例测试修补程序,以及如何将包含已测试过的修补程序的修补程序基准导出到另一 Update Manager 实例。
创建固定主机修补程序基准。
创建包含要测试的修补程序的固定修补程序基准。新的修补程序下载到 Update Manager 修补程序存储库时,固定修补程序基准不更改其内容。可以在 Update Manager“管理视图”的基准和组选项卡中创建固定修补程序基准。有关详细信息和详细步骤,请参见创建固定修补程序基准。
将修补程序基准附加到包含要扫描或修复的主机的容器对象。
容器对象可以是文件夹、群集或数据中心。可以在“Update Manager 合规性”视图中将基准和基准组附加到对象。有关将基准和基准组附加到 vSphere 对象的详细信息,请参见将基准和基准组附加到对象。
扫描容器对象。
将基准附加到所选容器对象后,必须对该容器对象进行扫描,以查看容器中主机的合规性状况。可以手动扫描所选对象以立即开始扫描。有关如何手动扫描主机的详细说明,请参见手动启动 ESX/ESXi 主机的扫描。
也可以通过调度扫描任务,在您方便的时候扫描容器对象中的主机。有关调度扫描的更多信息和详细说明,请参见调度扫描。
查看在“Update Manager Client 合规性”视图中显示的扫描结果。
有关查看扫描结果的详细步骤和合规性状况的详细信息,请参见查看 vSphere 对象的扫描结果及合规性状况。
(可选)将附加基准中的修补程序转储到要更新的主机。
在应用修补程序前,可以转储修补程序,并将其从 Update Manager 服务器复制到主机。转储修补程序会加快修复过程,并有助于最大程度地缩短主机在修复过程中的停机时间。有关将修补程序和扩展转储到主机的详细步骤,请参见将修补程序和扩展转储到 ESX/ESXi 主机。
修复容器对象。
修复处于“不合规”状况的主机,以使主机与附加的基准合规。有关根据修补程序或扩展基准修复主机的详细信息,请参见根据修补程序基准或扩展基准修复主机。
从用于测试修补程序的 Update Manager 服务器导出修补程序基准,并将这些修补程序基准导入到另一 Update Manager 服务器中。
可以通过使用 Update Manager PowerCLI 脚本将修补程序基准从一个 Update Manager 服务器导出和导入到另一服务器。以下示例脚本可在 $destinationServer 上创建基准 MyBaseline 的副本。
注:此脚本可用于固定和动态修补程序基准以及扩展基准。
# $destinationServer = Connect-VIServer <ip_address_of_the_destination_server> # $sourceServer = Connect-VIServer <ip_address_of_the_source_server> # $baselines = Get-PatchBaseline MyBaseline -Server $sourceServer # ExportImportBaselines.ps1 $baselines $destinationServer Param([VMware.VumAutomation.Types.Baseline[]] $baselines, [VMware.VimAutomation.Types.VIServer[]]$destinationServers) $ConfirmPreference = 'None' $includePatches = @() $excludePatches = @() function ExtractPatchesFromServer([VMware.VumAutomation.Types.Patch[]]$patches, [VMware.VimAutomation.Types.VIServer]$destinationServer){ $result = @() if ($patches -ne $null){ foreach($patch in $patches){ $extractedPatches = Get-Patch -Server $destinationServer -SearchPhrase $patch.Name if ($extractedPatches -eq $null){ Write-Warning -Message "Patch '$($patch.Name)' is not available on the server $destinationServer" } else { $isFound = $false foreach ($newPatch in $extractedPatches){ if ($newPatch.IdByVendor -eq $patch.IdByVendor){ $result += $newPatch $isFound = $true } } if ($isFound -eq $false) { Write-Warning -Message "Patch '$($patch.Name)' with VendorId '$($patch.IdByVendor)' is not available on the server $destinationServer" } } } } return .$result; } function CreateStaticBaseline([VMware.VumAutomation.Types.Baseline]$baseline,[VMware.VimAutomation.Types.VIServer]$destinationServer){ $includePatches = ExtractPatchesFromServer $baseline.CurrentPatches $destinationServer if ($includePatches.Count -lt 1){ write-error "Static baseline '$($baseline.Name)' can't be imported.No one of the patches it contains are available on the server $destinationServer" } else { $command = 'New-PatchBaseline -Server $destinationServer -Name $baseline.Name -Description $baseline.Description -Static -TargetType $baseline.TargetType -IncludePatch $includePatches' if ($baseline.IsExtension) { $command += ' -Extension' } Invoke-Expression $command } } function CreateDynamicBaseline([VMware.VumAutomation.Types.Baseline]$baseline,[VMware.VimAutomation.Types.VIServer]$destinationServer) { if ($baseline.BaselineContentType -eq 'Dynamic'){ $command = 'New-PatchBaseline -Server $destinationServer -Name $baseline.Name -Description $baseline.Description -TargetType $baseline.TargetType -Dynamic -SearchPatchStartDate $baseline.SearchPatchStartDate - SearchPatchEndDate $baseline.SearchPatchEndDate -SearchPatchProduct $baseline.SearchPatchProduct -SearchPatchSeverity $baseline.SearchPatchSeverity -SearchPatchVendor $baseline.SearchPatchVendor' } elseif ($baseline.BaselineContentType -eq 'Both'){ $includePatches = ExtractPatchesFromServer $baseline.InclPatches $destinationServer $excludePatches = ExtractPatchesFromServer $baseline.ExclPatches $destinationServer $command = 'New-PatchBaseline -Server $destinationServer -Name $baseline.Name -Description $baseline.Description -TargetType $baseline.TargetType -Dynamic -SearchPatchStartDate $baseline.SearchPatchStartDate -SearchPatchEndDate $baseline.SearchPatchEndDate -SearchPatchProduct $baseline.SearchPatchProduct -SearchPatchSeverity $baseline.SearchPatchSeverity -SearchPatchVendor $baseline.SearchPatchVendor' if ($includePatches.Count -gt 0){ $command += ' -IncludePatch $includePatches' } if ($excludePatches.Count -gt 0){ $command += ' -ExcludePatch $excludePatches' } } #check for null because there is known issue for creating baseline with null SearchPatchPhrase if ($baseline.SearchPatchPhrase -ne $null){ $command += ' -SearchPatchPhrase $baseline.SearchPatchPhrase' } Invoke-Expression $command } foreach ($destinationServer in $destinationServers) { if ($baselines -eq $null) { Write-Error "The baselines parameter is null" } else { foreach($baseline in $baselines){ if ($baseline.GetType().FullName -eq 'VMware.VumAutomation.Types.PatchBaselineImpl'){ Write-Host "Import '" $baseline.Name "' to the server $destinationServer" if($baseline.BaselineContentType -eq 'Static'){ CreateStaticBaseline $baseline $destinationServer } else { CreateDynamicBaseline $baseline $destinationServer } } else { Write-Warning -Message "Baseline '$($baseline.Name)' is not patch baseline and will be skipped." } } } }
现在,您已将测试过的基准导出到另一 Update Manager 服务器。
通过使用将测试过的修补程序基准导出到的 Update Manager 服务器实例,将修补程序应用到 ESX/ESXi 主机。