在 Azure 中为 Always On 可用性组配置负载均衡器Configure a load balancer for an Always On availability group in Azure

本文说明如何在使用 Azure Resource Manager 运行的 Azure 虚拟机中为 SQL Server Always On 可用性组创建负载均衡器。This article explains how to create a load balancer for a SQL Server Always On availability group in Azure virtual machines that are running with Azure Resource Manager. 当 SQL Server 实例位于 Azure 虚拟机时,可用性组需要负载均衡器。An availability group requires a load balancer when the SQL Server instances are on Azure virtual machines. 负载均衡器存储可用性组侦听器的 IP 地址。The load balancer stores the IP address for the availability group listener. 如果可用性组跨多个区域,则每个区域都需要一个负载均衡器。If an availability group spans multiple regions, each region needs a load balancer.

若要完成此任务,需要在使用 Resource Manager 运行的 Azure 虚拟机上部署一个 SQL Server 可用性组。To complete this task, you need to have a SQL Server availability group deployed on Azure virtual machines that are running with Resource Manager. 这两个 SQL Server 虚拟机必须属于同一个可用性集。Both SQL Server virtual machines must belong to the same availability set.

如果需要,可以 手动配置可用性组If you prefer, you can manually configure an availability group.

本文要求事先配置可用性组。This article requires that your availability groups are already configured.

相关主题包括:Related topics include:

执行本文中的每个步骤可以在 Azure 门户中创建和配置负载均衡器。By walking through this article, you create and configure a load balancer in the Azure portal. 完成该过程后,将配置群集,以将负载均衡器中的 IP 地址用于可用性组侦听器。After the process is complete, you configure the cluster to use the IP address from the load balancer for the availability group listener.

在 Azure 门户中创建并配置负载均衡器Create and configure the load balancer in the Azure portal

在任务的这一部分,将执行以下步骤:In this portion of the task, do the following:

  1. 在 Azure 门户中创建负载均衡器并配置 IP 地址。In the Azure portal, create the load balancer and configure the IP address.
  2. 配置后端池。Configure the back-end pool.
  3. 创建探测。Create the probe.
  4. 设置负载均衡规则。Set the load balancing rules.

备注

如果 SQL Server 实例在多个资源组和区域中,请执行每个步骤两次,在每个资源组中各执行一次。If the SQL Server instances are in multiple resource groups and regions, perform each step twice, once in each resource group.

步骤 1:创建负载均衡器并配置 IP 地址Step 1: Create the load balancer and configure the IP address

首先,请创建负载均衡器。First, create the load balancer.

  1. 在 Azure 门户中,打开包含 SQL Server 虚拟机的资源组。In the Azure portal, open the resource group that contains the SQL Server virtual machines.

  2. 在资源组中,单击“添加”。 In the resource group, click Add.

  3. 搜索“负载均衡器”,然后在搜索结果中选择 Microsoft 发布的“负载均衡器”。 Search for load balancer and then, in the search results, select Load Balancer, which is published by Microsoft.

  4. 在“负载均衡器”边栏选项卡上,单击“创建”。 On the Load Balancer blade, click Create.

  5. 在“创建负载均衡器”对话框中配置负载均衡器,如下所示: In the Create load balancer dialog box, configure the load balancer as follows:

    设置Setting ValueValue
    名称Name 表示负载均衡器的文本名称。A text name representing the load balancer. 例如 sqlLBFor example, sqlLB.
    类型Type 内部:大多数实施方案使用内部负载均衡器,它可让同一虚拟网络中的应用程序连接到可用性组。Internal: Most implementations use an internal load balancer, which allows applications within the same virtual network to connect to the availability group.
    外部:可让应用程序通过公共 Internet 连接连接到可用性组。External: Allows applications to connect to the availability group through a public Internet connection.
    虚拟网络Virtual network 选择 SQL Server 实例所在的虚拟网络。Select the virtual network that the SQL Server instances are in.
    子网Subnet 选择 SQL Server 实例所在的子网。Select the subnet that the SQL Server instances are in.
    IP 地址分配IP address assignment 静态Static
    专用 IP 地址Private IP address 指定子网中的某个可用 IP 地址。Specify an available IP address from the subnet. 在群集上创建侦听器时,请使用此 IP 地址。Use this IP address when you create a listener on the cluster. 本文稍后的 PowerShell 脚本会将此地址用于 $ILBIP 变量。In a PowerShell script, later in this article, use this address for the $ILBIP variable.
    订阅Subscription 如果有多个订阅,可能会显示此字段。If you have multiple subscriptions, this field might appear. 选择要与此资源关联的订阅。Select the subscription that you want to associate with this resource. 通常是与可用性组的所有资源相同的订阅。It is normally the same subscription as all the resources for the availability group.
    资源组Resource group 选择 SQL Server 实例所在的资源组。Select the resource group that the SQL Server instances are in.
    位置Location 选择 SQL Server 实例所在的 Azure 位置。Select the Azure location that the SQL Server instances are in.
  6. 单击创建Click Create.

