为 AG VNN 侦听器配置负载均衡器Configure load balancer for AG VNN listener

适用于: Azure VM 上的 SQL Server

在 Azure 虚拟机上,群集使用负载均衡器来保存每次都需要位于一个群集节点上的 IP 地址。On Azure Virtual Machines, clusters use a load balancer to hold an IP address that needs to be on one cluster node at a time. 在此解决方案中,负载均衡器保留 Always On 可用性组 (AG) 的虚拟网络名称 (VNN) 侦听器的 IP 地址。In this solution, the load balancer holds the IP address for the virtual network name (VNN) listener for the Always On availability group (AG).

本文介绍了如何使用 Azure 负载均衡器服务配置负载均衡器。This article teaches you to configure a load balancer by using the Azure Load Balancer service. 负载均衡器会使用 Azure VM 上的 SQL Server 将流量路由到可用性组 (AG) 侦听器,以实现高可用性和灾难恢复 (HADR)。The load balancer will route traffic to your availability group (AG) listener with SQL Server on Azure VMs for high availability and disaster recovery (HADR).

对于 SQL Server 2019 CU8 及更高版本上的客户的替代连接选项,请考虑改用 DNN 侦听器,以便简化配置并改进故障转移。For an alternative connectivity option for customers that are on SQL Server 2019 CU8 and later, consider a DNN listener instead for simplified configuration and improved failover.

先决条件Prerequisites

在完成本文中的步骤之前,应已做好以下准备:Before you complete the steps in this article, you should already have:

创建负载均衡器Create load balancer

使用 Azure 门户创建负载均衡器:Use the Azure portal to create the load balancer:

  1. 在 Azure 门户中,转到包含虚拟机的资源组。In the Azure portal, go to the resource group that contains the virtual machines.

  2. 选择 添加Select Add. 在 Azure 市场中搜索“负载均衡器”。Search Azure Marketplace for Load Balancer. 选择“负载均衡器”。Select Load Balancer.

  3. 选择“创建”。Select Create.

  4. 使用以下值设置负载均衡器:Set up the load balancer by using the following values:

    • 订阅:Azure 订阅。Subscription: Your Azure subscription.
    • 资源组:包含你的虚拟机的资源组。Resource group: The resource group that contains your virtual machines.
    • 名称:标识负载均衡器的名称。Name: A name that identifies the load balancer.
    • 区域:包含你的虚拟机的 Azure 位置。Region: The Azure location that contains your virtual machines.
    • 类型:公共或专用。Type: Either public or private. 可从虚拟网络内部访问专用负载均衡器。A private load balancer can be accessed from within the virtual network. 大多数 Azure 应用程序可以使用专用负载均衡器。Most Azure applications can use a private load balancer. 如果应用程序需要通过 Internet 直接访问 SQL Server,请使用公共负载均衡器。If your application needs access to SQL Server directly over the internet, use a public load balancer.
    • SKU:标准。SKU: Standard.
    • 虚拟网络:虚拟机所在的网络。Virtual network: The same network as the virtual machines.
    • IP 地址分配:静态。IP address assignment: Static.
    • 专用 IP 地址:你分配给群集化网络资源的 IP 地址。Private IP address: The IP address that you assigned to the clustered network resource.

    下图显示“创建负载均衡器”用户界面:The following image shows the Create load balancer UI:

    设置负载均衡器

配置后端池Configure backend pool

  1. 返回到包含虚拟机的 Azure 资源组,找到新的负载均衡器。Return to the Azure resource group that contains the virtual machines and locate the new load balancer. 可能需要在资源组中刷新视图。You might need to refresh the view on the resource group. 选择负载均衡器。Select the load balancer.

  2. 依次选择“后端池”、“添加”。 Select Backend pools, and then select Add.

  3. 将该后端池与包含 VM 的可用性集进行关联。Associate the backend pool with the availability set that contains the VMs.

  4. 在“目标网络 IP 配置”下选择“虚拟机”,并选择要作为群集节点参与操作的虚拟机。 Under Target network IP configurations, select VIRTUAL MACHINE and choose the virtual machines that will participate as cluster nodes. 请务必包括将承载 FCI 或可用性组的所有虚拟机。Be sure to include all virtual machines that will host the FCI or availability group.

  5. 选择“确定”以创建后端池。Select OK to create the backend pool.

配置运行状况探测Configure health probe

  1. 在负载均衡器窗格上,选择“运行状况探测”。On the load balancer pane, select Health probes.

  2. 选择 添加Select Add.

  3. 在“添加运行状况探测”窗格上,设置以下运行状况探测参数:On the Add health probe pane, set the following health probe parameters:

    • 名称:运行状况探测的名称。Name: A name for the health probe.
    • 协议:TCP。Protocol: TCP.
    • 端口准备 VM 时你在防火墙中为运行状况探测创建的端口。Port: The port you created in the firewall for the health probe when preparing the VM. 在本文中,示例使用了 TCP 端口 59999In this article, the example uses TCP port 59999.
    • 时间间隔:5 秒。Interval: 5 Seconds.
    • 不正常阈值:2 次连续失败。Unhealthy threshold: 2 consecutive failures.
  4. 选择“确定” 。Select OK.

