为 Always On 可用性组配置侦听程序Configure a listener for an Always On availability group

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions)

本主题介绍了如何通过在 SQL Server 2019 (15.x)SQL Server 2019 (15.x) 中使用 SQL Server Management StudioSQL Server Management StudioTransact-SQLTransact-SQL 或 PowerShell 为 AlwaysOn 可用性组创建或配置单个“可用性组侦听程序” 。This topic describes how to create or configure a single availability group listener for an Always On availability group by using SQL Server Management StudioSQL Server Management Studio, Transact-SQLTransact-SQL, or PowerShell in SQL Server 2019 (15.x)SQL Server 2019 (15.x).

重要

若要创建某个可用性组的第一个可用性组侦听器,我们强烈建议你使用 SQL Server Management StudioSQL Server Management StudioTransact-SQLTransact-SQLSQL ServerSQL Server PowerShell。To create the first availability group listener of an availability group, we strongly recommend that you use SQL Server Management StudioSQL Server Management Studio, Transact-SQLTransact-SQL, or SQL ServerSQL Server PowerShell. 除非必要情况,例如创建附加侦听器,否则,应避免直接在 WSFC 群集中创建侦听器。Avoid creating a listener directly in the WSFC cluster except when necessary, for example, to create an additional listener.

已存在此可用性组的侦听器?Does a Listener Exist for this Availability Group Already?

确定可用性组是否已存在一个侦听器To determine whether a listener already exists for the availability group

备注

如果某个侦听程序已存在并且你想要创建附加的侦听程序,请参阅本文后面的 为可用性组创建其他侦听程序(可选)If a listener already exists and you want to create an additional listener, see To Create An Additional Listener for an Availability Group (Optional), later in this topic.

限制和局限Limitations and Restrictions

  • 您只能通过 SQL ServerSQL Server为每个可用性组创建一个侦听器。You can create only one listener per availability group through SQL ServerSQL Server. 通常情况下,每个可用性组只需要一个侦听器。Typically, each availability group requires only one listener. 但是,某些用户群体要求一个可用性组多个侦听器。However, some customer scenarios require multiple listeners for one availability group. 通过 SQL Server 创建一个侦听器之后,您可以将 Windows PowerShell 用于故障转移群集或使用 WSFC 故障转移群集管理器来创建其他侦听器。After creating a listener through SQL Server, you can use Windows PowerShell for failover clusters or the WSFC Failover Cluster Manager to create additional listeners. 有关详细信息,请参阅本主题后面的 为可用性组创建其他侦听程序(可选)For more information, see To Create An Additional Listener for an Availability Group (Optional), later in this topic.

建议Recommendations

建议对于多子网配置使用静态 IP 地址,尽管不是必需的。Using a static IP address is recommended, although not required, for multiple subnet configurations.

先决条件Prerequisites

  • 您必须连接到承载主副本的服务器实例。You must be connected to the server instance that hosts the primary replica.

  • 如果您正在跨多个子网设置一个可用性组侦听器并计划使用静态 IP 地址,则对于承载您要为其创建侦听器的可用性组的可用性副本的每个子网,您需要获取其静态 IP 地址。If you are setting up an availability group listener across multiple subnets and plan to use static IP addresses, you need to get the static IP address of every subnet that hosts an availability replica for the availability group for which you are creating the listener. 通常,您需要向网络管理员索取静态 IP 地址。Usually, you will need to ask your network administrators for the static IP addresses.

重要

在创建你的第一个侦听程序之前,我们强烈建议你阅读 AlwaysOn 客户端连接 (SQL Server)Before you create your first listener, we strongly recommend that you read Always On Client Connectivity (SQL Server).

可用性组侦听器的 DNS 名称的要求Requirements for the DNS Name of an Availability Group Listener

每个可用性组侦听器都需要一个 DNS 主机名,该名称在域和 NetBIOS 中是唯一的。Each availability group listener requires a DNS host name that is unique in the domain and in NetBIOS. DNS 名称为字符串值。The DNS name is a string value. 该名称只能包含字母数字字符、破折号/连字符 (-) 和下划线 (),顺序不分先后。This name can contain only alphanumeric characters, dashes/hyphens (-), and underscores (), in any order. DNS 主机名不区分大小写。DNS host names are case insensitive. 最大长度为 63 个字符,但是,在 SQL Server Management StudioSQL Server Management Studio中,您可以指定的最大长度为 15 个字符。The maximum length is 63 characters, however, in SQL Server Management StudioSQL Server Management Studio, the maximum length you can specify is 15 characters.