Azure 创建负载均衡器。Azure creates the load balancer. 该负载均衡器属于特定的网络、子网、资源组和位置。The load balancer belongs to a specific network, subnet, resource group, and location. 在 Azure 完成任务后,请在 Azure 中验证负载均衡器设置。After Azure completes the task, verify the load balancer settings in Azure.

步骤 2:配置后端池Step 2: Configure the back-end pool

Azure 将后端地址池称作“后端池” 。Azure calls the back-end address pool backend pool. 在本例中,后端池是可用性组中两个 SQL Server 实例的地址。In this case, the back-end pool is the addresses of the two SQL Server instances in your availability group.

  1. 在资源组中,单击已创建的负载均衡器。In your resource group, click the load balancer that you created.

  2. 在“设置”中,单击“后端池”。 On Settings, click Backend pools.

  3. 在“后端池”中,单击“添加”创建后端地址池。 On Backend pools, click Add to create a back-end address pool.

  4. 在“添加后端池”中的“名称”下,键入后端池的名称。 On Add backend pool, under Name, type a name for the back-end pool.

  5. 在“虚拟机”下,单击“添加虚拟机”。 Under Virtual machines, click Add a virtual machine.

  6. 在“选择虚拟机”下,单击“选择可用性集”,然后指定 SQL Server 虚拟机所属的可用性集。 Under Choose virtual machines, click Choose an availability set, and then specify the availability set that the SQL Server virtual machines belong to.

  7. 选择可用性集后,请单击“选择虚拟机”,选择在可用性组中托管 SQL Server 实例的两个虚拟机,然后单击“选择”。 After you have chosen the availability set, click Choose the virtual machines, select the two virtual machines that host the SQL Server instances in the availability group, and then click Select.

  8. 单击“确定”,关闭“选择虚拟机”和“添加后端池”边栏选项卡。 Click OK to close the blades for Choose virtual machines, and Add backend pool.

Azure 将更新后端地址池的设置。Azure updates the settings for the back-end address pool. 现在,可用性集有了一个池,其中包含两个 SQL Server 实例。Now your availability set has a pool of two SQL Server instances.

步骤 3:创建探测Step 3: Create a probe

探测定义 Azure 如何确认哪一个 SQL Server 实例当前拥有可用性组侦听器。The probe defines how Azure verifies which of the SQL Server instances currently owns the availability group listener. Azure 根据创建探测时定义的端口上的 IP 地址来探测服务。Azure probes the service based on the IP address on a port that you define when you create the probe.

  1. 在负载均衡器的“设置”边栏选项卡上,单击“运行状况探测”。 On the load balancer Settings blade, click Health probes.

  2. 在“运行状况探测”边栏选项卡上,单击“添加”。 On the Health probes blade, click Add.

  3. 在“添加探测”边栏选项卡上配置探测。 Configure the probe on the Add probe blade. 使用以下值配置探测:Use the following values to configure the probe:

    设置Setting ValueValue
    名称Name 表示探测的文本名称。A text name representing the probe. 例如 SQLAlwaysOnEndPointProbeFor example, SQLAlwaysOnEndPointProbe.
    协议Protocol TCPTCP
    端口Port 可以使用任何可用的端口。You can use any available port. 例如 59999For example, 59999.
    时间间隔Interval 55
    不正常阈值Unhealthy threshold 22
  4. 单击 “确定”Click OK.

备注