设置负载均衡规则Set load-balancing rules

  1. 在负载均衡器窗格中,选择“负载均衡规则”。On the load balancer pane, select Load-balancing rules.

  2. 选择 添加Select Add.

  3. 设置负载均衡规则参数:Set the load-balancing rule parameters:

    • 名称:负载均衡规则的名称。Name: A name for the load-balancing rules.
    • 前端 IP 地址:SQL Server FCI 或 AG 侦听程序的群集化网络资源的 IP 地址。Frontend IP address: The IP address for the SQL Server FCIs or the AG listener's clustered network resource.
    • 端口:SQL Server TCP 端口。Port: The SQL Server TCP port. 默认实例端口为 1433。The default instance port is 1433.
    • 后端端口:与启用“浮动 IP (直接服务器返回)”时使用的“端口”值相同的端口。 Backend port: The same port as the Port value when you enable Floating IP (direct server return).
    • 后端池:前面配置的后端池名称。Backend pool: The backend pool name that you configured earlier.
    • 运行状况探测:前面配置的运行状况探测。Health probe: The health probe that you configured earlier.
    • 会话持久性:无。Session persistence: None.
    • 空闲超时(分钟) :4.Idle timeout (minutes): 4.
    • 浮动 IP (直接服务器返回) :已启用。Floating IP (direct server return): Enabled.
  4. 选择“确定” 。Select OK.

配置群集探测Configure cluster probe

在 PowerShell 中设置群集探测端口参数。Set the cluster probe port parameter in PowerShell.

若要设置群集探测端口参数,请使用环境中的值更新以下脚本中的变量。To set the cluster probe port parameter, update the variables in the following script with values from your environment. 从脚本中删除尖括号(<>)。Remove the angle brackets (< and >) from the script.

$ClusterNetworkName = "<Cluster Network Name>"
$IPResourceName = "<SQL Server FCI / AG Listener IP Address Resource Name>" 
$ILBIP = "<n.n.n.n>" 
[int]$ProbePort = <nnnnn>

Import-Module FailoverClusters

Get-ClusterResource $IPResourceName | Set-ClusterParameter -Multiple @{"Address"="$ILBIP";"ProbePort"=$ProbePort;"SubnetMask"="255.255.255.255";"Network"="$ClusterNetworkName";"EnableDhcp"=0}

下表介绍了需要更新的值:The following table describes the values that you need to update:

Value 说明Description
Cluster Network Name Windows Server 故障转移群集的网络名称。The Windows Server Failover Cluster name for the network. 在“故障转移群集管理器” > “网络”中,右键单击该网络并选择“属性”。 In Failover Cluster Manager > Networks, right-click the network and select Properties. 正确的值位于“常规”选项卡的“名称”下。The correct value is under Name on the General tab.
AG listener IP Address Resource Name SQL Server FCI 的或 AG 侦听程序的 IP 地址的资源名称。The resource name for the SQL Server FCI's or AG listener's IP address. 在“故障转移群集管理器” > “角色”中“SQL Server FCI”角色的“服务器名称”下,右键单击 IP 地址资源并选择单击“属性”。 In Failover Cluster Manager > Roles, under the SQL Server FCI role, under Server Name, right-click the IP address resource and select Properties. 正确的值位于“常规”选项卡的“名称”下。The correct value is under Name on the General tab.
ILBIP 内部负载均衡器 (ILB) 的 IP 地址。The IP address of the internal load balancer (ILB). 在 Azure 门户中将此地址配置为 ILB 的前端地址。This address is configured in the Azure portal as the ILB's frontend address. 这也是 SQL Server FCI 的 IP 地址。This is also the SQL Server FCI's IP address. 可在“故障转移群集管理器”中找到该地址,它与 <AG listener IP Address Resource Name> 位于同一属性页。You can find it in Failover Cluster Manager on the same properties page where you located the <AG listener IP Address Resource Name>.
nnnnn 在负载均衡器的运行状况探测中配置的探测端口。The probe port that you configured in the load balancer's health probe. 任何未使用的 TCP 端口都有效。Any unused TCP port is valid.
"SubnetMask""SubnetMask" 群集参数的子网掩码。The subnet mask for the cluster parameter. 它必须是 TCP IP 广播地址:255.255.255.255It must be the TCP IP broadcast address: 255.255.255.255.

设置群集探测后,可在 PowerShell 中看到所有群集参数。After you set the cluster probe, you can see all the cluster parameters in PowerShell. 运行此脚本:Run this script:

Get-ClusterResource $IPResourceName | Get-ClusterParameter

测试故障转移Test failover

测试群集化资源的故障转移以验证群集功能。Test failover of the clustered resource to validate cluster functionality.

执行以下步骤:Take the following steps:

  1. 打开 SQL Server Management Studio 并连接到你的可用性组侦听程序。Open SQL Server Management Studio) and connect to your availability group listener.
  2. 在“对象资源管理器”中展开“Always On 可用性组”。 Expand Always On Availability Group in Object Explorer.
  3. 右键单击该可用性组,然后选择“故障转移”。Right-click the availability group and select Failover.
  4. 按照向导提示将该可用性组故障转移到一个次要副本。Follow the wizard prompts to fail over the availability group to a secondary replica.

当副本切换角色并且两者同步后,故障转移成功。Failover succeeds when the replicas switch roles and are both synchronized.

测试连接Test connectivity

若要测试连接,请登录到同一虚拟网络中的另一个虚拟机。To test connectivity, sign in to another virtual machine in the same virtual network. 打开 SQL Server Management Studio 并连接到可用性组侦听程序。Open SQL Server Management Studio and connect to the availability group listener.

备注

如果需要,可以下载 SQL Server Management StudioIf you need to, you can download SQL Server Management Studio.

后续步骤Next steps

若要详细了解 Azure 中的 SQL Server HADR 功能,请参阅可用性组故障转移群集实例To learn more about SQL Server HADR features in Azure, see Availability groups and Failover cluster instance. 你还可以了解对环境进行配置以实现高可用性和灾难恢复的最佳做法You can also learn best practices for configuring your environment for high availability and disaster recovery.