我们建议您指定一个有意义的字符串。We recommend that you specify a meaningful string. 例如,对于名为 AG1的可用性组,有意义的 DNS 主机名将是 ag1-listenerFor example, for an availability group named AG1, a meaningful DNS host name would be ag1-listener.

重要

NetBIOS 只识别 dns_name 中的前 15 个字符。NetBIOS recognizes only the first 15 chars in the dns_name. 如果您的两个 WSFC 群集均由同一 Active Directory 控制,而您试图使用超过 15 个字符的名称(具有相同的 15 字符前缀)在这两个群集中创建可用性组侦听器,此时您将收到错误,报告无法使虚拟网络名称资源联机。If you have two WSFC clusters that are controlled by the same Active Directory and you try to create availability group listeners in both of clusters using names with more than 15 characters and an identical 15 character prefix, you will get an error reporting that the Virtual Network Name resource could not be brought online. 有关 DNS 名称的前缀命名规则的信息,请参阅 分配域名For information about prefix naming rules for DNS names, see Assigning Domain Names.

Windows 权限Windows Permissions

权限Permissions 链接Link
托管可用性组的 WSFC 群集的群集对象名称 (CNO) 必须具有“创建计算机对象” 权限。The cluster object name (CNO) of WSFC cluster that is hosting the availability group must have Create Computer objects permission.

在 Active Directory 中,CNO 默认不具有显式“创建计算机对象” 权限,并且可以创建 10 个虚拟计算机对象 (VCO)。In Active Directory, a CNO by default does not have Create Computer objects permission explicitly and can create 10 virtual computer objects (VCOs). 在创建了 10 个 VCO 后,再创建 VCO 将失败。After 10 VCOs are created, the creation of additional VCOs will fail. 可通过将权限显式授予 WSFC 群集的 CNO,避免发生此情况。You can avoid this by granting the permission explicitly to the WSFC cluster's CNO. 请注意,您已删除的可用性组的 VCO 并不自动在 Active Directory 中删除,因此,在手动删除它们之前,10 个 VCO 的默认数目限制仍会将其计算在内。Note that VCOs for availability groups that you have deleted are not automatically deleted in Active Directory and count against your 10 VCO default limit unless they are manually deleted.

注意:在某些组织中,安全策略禁止向单独用户帐户授予“创建计算机对象”权限 。Note: In some organizations, the security policy prohibits granting Create Computer objects permission to individual user accounts.
为安装此群集的人员配置帐户的步骤(位于故障转移群集分步指南 :在 Active Directory 中配置帐户中)Steps for configuring the account for the person who installs the cluster in Failover Cluster Step-by-Step Guide: Configuring Accounts in Active Directory

预配置群集名称帐户的步骤(位于故障转移群集分步指南 :在 Active Directory 中配置帐户中)Steps for prestaging the cluster name account in Failover Cluster Step-by-Step Guide: Configuring Accounts in Active Directory
如果你的组织要求你为侦听器虚拟网络名称预配置计算机帐户,则你需要具有 “帐户操作员”组的成员资格或域管理员的帮助。If your organization requires that you prestage the computer account for a listener virtual network name, you will need membership in the Account Operator group or your domain administrator's assistance. 为群集服务或应用程序预配置帐户的步骤(位于故障转移群集分步指南 :在 Active Directory 中配置帐户中)。Steps for prestaging an account for a clustered service or application in Failover Cluster Step-by-Step Guide: Configuring Accounts in Active Directory.

提示

一般情况下,最简单的方法是不为侦听器虚拟网络名称预配置计算机帐户。Generally, it is simplest not to prestage the computer account for a listener virtual network name. 如果可以,请在运行 WSFC 高可用性向导时自动创建并配置该帐户。If you can, let the account to be created and configured automatically when you run the WSFC High Availability wizard.

SQL Server 权限SQL Server Permissions