确保指定的端口已在两个 SQL Server 实例的防火墙上打开。Make sure that the port you specify is open on the firewall of both SQL Server instances. 这两个实例需要所用 TCP 端口的入站规则。Both instances require an inbound rule for the TCP port that you use. 有关详细信息,请参阅 添加或编辑防火墙规则For more information, see Add or Edit Firewall Rule.

Azure 创建探测,然后使用它来测试哪个 SQL Server 实例具有可用性组的侦听器。Azure creates the probe and then uses it to test which SQL Server instance has the listener for the availability group.

步骤 4:设置负载均衡规则Step 4: Set the load balancing rules

负载均衡规则设置负载均衡器将流量路由到 SQL Server 实例的方式。The load balancing rules configure how the load balancer routes traffic to the SQL Server instances. 对此负载均衡器,需要启用直接服务器返回,因为在两个 SQL Server 实例中,每次只有一个拥有可用性组侦听器资源。For this load balancer, you enable direct server return because only one of the two SQL Server instances owns the availability group listener resource at a time.

  1. 在负载均衡器的“设置”边栏选项卡上,单击“负载均衡规则”。 On the load balancer Settings blade, click Load balancing rules.

  2. 在“负载均衡规则”边栏选项卡上,单击“添加”。 On the Load balancing rules blade, click Add.

  3. 使用“添加负载均衡规则”边栏选项卡配置负载均衡规则。 On the Add load balancing rules blade, configure the load balancing rule. 使用以下设置:Use the following settings:

    设置Setting ValueValue
    名称Name 表示负载均衡规则的文本名称。A text name representing the load balancing rules. 例如 SQLAlwaysOnEndPointListenerFor example, SQLAlwaysOnEndPointListener.
    协议Protocol TCPTCP
    端口Port 14331433
    后端端口Backend Port 1433.将忽略此值,因为此规则使用“浮动 IP (直接服务器返回)”。 1433. This value is ignored because this rule uses Floating IP (direct server return).
    探测Probe 使用为此负载均衡器创建的探测的名称。Use the name of the probe that you created for this load balancer.
    会话持久性Session persistence None
    空闲超时(分钟)Idle timeout (minutes) 44
    浮动 IP (直接服务器返回)Floating IP (direct server return) EnabledEnabled

    备注

    可能需要在边栏选项卡中向下滚动才能查看所有设置。You might have to scroll down the blade to view all the settings.

  4. 单击 “确定”Click OK.

  5. Azure 配置负载均衡规则。Azure configures the load balancing rule. 负载均衡器现已配置为将流量路由到托管可用性组侦听器的 SQL Server 实例。Now the load balancer is configured to route traffic to the SQL Server instance that hosts the listener for the availability group.

此时,资源组有一个连接到这两个 SQL Server 计算机的负载均衡器。At this point, the resource group has a load balancer that connects to both SQL Server machines. 负载均衡器还包含 SQL Server AlwaysOn 可用性组侦听器的 IP 地址,以便任一计算机可以响应针对可用性组的请求。The load balancer also contains an IP address for the SQL Server Always On availability group listener, so that either machine can respond to requests for the availability groups.

备注

如果 SQL Server 实例位于两个不同的区域,请在另一个区域重复上述步骤。If your SQL Server instances are in two separate regions, repeat the steps in the other region. 每个区域都需要一个负载均衡器。Each region requires a load balancer.

将群集配置为使用负载均衡器 IP 地址Configure the cluster to use the load balancer IP address

下一步是在群集上配置侦听器,并将侦听器联机。The next step is to configure the listener on the cluster, and bring the listener online. 请执行以下操作:Do the following:

  1. 在故障转移群集上创建可用性组侦听器。Create the availability group listener on the failover cluster.

  2. 使侦听器联机。Bring the listener online.

步骤 5:在故障转移群集上创建可用性组侦听器Step 5: Create the availability group listener on the failover cluster

在此步骤中,你在故障转移群集管理器和 SQL Server Management Studio 中手动创建可用性组侦听器。In this step, you manually create the availability group listener in Failover Cluster Manager and SQL Server Management Studio.

