您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure 虚拟机中 SQL Server 的自动修补 (Resource Manager)Automated Patching for SQL Server in Azure Virtual Machines (Resource Manager)

自动修补为运行 SQL Server 的 Azure 虚拟机建立一个维护时段。Automated Patching establishes a maintenance window for an Azure Virtual Machine running SQL Server. 只能在此维护时段内安装自动更新。Automated Updates can only be installed during this maintenance window. 对于 SQL Server,此限制可以确保在数据库的最佳可能时间发生系统更新和任何关联的重新启动。For SQL Server, this restriction ensures that system updates and any associated restarts occur at the best possible time for the database.

重要

仅安装标记为“重要”的 Windows 更新。Only Windows updates marked Important are installed. 必须手动安装其他 SQL Server 更新,如累积更新。Other SQL Server updates, such as Cumulative Updates, must be installed manually.

自动修补依赖于 SQL Server IaaS 代理扩展Automated Patching depends on the SQL Server IaaS Agent Extension.

先决条件Prerequisites

若要使用自动修补,请考虑以下先决条件:To use Automated Patching, consider the following prerequisites:

操作系统Operating System:

  • Windows Server 2008 R2Windows Server 2008 R2
  • Windows Server 2012Windows Server 2012
  • Windows Server 2012 R2Windows Server 2012 R2
  • Windows Server 2016Windows Server 2016

SQL Server 版本SQL Server version:

  • SQL Server 2008 R2SQL Server 2008 R2
  • SQL Server 2012SQL Server 2012
  • SQL Server 2014SQL Server 2014
  • SQL Server 2016SQL Server 2016
  • SQL Server 2017SQL Server 2017

Azure PowerShellAzure PowerShell:

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

备注

自动修补依赖 SQL Server IaaS 代理扩展。Automated Patching relies on the SQL Server IaaS Agent Extension. 当前的 SQL 虚拟机库映像默认添加此扩展。Current SQL virtual machine gallery images add this extension by default. 有关详细信息,请参阅 SQL Server IaaS 代理扩展For more information, see SQL Server IaaS Agent Extension.

设置Settings

下表描述了可为自动修补配置的选项。The following table describes the options that can be configured for Automated Patching. 实际配置步骤根据使用的是 Azure 门户还是 Azure Windows PowerShell 命令而有所不同。The actual configuration steps vary depending on whether you use the Azure portal or Azure Windows PowerShell commands.

设置Setting 可能的值Possible values 描述Description
自动修补Automated Patching 启用/禁用(已禁用)Enable/Disable (Disabled) 为 Azure 虚拟机启用或禁用自动修补。Enables or disables Automated Patching for an Azure virtual machine.
维护计划Maintenance schedule 每天、星期一、星期二、星期三、星期四、星期五、星期六、星期日Everyday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday 为虚拟机下载和安装 Windows、SQL Server 和 Microsoft 更新的计划。The schedule for downloading and installing Windows, SQL Server, and Microsoft updates for your virtual machine.
维护开始时间Maintenance start hour 0-240-24 更新虚拟机的本地开始时间。The local start time to update the virtual machine.
维护时段持续时间Maintenance window duration 30-18030-180 允许完成更新下载和安装的分钟数。The number of minutes permitted to complete the download and installation of updates.
修补程序类别Patch Category 重要提示Important 要下载并安装的 Windows 更新类别。The category of Windows updates to download and install.

门户中的配置Configuration in the Portal

可以在预配期间或针对现有的 VM,使用 Azure 门户来配置自动修补。You can use the Azure portal to configure Automated Patching during provisioning or for existing VMs.

新的 VMNew VMs

在 Resource Manager 部署模型中创建新的 SQL Server 虚拟机时,可以使用 Azure 门户配置自动修补。Use the Azure portal to configure Automated Patching when you create a new SQL Server Virtual Machine in the Resource Manager deployment model.

在“SQL Server 设置”选项卡中,选择“自动修补”下的“更改配置”。In the SQL Server settings tab, select Change configuration under Automated patching. 下面的 Azure 门户屏幕截图显示了“SQL 自动修补”边栏选项卡。The following Azure portal screenshot shows the SQL Automated Patching blade.

Azure 门户中的 SQL 自动修补

若要了解上下文,请参阅有关在 Azure 中预配 SQL Server 虚拟机的完整主题。For context, see the complete topic on provisioning a SQL Server virtual machine in Azure.

现有 VMExisting VMs

备注