任务Task 权限Permissions
创建可用性组侦听器To create an availability group listener 需要 sysadmin 固定服务器角色的成员资格,以及 CREATE AVAILABILITY GROUP 服务器权限、ALTER ANY AVAILABILITY GROUP 权限或 CONTROL SERVER 权限。Requires membership in the sysadmin fixed server role and either CREATE AVAILABILITY GROUP server permission, ALTER ANY AVAILABILITY GROUP permission, or CONTROL SERVER permission.
修改现有可用性组侦听器To modify an existing availability group listener 对可用性组要求 ALTER AVAILABILITY GROUP 权限、CONTROL AVAILABILITY GROUP 权限、ALTER ANY AVAILABILITY GROUP 权限或 CONTROL SERVER 权限。Requires ALTER AVAILABILITY GROUP permission on the availability group, CONTROL AVAILABILITY GROUP permission, ALTER ANY AVAILABILITY GROUP permission, or CONTROL SERVER permission.

使用 SQL Server Management StudioUsing SQL Server Management Studio

提示

“新建可用性组”向导 支持为新可用性组创建侦听程序。The New Availability Group wizard supports creation of the listener for a new availability group.

创建和配置可用性组侦听器To create or configure an availability group listener

  1. 在对象资源管理器中,连接到承载可用性组的主副本的服务器实例,然后单击此服务器名称以展开服务器树。In Object Explorer, connect to the server instance that hosts the primary replica of the availability group, and click the server name to expand the server tree.

  2. 依次展开“Always On 高可用性” 节点和“可用性组” 节点。Expand the Always On High Availability node and the Availability Groups node.

  3. 单击您要配置其侦听器的可用性组,然后选择以下备选方法之一:Click the availability group whose listener you want to configure, and choose one of the following alternatives:

    • 若要创建一个侦听程序,请右键单击“可用性组侦听程序” 节点,然后选择“新建侦听程序” 命令。To create a listener, right-click the Availability group Listeners node, and select the New Listener command. 这将打开 “新建可用性组侦听器” 对话框。This opens the New Availability Group Listener dialog box. 有关详细信息,请参阅本主题后面的添加可用性组侦听程序(对话框)For more information, see Add Availability Group Listener (Dialog Box), later in this topic.

    • 若要更改现有侦听程序的端口号,请展开“可用性组侦听程序” 节点,右键单击此侦听程序,然后选择“属性” 命令。To change the port number of an existing listener, expand the Availability group Listeners node, right-click the listener, and select the Properties command. “端口” 字段中输入新的端口号,然后单击 “确定”Enter the new port number into the Port field, and click OK.

新建可用性组(对话框)New Availability Group Listener (Dialog Box)

侦听器 DNS 名称Listener DNS Name
指定可用性组侦听器的 DNS 主机名。Specifies the DNS host name of the availability group listener. DNS 名称为字符串,且在域和 NetBIOS 中必须唯一。The DNS name is a string must be unique in the domain and in NetBIOS. 该名称只能包含字母数字字符、破折号 (-) 和连字符 (),顺序不分先后。This name can contain only alphanumeric characters, dashes (-), and hyphens (), in any order. DNS 主机名不区分大小写。DNS host names are case insensitive. 最大长度为 15 个字符。The maximum length is 15 characters.

有关详细信息,请参阅本主题前面的 可用性组侦听器的 DNS 名称的要求For more information, see Requirements for the DNS Name of an Availability Group Listener, earlier in this topic.

端口 Port
该侦听器使用的 TCP 端口。The TCP port used by this listener.

网络模式Network Mode
指示该侦听器使用的 TCP 协议,选择如下一种:Indicates the TCP protocol used by the listener, one of:

DHCPDHCP
侦听器将使用运行动态主机配置协议 (DHCP) 的服务器分配的动态 IP 地址。The listener will us a dynamic IP address that is assigned by a server running the Dynamic Host Configuration Protocol (DHCP). DHCP 仅限于单个子网。DHCP is limited to a single subnet.

重要

不建议在生产环境中使用 DHCP。We do not recommend DHCP in production environment. 如果停止工作且 DHCP IP 租期已到,则需要额外的时间来注册与侦听器 DNS 名称相关联且影响客户端连接的新 DHCP 网络 IP 地址。If there is a down time and the DHCP IP lease expires, extra time is required to register the new DHCP network IP address that is associated with the listener DNS name and impact the client connectivity. 但是,DHCP 适合用于设置开发和测试环境以验证可用性组的基本功能并适合与应用程序集成。However, DHCP is good for setting up your development and testing environment to verify basic functions of availability groups and for integration with your applications.