可用性组侦听器是 SQL Server 可用性组侦听的 IP 地址和网络名称。The availability group listener is an IP address and network name that the SQL Server availability group listens on. 若要创建可用性组侦听器,请执行以下操作:To create the availability group listener, do the following:

  1. 获取群集网络资源的名称。Get the name of the cluster network resource.

    a.a. 使用 RDP 连接到托管主副本的 Azure 虚拟机。Use RDP to connect to the Azure virtual machine that hosts the primary replica.

    b.b. 打开故障转移群集管理器。Open Failover Cluster Manager.

    c.c. 选择“网络”节点,并记下群集网络名称。 Select the Networks node, and note the cluster network name. 在 PowerShell 脚本的 $ClusterNetworkName 变量中使用此名称。Use this name in the $ClusterNetworkName variable in the PowerShell script. 在下图中,群集网络名称为“群集网络 1”: In the following image the cluster network name is Cluster Network 1:

    群集网络名称 Cluster Network Name

  2. 添加客户端接入点。Add the client access point.
    客户端接入点是应用程序用来连接到可用性组中的数据库的网络名称。The client access point is the network name that applications use to connect to the databases in an availability group. 可在故障转移群集管理器中创建客户端接入点。Create the client access point in Failover Cluster Manager.

    a.a. 展开群集名称,并单击“角色”。 Expand the cluster name, and then click Roles.

    b.b. 在“角色”窗格中,右键单击可用性组名称,并选择“添加资源” > “客户端接入点”。 In the Roles pane, right-click the availability group name, and then select Add Resource > Client Access Point.

    客户端接入点

    c.c. 在“名称”框中,创建新侦听器的名称。 In the Name box, create a name for this new listener. 新侦听器的名称是应用程序用来连接 SQL Server 可用性组中数据库的网络名称。The name for the new listener is the network name that applications use to connect to databases in the SQL Server availability group.

    d.d. 如果要完成创建侦听器,请单击“下一步”两次,并单击“完成”。 To finish creating the listener, click Next twice, and then click Finish. 不要在此时使侦听器或资源联机。Do not bring the listener or resource online at this point.

  3. 使可用性组群集角色脱机。Take the availability group cluster role offline. 在“故障转移群集管理器” 的“角色” 下,右键单击角色,然后选择“停止角色” 。In Failover Cluster Manager under Roles, right-click the role, and select Stop Role.

  4. 配置可用性组的 IP 资源。Configure the IP resource for the availability group.

    a.a. 单击“资源”选项卡,并展开创建的客户端接入点。 Click the Resources tab, and then expand the client access point you created.
    客户端接入点处于脱机状态。The client access point is offline.

    客户端接入点

    b.b. 右键单击 IP 资源,并单击“属性”。Right-click the IP resource, and then click properties. 记下 IP 地址的名称,将其用在 PowerShell 脚本的 $IPResourceName 变量中。Note the name of the IP address, and use it in the $IPResourceName variable in the PowerShell script.

    c.c. 在“IP 地址”下面,单击“静态 IP 地址”。 Under IP Address, click Static IP Address. 将 IP 地址设置为在 Azure 门户中设置负载均衡器地址时所用的同一地址。Set the IP address as the same address that you used when you set the load balancer address on the Azure portal.

    IP 资源

    1. 使 SQL Server 可用性组资源依赖于客户端接入点。1. Make the SQL Server availability group resource dependent on the client access point.

    a.a. 在故障转移群集管理器中,单击“角色” ,然后单击可用性组。In Failover Cluster Manager, click Roles, and then click your availability group.

    b.b. 在“资源” 选项卡的“其他资源”下,右键单击可用性资源组,然后单击“属性” 。On the Resources tab, under Other Resources, right-click the availability resource group, and then click Properties.

    c.c. 在依赖关系选项卡上,添加客户端接入点(侦听器)资源的名称。On the dependencies tab, add the name of the client access point (the listener) resource.

    IP 资源

    d.d. 单击 “确定”Click OK.

  5. 使客户端接入点资源依赖于 IP 地址。Make the client access point resource dependent on the IP address.

    a.a. 在故障转移群集管理器中,单击“角色” ,然后单击可用性组。In Failover Cluster Manager, click Roles, and then click your availability group.

    b.b. 在“资源”选项卡中,右键单击“服务器名称”下面的客户端接入点资源,并单击“属性”。 On the Resources tab, right-click the client access point resource under Server Name, and then click Properties.

    IP 资源

    c.c. 选择“依赖项”选项卡。 验证 IP 地址是否为依赖项。Click the Dependencies tab. Verify that the IP address is a dependency. 如果不是,则设置 IP 地址的依赖项。If it is not, set a dependency on the IP address. 如果有多个资源列出,请验证 IP 地址具有 OR 而不是 AND 依赖项。If there are multiple resources listed, verify that the IP addresses have OR, not AND, dependencies. 单击 “确定”Click OK.

    IP 资源

    提示

    可以验证是否正确配置了依赖项。You can validate that the dependencies are correctly configured. 在故障转移群集管理器中,转到“角色”,右键单击可用性组,单击“更多操作” ,然后单击“显示依赖项报告” 。In Failover Cluster Manager, go to Roles, right-click the availability group, click More Actions, and then click Show Dependency Report. 正确配置依赖项后,可用性组将依赖于网络名称,网络名称将依赖于 IP 地址。When the dependencies are correctly configured, the availability group is dependent on the network name, and the network name is dependent on the IP address.

  6. 在 PowerShell 中设置群集参数。Set the cluster parameters in PowerShell.

    a.a. 将以下 PowerShell 脚本复制到某个 SQL Server 实例。Copy the following PowerShell script to one of your SQL Server instances. 请更新环境的变量。Update the variables for your environment.

    • $ListenerILBIP 是在 Azure 负载均衡器上为可用性组侦听程序创建的 IP 地址。$ListenerILBIP is the IP address that you created on the Azure load balancer for the availability group listener.

    • $ListenerProbePort 是在 Azure 负载均衡器上为可用性组侦听程序配置的端口。$ListenerProbePort is the port you configured on the Azure load balancer for the availability group listener.

    $ClusterNetworkName = "<MyClusterNetworkName>" # the cluster network name (Use Get-ClusterNetwork on Windows Server 2012 of higher to find the name)
    $IPResourceName = "<IPResourceName>" # the IP Address resource name
    $ListenerILBIP = "<n.n.n.n>" # the IP Address of the Internal Load Balancer (ILB). This is the static IP address for the load balancer you configured in the Azure portal.
    [int]$ListenerProbePort = <nnnnn>
    
    Import-Module FailoverClusters
    
    Get-ClusterResource $IPResourceName | Set-ClusterParameter -Multiple @{"Address"="$ListenerILBIP";"ProbePort"=$ListenerProbePort;"SubnetMask"="255.255.255.255";"Network"="$ClusterNetworkName";"EnableDhcp"=0}
    

    b.b. 通过在某个群集节点上运行 PowerShell 脚本设置群集参数。Set the cluster parameters by running the PowerShell script on one of the cluster nodes.

    备注

    如果 SQL Server 实例位于不同的区域,则需要运行 PowerShell 脚本两次。If your SQL Server instances are in separate regions, you need to run the PowerShell script twice. 第一次运行时,请从第一个区域中选择 $ListenerILBIP$ListenerProbePortThe first time, use the $ListenerILBIP and $ListenerProbePort from the first region. 第二次运行时,请从第二个区域中选择 $ListenerILBIP$ListenerProbePortThe second time, use the $ListenerILBIP and $ListenerProbePort from the second region. 每个区域的群集网络名称和群集 IP 资源名称也不同。The cluster network name and the cluster IP resource name are also different for each region.

  7. 使可用性组群集角色联机。Bring the availability group cluster role online. 在“故障转移群集管理器” 的“角色” 下,右键单击角色,然后选择“启动角色” 。In Failover Cluster Manager under Roles, right click the role, and select Start Role.