以下屏幕截图来自 Azure 门户中的SQL 虚拟机资源。The following screenshots are from the SQL virtual machines resource within the Azure portal. 对于不在SQL VM 资源提供程序中注册的支持结束 (EOS) sql Server vm 和 SQL Server vm, 请改用SQL Server 配置选项卡来管理 SQL Server VM。For end-of-support (EOS) SQL server VMs, and SQL Server VMs that have not been registered with the SQL VM resource provider, use the SQL Server configuration tab to manage your SQL Server VM instead.

对于现有 SQL Server 虚拟机, 请打开SQL 虚拟机资源, 然后选择 "设置" 下的 "修补"。For existing SQL Server virtual machines, open your SQL virtual machines resource and select Patching under Settings.

现有 VM 的 SQL 自动修补

完成后,单击“SQL Server 配置”边栏选项卡底部的“确定”按钮保存更改。When finished, click the OK button on the bottom of the SQL Server configuration blade to save your changes.

首次启用自动修补时,Azure 会在后台配置 SQL Server IaaS 代理。If you are enabling Automated Patching for the first time, Azure configures the SQL Server IaaS Agent in the background. 在此期间,Azure 门户可能不会显示已配置自动修补。During this time, the Azure portal might not show that Automated Patching is configured. 请等待几分钟,以便安装和配置代理。Wait several minutes for the agent to be installed, configured. 随后,Azure 门户将反映新设置。After that the Azure portal reflects the new settings.

使用 PowerShell 进行配置Configuration with PowerShell

预配 SQL VM 后,使用 PowerShell 配置自动修补。After provisioning your SQL VM, use PowerShell to configure Automated Patching.

以下示例使用 PowerShell 在现有的 SQL Server VM 上配置自动修补。In the following example, PowerShell is used to configure Automated Patching on an existing SQL Server VM. New-AzVMSqlServerAutoPatchingConfig 命令可为自动更新配置新的维护时段。The New-AzVMSqlServerAutoPatchingConfig command configures a new maintenance window for automatic updates.

$vmname = "vmname"
$resourcegroupname = "resourcegroupname"
$aps = New-AzVMSqlServerAutoPatchingConfig -Enable -DayOfWeek "Thursday" -MaintenanceWindowStartingHour 11 -MaintenanceWindowDuration 120  -PatchCategory "Important"

s Set-AzVMSqlServerExtension -AutoPatchingSettings $aps -VMName $vmname -ResourceGroupName $resourcegroupnames Set-AzVMSqlServerExtension -AutoPatchingSettings $aps -VMName $vmname -ResourceGroupName $resourcegroupname

重要

如果尚未安装该扩展,安装该扩展将会重新启动 SQL Server 服务。If the extension is not already installed, installing the extension restarts the SQL Server service.

下表根据此示例描述了对目标 Azure VM 产生的实际效果:Based on this example, the following table describes the practical effect on the target Azure VM:

参数Parameter 效果Effect
DayOfWeekDayOfWeek 每个星期四安装修补程序。Patches installed every Thursday.
MaintenanceWindowStartingHourMaintenanceWindowStartingHour 在上午 11:00 开始更新。Begin updates at 11:00am.
MaintenanceWindowsDurationMaintenanceWindowsDuration 必须在 120 分钟内安装修补程序。Patches must be installed within 120 minutes. 根据开始时间,修补必须在下午 1:00 之前完成。Based on the start time, they must complete by 1:00pm.
PatchCategoryPatchCategory 此参数的唯一可能设置为 ImportantThe only possible setting for this parameter is Important. 这会安装标记为“重要”的 Windows 更新;不安装未包含在此类别中的任何 SQL Server 更新。This installs Windows update marked Important; it does not install any SQL Server updates that are not included in this category.

可能需要花费几分钟来安装和配置 SQL Server IaaS 代理。It could take several minutes to install and configure the SQL Server IaaS Agent.

若要禁用自动修补,请在不使用 -Enable 参数的情况下对 New-AzVMSqlServerAutoPatchingConfig 运行同一脚本。To disable Automated Patching, run the same script without the -Enable parameter to the New-AzVMSqlServerAutoPatchingConfig. 缺少 -Enable 参数将向该命令发出指示以禁用此功能。The absence of the -Enable parameter signals the command to disable the feature.

后续步骤Next steps

有关其他可用自动化任务的信息,请参阅 SQL Server IaaS 代理扩展For information about other available automation tasks, see SQL Server IaaS Agent Extension.

有关在 Azure VM 中运行 SQL Server 的详细信息,请参阅 Azure 虚拟机中的 SQL Server 概述For more information about running SQL Server on Azure VMs, see SQL Server on Azure Virtual Machines overview.