静态 IPStatic IP
侦听器将使用一个或多个静态 IP 地址。The listener will use one or more static IP addresses. 其他 IP 地址是可选的。Additional IP addresses are optional. 若要跨多个子网创建一个可用性组侦听器,必须在侦听器配置中为每个子网指定一个静态 IP 地址。To create an availability group listener across multiple subnets, for each subnet you must specify a static IP address in the listener configuration. 请与您的网络管理员联系以获取这些静态 IP 地址。Contact your network administrator to get these static IP addresses.

如果您选择 “静态 IP” ,则会在 “网络模式” 字段下出现一个子网网格。If you select Static IP a subnet grid appears below the Network Mode field. 此网格将显示有关该可用性组侦听器可以访问的每个子网的信息。This grid displays information about each subnet that can be accessed by this availability group listener. 在通过单击 “添加” 添加静态 IP 地址之前,该网格为空。This grid is empty until you add a static IP address by clicking Add.

这些列如下所示:The columns are as follows:

子网Subnet
显示您添加到可用性组侦听器的每个子网的标识符。Displays the identifier of each subnet that you add to the availability group listener.

IP 地址IP Address
显示给定子网的 IP 地址。Displays the IP address of a given subnet. 对于给定子网,静态 IP 地址可以是 IPv4 地址或 IPv6 地址。For a given subnet, the IP address is either an IPv4 address or an IPv6 address.

添加Add
单击“添加”可将静态 IP 地址添加到所选子网,或添加到该侦听器的其他子网。Click to add to add a static IP address to a selected subnet or to another subnet for this listener. 这将打开 “添加 IP 地址” 对话框。This opens the Add IP Address dialog box. 有关详细信息,请参阅添加 IP 地址对话框 (SQL Server Management Studio) 帮助主题。For more information, see the Add IP Address Dialog Box (SQL Server Management Studio) help topic.

删除Remove
单击此项可以从侦听器中移除所选子网。Click to remove the selected subnet from this listener.

确定OK
单击此选项可创建指定的可用性组侦听器。Click to create the specified availability group listener.

使用 Transact-SQLUsing Transact-SQL

创建和配置可用性组侦听器To create or configure an availability group listener

  1. 连接到承载主副本的服务器实例。Connect to the server instance that hosts the primary replica.

  2. 使用 CREATE AVAILABILITY GROUP 语句的 LISTENER 选项或 ALTER AVAILABILITY GROUP 语句的 ADD LISTENER 选项。Use the LISTENER option of the CREATE AVAILABILITY GROUP statement or the ADD LISTENER option of the ALTER AVAILABILITY GROUP statement.

    下面的示例将可用性组侦听器添加到名为 MyAg2的现有可用性组。The following example adds an availability group listener to an existing availability group named MyAg2. 将为此侦听器指定唯一的 DNS 名称 MyAg2ListenerIvP6A unique DNS name, MyAg2ListenerIvP6, is specified for this listener. 两个副本位于不同的子网,因此按照建议,侦听器使用静态 IP 地址。The two replicas are on different subnets, so , as recommended, the listener uses static IP addresses. 对于这两个可用性副本中的每一个,WITH IP 子句都指定一个将使用 IPv6 格式的静态 IP 地址 2001:4898:f0:f00f::cf3c and 2001:4898:e0:f213::4ce2For each of the two availability replicas, the WITH IP clause specifies a static IP address, 2001:4898:f0:f00f::cf3c and 2001:4898:e0:f213::4ce2, which use the IPv6 format. 此示例还指定使用可选的 PORT 参数来将端口 60173 指定为侦听器端口。This example also specifies uses the optional PORT argument to specify port 60173 as the listener port.

    ALTER AVAILABILITY GROUP MyAg2   
          ADD LISTENER 'MyAg2ListenerIvP6' ( WITH IP ( ('2001:db88:f0:f00f::cf3c'),('2001:4898:e0:f213::4ce2') ) , PORT = 60173 );   
    GO  
    
    

使用 PowerShellUsing PowerShell