如有必要,重复上述步骤以设置 WSFC 群集 IP 地址的群集参数。If necessary, repeat the steps above to set the cluster parameters for the WSFC cluster IP address.

  1. 获取 WSFC 群集 IP 地址的 IP 地址名称。Get the IP address name of the WSFC Cluster IP address. 在“故障转移群集管理器” 中的“群集核心资源” 下,找到“服务器名称” 。In Failover Cluster Manager under Cluster Core Resources, locate Server Name.

  2. 右键单击“IP 地址” ,并选择“属性” 。Right-click IP Address, and select Properties.

  3. 记下 IP 地址的名称Copy the Name of the IP address. 该项可能为 Cluster IP AddressIt may be Cluster IP Address.

  4. 在 PowerShell 中设置群集参数。Set the cluster parameters in PowerShell.

    a.a. 将以下 PowerShell 脚本复制到某个 SQL Server 实例。Copy the following PowerShell script to one of your SQL Server instances. 请更新环境的变量。Update the variables for your environment.

    • $ClusterCoreIP 是在 Azure 负载均衡器上为 WSFC 核心群集资源创建的 IP 地址。$ClusterCoreIP is the IP address that you created on the Azure load balancer for the WSFC core cluster resource. 它不同于可用性组侦听程序的 IP 地址。It is different from the IP address for the availability group listener.

    • $ClusterProbePort 是在 Azure 负载均衡器上为 WSFC 运行状况探测配置的端口。$ClusterProbePort is the port you configured on the Azure load balancer for the WSFC health probe. 它不同于可用性组侦听程序的探测。It is different from the probe for the availability group listener.

    $ClusterNetworkName = "<MyClusterNetworkName>" # the cluster network name (Use Get-ClusterNetwork on Windows Server 2012 of higher to find the name)
    $IPResourceName = "<ClusterIPResourceName>" # the IP Address resource name
    $ClusterCoreIP = "<n.n.n.n>" # the IP Address of the Cluster IP resource. This is the static IP address for the load balancer you configured in the Azure portal.
    [int]$ClusterProbePort = <nnnnn> # The probe port from the WSFCEndPointprobe in the Azure portal. This port must be different from the probe port for the availability group listener probe port.
    
    Import-Module FailoverClusters
    
    Get-ClusterResource $IPResourceName | Set-ClusterParameter -Multiple @{"Address"="$ClusterCoreIP";"ProbePort"=$ClusterProbePort;"SubnetMask"="255.255.255.255";"Network"="$ClusterNetworkName";"EnableDhcp"=0}
    

    b.b. 通过在某个群集节点上运行 PowerShell 脚本设置群集参数。Set the cluster parameters by running the PowerShell script on one of the cluster nodes.

警告

可用性组侦听程序运行状况探测端口必须不同于群集核心 IP 地址运行状况探测端口。The availability group listener health probe port has to be different from the cluster core IP address health probe port. 在这些示例中,侦听程序端口为 59999,群集核心 IP 地址为 58888。In these examples, the listener port is 59999 and the cluster core IP address is 58888. 这两个端口都要求允许入站防火墙规则。Both ports require an allow inbound firewall rule.

验证侦听器的配置Verify the configuration of the listener

如果正确配置了群集资源和依赖项,应能够查看 SQL Server Management Studio 中的侦听器。If the cluster resources and dependencies are correctly configured, you should be able to view the listener in SQL Server Management Studio. 若要设置侦听器端口,请执行以下操作:To set the listener port, do the following:

  1. 启动 SQL Server Management Studio,然后连接到主副本。Start SQL Server Management Studio, and then connect to the primary replica.

  2. 转到“AlwaysOn 高可用性” > “可用性组” > “可用性组侦听器”。 Go to AlwaysOn High Availability > Availability Groups > Availability Group Listeners.
    现在应看到在故障转移群集管理器中创建的侦听器名称。You should now see the listener name that you created in Failover Cluster Manager.

  3. 右键单击侦听器名称,并单击“属性”。 Right-click the listener name, and then click Properties.

  4. 在“端口”框中,通过使用先前使用过的 $EndpointPort 为可用性组侦听器指定端口号(默认值为 1433),然后单击“确定”。 In the Port box, specify the port number for the availability group listener by using the $EndpointPort you used earlier (1433 was the default), and then click OK.

现在,在 Resource Manager 模式下运行的 Azure 虚拟机中有了一个可用性组。You now have an availability group in Azure virtual machines running in Resource Manager mode.

测试与侦听器的连接Test the connection to the listener

若要测试连接,请执行以下操作:Test the connection by doing the following:

  1. 通过 RDP 连接到同一虚拟网络中不拥有副本的 SQL Server 实例。RDP to a SQL Server instance that is in the same virtual network, but does not own the replica. 此服务可以是群集中的其他 SQL Server 实例。This server can be the other SQL Server instance in the cluster.

  2. 使用 sqlcmd 实用工具测试连接。Use sqlcmd utility to test the connection. 例如,以下脚本通过侦听器与 Windows 身份验证来与主副本建立 sqlcmd 连接:For example, the following script establishes a sqlcmd connection to the primary replica through the listener with Windows authentication:

     sqlcmd -S <listenerName> -E
    