创建和配置可用性组侦听器To create or configure an availability group listener

  1. 将目录 (cd) 更改为托管主副本的服务器实例。Change directory (cd) to the server instance that hosts the primary replica.

  2. 使用下列 cmdlet 之一创建或修改可用性组侦听器:To create or modify an availability group listener use one of the following cmdlets:

    New-SqlAvailabilityGroupListenerNew-SqlAvailabilityGroupListener
    创建一个新的可用性组侦听器,并将其附加到一个现有可用性组。Creates a new availability group listener and attaches it to an existing availability group.

    例如,下列 New-SqlAvailabilityGroupListener 命令为可用性组 MyListener 创建名为 MyAg的可用性组侦听程序。For example, the following New-SqlAvailabilityGroupListener command creates an availability group listener named MyListener for the availability group MyAg. 此侦听程序将使用传递到 -StaticIp 参数的 IPv4 地址作为其虚拟 IP 地址。This listener will use the IPv4 address passed to the -StaticIp parameter as its virtual IP address.

    New-SqlAvailabilityGroupListener -Name MyListener `   
    -StaticIp '192.168.3.1/255.255.252.0' `   
    -Path SQLSERVER:\Sql\Computer\Instance\AvailabilityGroups\MyAg  
    
    

    Set-SqlAvailabilityGroupListenerSet-SqlAvailabilityGroupListener
    修改现有可用性组侦听器的端口设置。Modifies the port setting on an existing availability group listener.

    例如,下列 Set-SqlAvailabilityGroupListener 命令将名为 MyListener 的可用性组侦听程序的端口号设置为 1535For example, the following Set-SqlAvailabilityGroupListener command sets the port number for the availability group listener named MyListener to 1535. 此端口用于侦听与侦听器的连接。This port is used to listen for connections to the listener.

    Set-SqlAvailabilityGroupListener -Port 1535 `   
    -Path SQLSERVER:\Sql\PrimaryServer\InstanceName\AvailabilityGroups\MyAg\AGListeners\MyListener  
    
    

    Add-SqlAGListenerstaticIpAdd-SqlAGListenerstaticIp
    将一个静态 IP 地址添加到现有的可用性组侦听器配置。Adds a static IP address to an existing availability group listener configuration. 此 IP 地址可以是带子网的 IPv4 地址或 IPv6 地址。The IP address can be an IPv4 address with subnet, or an IPv6 address.

    例如,下列 Add-SqlAGListenerstaticIp 命令将一个静态 IPv4 地址添加到可用性组 MyListener 上的可用性组侦听程序 MyAgFor example, the following Add-SqlAGListenerstaticIp command adds a static IPv4 address to the availability group listener MyListener on the availability group MyAg. 此 IPv6 地址用作子网 255.255.252.0上侦听器的虚拟 IP 地址。This IPv6 address serves as the virtual IP address of the listener on the subnet 255.255.252.0. 如果可用性组跨多个子网,则应将针对每个子网的静态 IP 地址添加到侦听器。If the availability group spans multiple subnets, you should add a static IP address for each subnet to the listener.

    $path = "SQLSERVER:\SQL\PrimaryServer\InstanceName\AvailabilityGroups\MyAg\AGListeners\ MyListener" `   
    Add-SqlAGListenerstaticIp -Path $path `   
    -StaticIp "2001:0db8:85a3:0000:0000:8a2e:0370:7334"  
    

    备注

    若要查看 cmdlet 的语法,请在 PowerShell 环境中使用 Get-Help SQL ServerSQL Server cmdlet。To view the syntax of a cmdlet, use the Get-Help cmdlet in the SQL ServerSQL Server PowerShell environment. 有关详细信息,请参阅 Get Help SQL Server PowerShellFor more information, see Get Help SQL Server PowerShell.

设置和使用 SQL Server PowerShell 提供程序To set up and use the SQL Server PowerShell provider

故障排除Troubleshooting

因 Active Directory 配额未能创建可用性组侦听器Failure to Create An Availability Group Listener Because of Active Directory Quotas

新的可用性组侦听器可能在创建时失败,因为您已经达到参与群集节点计算机帐户的 Active Directory 配额。The creation of a new availability group listener may fail upon creation because you have reached an Active Directory quota for the participating cluster node machine account. 有关详细信息,请参阅以下文章:For more information, see the following articles:

后续任务:创建可用性组侦听程序后Follow-up: After Creating an Availability Group Listener

MultiSubnetFailover 关键字和相关功能MultiSubnetFailover Keyword and Associated Features

MultiSubnetFailover 是 SQL Server 2012 中用于允许使用 AlwaysOn 可用性组和 AlwaysOn 故障转移群集实例进行更快故障转移的新连接字符串关键字。MultiSubnetFailover is a new connection string keyword used to enable faster failover with Always On Availability Groups and Always On Failover Cluster Instances in SQL Server 2012. 在连接字符串中设置 MultiSubnetFailover=True 时,将启用以下三个子功能:The following three sub-features are enabled when MultiSubnetFailover=True is set in connection string:

  • 更快进行多子网故障转移到 AlwaysOn 可用性组或故障转移群集实例的多子网侦听程序。Faster multi-subnet failover to a multi-subnet listener for an Always On Availability Group or Failover Cluster Instances.

  • 更快进行单子网故障转移到 AlwaysOn 可用性组或故障转移群集实例的单子网侦听程序。Faster single subnet failover to a single subnet listener for an Always On Availability Group or Failover Cluster Instances.

    • 当连接到具有单个子网中的单个 IP 的侦听器时使用此功能。This feature is used when connecting to a listener that has a single IP in a single subnet. 这将进行更频繁的 TCP 连接重试以加快单子网故障转移。This performs more aggressive TCP connection retries to speed up single subnet failovers.
  • 多子网 AlwaysOn 故障转移群集实例的命名实例解析。Named instance resolution to a multi-subnet Always On Failover Cluster Instance.

    • 这将添加对具有多子网端点的 AlwaysOn 故障转移群集实例的命名实例解析支持。This is to add named instance resolution support for an Always On Failover Cluster Instances with multiple subnet endpoints.

NET Framework 3.5 或 OLEDB 不支持 MultiSubnetFailover=TrueMultiSubnetFailover=True Not Supported by NET Framework 3.5 or OLEDB

问题: 如果你的可用性组或故障转移群集实例具有取决于不同子网的多个 IP 地址的侦听程序名称(在 WSFC 群集管理器中称作网络名称或客户端访问点),并且你在将 ADO.NET 用于 .NET Framework 3.5SP1 或 SQL Native Client 11.0 OLEDB,则可能你对可用性组侦听程序的 50% 的客户端连接请求都将遇到连接超时。Issue: If your Availability Group or Failover Cluster Instance has a listener name (known as the network name or Client Access Point in the WSFC Cluster Manager) depending on multiple IP addresses from different subnets, and you are using either ADO.NET with .NET Framework 3.5SP1 or SQL Native Client 11.0 OLEDB, potentially 50% of your client-connection requests to the availability group listener will hit a connection timeout.

解决方法: 我们建议你执行以下任务之一。Workarounds: We recommend that you do one of the following tasks.

  • 如果您无权操作群集资源,则将连接超时更改为 30 秒(该值导致 20 秒的 TCP 超时期加上 10 秒的缓冲)。If do not have the permission to manipulate cluster resources, change your connection timeout to 30 seconds (this value results in a 20-second TCP timeout period plus a 10-second buffer).

    优点 :如果发生跨子网故障转移,则客户端恢复时间将比较短。Pros: If a cross-subnet failover occurs, client recovery time is short.

    缺点 :半数的客户端连接将需要 20 多秒Cons: Half of the client connections will take more than 20 seconds

  • 如果您有权操作群集资源,则强烈建议您将可用性组侦听器的网络名称设置为 RegisterAllProvidersIP=0If you have the permission to manipulate cluster resources, the more recommended approach is to set the network name of your availability group listener to RegisterAllProvidersIP=0. 有关详细信息,请参阅本节后面的“RegisterAllProvidersIP 设置”。For more information, see "RegisterAllProvidersIP Setting" later in this section.

    优点 :无需增加客户端连接超时值。Pros: You do not need to increase your client-connection timeout value.

    缺点 :如果跨子网故障转移发生,则客户端恢复时间可能为 15 分钟或更长,具体时间取决于 HostRecordTTL 设置以及跨站点 DNS/AD 复制计划的设置 。Cons: If a cross-subnet failover occurs, the client recovery time could be 15 minutes or longer, depending on your HostRecordTTL setting and the setting of your cross-site DNS/AD replication schedule.

RegisterAllProvidersIP 设置RegisterAllProvidersIP Setting

在使用 SQL Server Management StudioSQL Server Management StudioTransact-SQLTransact-SQL或 PowerShell 创建可用性组侦听程序时,将在 WSFC 中创建客户端访问点,其 RegisterAllProvidersIP 属性设为 1 (true)。When you use SQL Server Management StudioSQL Server Management Studio, Transact-SQLTransact-SQL, or PowerShell to create an availability group listener, the Client Access Point is created in WSFC with the RegisterAllProvidersIP property set to 1 (true). 此属性值的影响取决于客户端连接字符串,如下所示:The effect of this property value depends on the client connection string, as follows:

  • MultiSubnetFailover 设置为 true 的连接字符串Connection strings that set MultiSubnetFailover to true

    Always On 可用性组Always On availability groups 可将 RegisterAllProvidersIP 属性设置为 1,从而缩短其客户端连接字符串按照建议指定 MultiSubnetFailover = True的客户端在故障转移后的重新连接时间。sets the RegisterAllProvidersIP property to 1 in order to reduce re-connection time after a failover for clients whose client connection strings specify MultiSubnetFailover = True, as recommended. 请注意,为了利用侦听程序多子网功能,你的客户端可能会需要支持 MultiSubnetFailover 关键字的数据提供程序。Note that to take advantage of the listener multi-subnet feature, your clients might require a data provider that supports the MultiSubnetFailover keyword. 有关针对多子网故障转移的驱动程序支持的信息,请参阅 AlwaysOn 客户连接 (SQL Server)For information about driver support for multi-subnet failover, see Always On Client Connectivity (SQL Server).

    有关多子网群集的信息,请参阅 SQL Server 多子网群集 (SQL Server)为每个可用性组创建一个侦听器。For information about multi-subnet clustering, see SQL Server Multi-Subnet Clustering (SQL Server).

    提示

    RegisterAllProvidersIP = 1时,如果您在 WSFC 群集上运行 WSFC 验证配置向导,该向导将生成以下警告消息:When RegisterAllProvidersIP = 1, if you run the WSFC Validate a Configuration Wizard on the WSFC cluster, the wizard generates the following warning message:

    “网络名称 ‘Name:<network_name>’ 的 RegisterAllProviderIP 属性设为 1。对于当前群集配置,该值应设为 0。”"The RegisterAllProviderIP property for network name 'Name:<network_name>' is set to 1 For the current cluster configuration this value should be set to 0."

    请忽略此消息。Please ignore this message.

  • 未将 MultiSubnetFailover 设置为 true 的连接字符串Connection strings that do not set MultiSubnetFailover to true

    RegisterAllProvidersIP = 1时,其连接字符串未使用 MultiSubnetFailover = True的任何客户端都将会经历高延迟的连接。When RegisterAllProvidersIP = 1, any clients whose connection strings do not use MultiSubnetFailover = True, will experience high latency connections. 发生这种情况的原因是这些客户端将按顺序尝试与所有 IP 的连接。This occurs because these clients attempt connections to all IPs sequentially. 相反,如果将 RegisterAllProvidersIP 更改为 0,将在 WSFC 群集中的客户端接入点注册活动 IP 地址,从而缩短旧客户端的延迟时间。In contrast, if RegisterAllProvidersIP is changed to 0, the active IP address is registered in the Client Access Point in the WSFC cluster, reducing latency for legacy clients. 因此,如果具有需要连接到某一可用性组侦听器并且不能使用 MultiSubnetFailover 属性的旧客户端,建议将 RegisterAllProvidersIP 更改为 0 。Therefore, if you have legacy clients that need to connect to an availability group listener and cannot use the MultiSubnetFailover property, we recommend that you change RegisterAllProvidersIP to 0.

    重要

    在你通过 WSFC 群集(故障转移群集管理器 GUI)创建可用性组侦听程序时, RegisterAllProvidersIP 默认情况下将为 0 (false)。When you create an availability group listener through the WSFC cluster (Failover Cluster Manager GUI), RegisterAllProvidersIP will be 0 (false) by default.

HostRecordTTL 设置HostRecordTTL Setting

默认情况下,客户端缓存 20 分钟的群集 DNS 记录。By default, clients cache cluster DNS records for 20 minutes. 通过缩短缓存记录的 HostRecordTTL(生存时间 (TTL)),旧客户端重新连接速度可能更快。By reducing HostRecordTTL, the Time to Live (TTL), for the cached record, legacy clients may reconnect more quickly. 但是,减低 HostRecordTTL 设置也可能导致到 DNS 服务器的流量增加 。However, reducing the HostRecordTTL setting may also result in increased traffic to the DNS servers.

用于禁用 RegisterAllProvidersIP 和减少 TTL 的示例 PowerShell 脚本Sample PowerShell Script to Disable RegisterAllProvidersIP and Reduce TTL

下面的 PowerShell 示例演示如何为侦听器资源配置 RegisterAllProvidersIPHostRecordTTL 群集参数。The following PowerShell example demonstrates how to configure both the RegisterAllProvidersIP and HostRecordTTL cluster parameters for the listener resource. DNS 记录将缓存 5 分钟,而不是默认的 20 分钟。The DNS record will be cached for 5 minutes rather than the default 20 minutes. 同时修改两个群集参数可以缩短无法使用 MultiSubnetFailover 参数的旧客户端在故障转移后连接到正确 IP 地址的时间。Modifying both cluster parameters may reduce the time to connect to the correct IP address after a failover for legacy clients that cannot use the MultiSubnetFailover parameter. 使用您要更改的侦听器名称替换 yourListenerNameReplace yourListenerName with the name of the listener that you are changing.

Import-Module FailoverClusters  
Get-ClusterResource yourListenerName | Set-ClusterParameter RegisterAllProvidersIP 0   
Get-ClusterResource yourListenerName | Set-ClusterParameter HostRecordTTL 300  
Stop-ClusterResource yourListenerName  
Start-ClusterResource yourListenerName  
Start-Clustergroup yourListenerGroupName

有关故障转移期间的恢复时间的详细信息,请参阅 Client Recovery Latency During FailoverFor more information about recovery times during failover, see Client Recovery Latency During Failover.

跟进建议Follow-up Recommendations

在创建可用性组侦听器后:After you create an availability group listener:

  • 请求您的网络管理员将该侦听器的 IP 地址保留为专用。Ask your network administrator to reserve the listener's IP address for its exclusive use.

  • 将该侦听器的 DNS 主机名提供给应用程序开发人员,以便在请求与此可用性组的客户端连接时用于连接字符串中。Give the listener's DNS host name to application developers to use in connection strings when requesting client connections to this availability group.

  • 如有可能,鼓励开发人员更新客户端连接字符串,以便指定 MultiSubnetFailover = TrueEncourage developers to update client connection strings to specify MultiSubnetFailover = True, if possible. 有关针对多子网故障转移的驱动程序支持的信息,请参阅 AlwaysOn 客户连接 (SQL Server)For information about driver support for multi-subnet failover, see Always On Client Connectivity (SQL Server).

为可用性组创建其他侦听器(可选)Create an Additional Listener for an Availability Group (Optional)

通过 SQL Server 创建一个侦听器之后,您可以添加其他侦听器,如下所示:After you create one listener through SQL Server, you can add an additional listener, as follows:

  1. 使用下列任一工具创建侦听器:Create the listener using either of the following tools:

  2. 在新的侦听器上启动 SQL ServerSQL Server 侦听。Start SQL ServerSQL Server listening on the new listener. 在创建其他侦听器之后,可连接到承载可用性组主副本的 SQL ServerSQL Server 实例,并使用 SQL Server Management StudioSQL Server Management StudioTransact-SQLTransact-SQL或 PowerShell 修改侦听器端口。After creating the additional listener, connect to the instance of SQL ServerSQL Server that hosts the primary replica of the availability group and use SQL Server Management StudioSQL Server Management Studio, Transact-SQLTransact-SQL, or PowerShell to modify the listener port.

有关详细信息,请参阅 如何为相同的可用性组创建多个侦听程序 (SQL Server AlwaysOn 团队博客)。For more information, see How to create multiple listeners for same availability group (a SQL Server Always On team blog).

后续步骤Next steps

现在你已经创建了侦听器,请将应用程序配置为连接到侦听器Now that you've created your listener, configure your application to connect to the listener. 还可以查看各种可用性组监视策略,以确保可用性组正常运行。You can also review various availability group monitoring strategies to ensure the health of your availability group.

还可以查看侦听器的属性,或了解如何删除侦听器(如有必要)。You can also view the properties of a listener or learn how to remove the listener, if necessary.