SQLCMD 连接会自动连接到托管主副本的 SQL Server 实例。The SQLCMD connection automatically connects to the SQL Server instance that hosts the primary replica.

为其他可用性组创建一个 IP 地址Create an IP address for an additional availability group

每个可用性组使用单独的侦听器。Each availability group uses a separate listener. 每个侦听器都有自己的 IP 地址。Each listener has its own IP address. 使用同一个负载均衡器以保留其他侦听器的 IP 地址。Use the same load balancer to hold the IP address for additional listeners. 创建可用性组后,请将 IP 地址添加到负载均衡器,然后配置侦听器。After you create an availability group, add the IP address to the load balancer, and then configure the listener.

若要使用 Azure 门户将 IP 地址添加到负载均衡器,请执行以下操作:To add an IP address to a load balancer with the Azure portal, do the following:

  1. 在 Azure 门户中,打开包含负载均衡器的资源组,然后单击负载均衡器。In the Azure portal, open the resource group that contains the load balancer, and then click the load balancer.

  2. 在“设置”下面,单击“前端 IP 池”,然后单击“添加”。 Under SETTINGS, click Frontend IP pool, and then click Add.

  3. 在“添加前端 IP 地址” 下,为前端分配名称。Under Add frontend IP address, assign a name for the front end.

  4. 验证“虚拟网络” 和“子网” 是否与 SQL Server 实例相同。Verify that the Virtual network and the Subnet are the same as the SQL Server instances.

  5. 设置侦听器的 IP 地址。Set the IP address for the listener.

    提示

    可将 IP 地址设置为静态,并键入子网中当前未使用的地址。You can set the IP address to static and type an address that is not currently used in the subnet. 也可将 IP 地址设置为动态,并保存新的前端 IP 池。Alternatively, you can set the IP address to dynamic and save the new front-end IP pool. 执行此操作时,Azure 门户会自动向池分配可用的 IP 地址。When you do so, the Azure portal automatically assigns an available IP address to the pool. 然后可以重新打开前端 IP 池,并将分配更改为静态。You can then reopen the front-end IP pool and change the assignment to static.

  6. 保存侦听器的 IP 地址。Save the IP address for the listener.

  7. 使用以下设置添加运行状况探测:Add a health probe by using the following settings:

    设置Setting ValueValue
    名称Name 用于标识探测的名称。A name to identify the probe.
    协议Protocol TCPTCP
    端口Port 一个未使用的 TCP 端口,必须在所有虚拟机上可用。An unused TCP port, which must be available on all virtual machines. 此端口不能用于任何其他用途。It cannot be used for any other purpose. 两个侦听器不能使用相同的探测端口。No two listeners can use the same probe port.
    时间间隔Interval 探测尝试之间的时间长短。The amount of time between probe attempts. 使用默认值 (5)。Use the default (5).
    不正常阈值Unhealthy threshold 在将虚拟机视为运行状况不正常之前连续阈值应失败的次数。The number of consecutive thresholds that should fail before a virtual machine is considered unhealthy.
  8. 单击“确定” 保存探测。Click OK to save the probe.

  9. 创建负载均衡规则。Create a load balancing rule. 单击“负载均衡规则”,然后单击“+ 添加”。 Click Load balancing rules, and then click Add.

  10. 使用以下设置配置新的负载均衡规则:Configure the new load balancing rule by using the following settings:

    设置Setting ValueValue
    名称Name 用于标识负载均衡规则的名称。A name to identify the load balancing rule.
    “前端 IP 地址” Frontend IP address 选择所创建的 IP 地址。Select the IP address you created.
    协议Protocol TCPTCP
    端口Port 使用 SQL Server 实例正在使用的端口。Use the port that the SQL Server instances are using. 在不更改的情况下,默认实例使用端口 1433。A default instance uses port 1433, unless you changed it.
    后端端口 Backend port 使用与“端口”相同的值 。Use the same value as Port.
    后端池 Backend pool 包含具有 SQL Server 实例的虚拟机的池。The pool that contains the virtual machines with the SQL Server instances.
    运行状况探测 Health probe 选择所创建的探测。Choose the probe you created.
    会话持久性Session persistence None
    空闲超时(分钟)Idle timeout (minutes) 默认值 (4)Default (4)
    浮动 IP (直接服务器返回)Floating IP (direct server return) EnabledEnabled

将可用性组配置为使用新 IP 地址Configure the availability group to use the new IP address

若要完成配置群集,请重复配置第一个可用性组时所遵照的步骤。To finish configuring the cluster, repeat the steps that you followed when you made the first availability group. 也就是说,将群集配置为使用新 IP 地址That is, configure the cluster to use the new IP address.

为侦听器添加了 IP 地址后,可执行以下操作配置其他可用性组:After you have added an IP address for the listener, configure the additional availability group by doing the following:

  1. 验证两个 SQL Server 虚拟机上新 IP 地址的探测端口是否处于打开状态。Verify that the probe port for the new IP address is open on both SQL Server virtual machines.

  2. 在群集管理器中,添加客户端接入点In Cluster Manager, add the client access point.

  3. 配置可用性组的 IP 资源Configure the IP resource for the availability group.

    重要

    创建 IP 地址时,请使用已添加到负载均衡器的 IP 地址。When you create the IP address, use the IP address that you added to the load balancer.

  4. 使 SQL Server 可用性组资源依赖于客户端接入点Make the SQL Server availability group resource dependent on the client access point.

  5. 使客户端接入点资源依赖于 IP 地址Make the client access point resource dependent on the IP address.

  6. 在 PowerShell 中设置群集参数Set the cluster parameters in PowerShell.

将可用性组配置为使用新 IP 地址时,请配置到侦听器的连接。After you configure the availability group to use the new IP address, configure the connection to the listener.

向分布式可用性组添加负载均衡规则Add load balancing rule for distributed availability group

如果分布式可用性组中使用了可用性组,则负载均衡器需应用其他规则。If an availability group participates in a distributed availability group, the load balancer needs an additional rule. 此规则会存储分布式可用性组侦听器所用的端口。This rule stores the port used by the distributed availability group listener.

重要

此步骤仅适用于分布式可用性组中未涉及到任何可用性组的情况。This step only applies if the availability group participates in a distributed availability group.

  1. 在参与到分布式可用性组的每个服务器上,针对分布式可用性组侦听器 TCP 端口创建一个入站规则。On each server that participates in the distributed availability group, create an inbound rule on the distributed availability group listener TCP port. 在很多示例中,文档都使用 5022。In many examples, documentation uses 5022.

  2. 在 Azure 门户中,依次单击负载均衡器、“负载均衡规则”和“+添加” 。In the Azure portal, click on the load balancer and click Load balancing rules, and then click +Add.

  3. 通过以下设置创建负载均衡规则:Create the load balancing rule with the following settings:

    设置Setting ValueValue
    名称Name 用于定义分布式可用性组的负载均衡规则的名称。A name to identify the load balancing rule for the distributed availability group.
    前端 IP 地址Frontend IP address 与可用性组使用相同的前端 IP 地址。Use the same frontend IP address as the availability group.
    协议Protocol TCPTCP
    端口Port 5022 - 用于 分布式可用性组终结点侦听器 的端口。5022 - The port for the distributed availability group endpoint listener.
    可为任何可用端口。Can be any available port.
    后端端口 Backend port 5022 - 使用与“端口”相同的值 。5022 - Use the same value as Port.
    后端池 Backend pool 包含具有 SQL Server 实例的虚拟机的池。The pool that contains the virtual machines with the SQL Server instances.
    运行状况探测 Health probe 选择所创建的探测。Choose the probe you created.
    会话持久性Session persistence None
    空闲超时(分钟)Idle timeout (minutes) 默认值 (4)Default (4)
    浮动 IP (直接服务器返回)Floating IP (direct server return) EnabledEnabled

在参与到分布式可用性组的其他可用性组上,针对负载均衡器重复这些步骤。Repeat these steps for the load balancer on the other availability groups that participate in the distributed availability groups.

如果要限制 Azure 网络安全组的访问权限,请确保“允许”规则包含后端 SQL Server VM IP 地址、可用性组侦听器的负载均衡器浮动 IP 地址、群集核心 IP 地址(如适用)。If you are restricting access with an Azure Network Security Group, ensure that the allow rules include the backend SQL Server VM IP addresses, and the load balancer floating IP addresses for the AG listener and the cluster core IP address, if applicable.

后续步骤Next steps