Exporteren (0) Afdrukken
Alles uitvouwen
EN
Deze inhoud is niet beschikbaar in uw taal, maar wel in het Engels.

Tutorial: Listener Configuration for AlwaysOn Availability Groups

Updated: June 12, 2014

This topic shows you how to configure a listener for an AlwaysOn Availability Group. Your Availability Group can contain replicas that are on-premises only, Azure only, or span both on-premises and Azure for hybrid configurations. Azure replicas can reside within the same region or across multiple regions using multiple virtual networks (VNets).

The steps below assume you have already configured an availability group but have not configured a listener. Note the following limitations on the availability group listener in Azure:

  • The availability group listener is supported on Windows Server 2008 R2, Windows Server 2012, and Windows Server 2012 R2.

  • The client application must reside on a different cloud service than the one that contains your availability group VMs. Azure does not support direct server return with client and server in the same cloud service.

  • Only one availability group listener is supported per cloud service because the listener is configured to use the cloud service IP address.

  • If you are creating a listener for a hybrid environment, the on-premises network must have connectivity to the public Internet in addition to the site-to-site VPN with the Azure virtual network. When in the Azure subnet, the availability group listener is reachable only by the public IP address of the respective cloud service.

ImportantImportant
On-premises Availability Group listeners can be configured using SQL Server Management Studio (SSMS) graphical user interface, through Transact-SQL, and through PowerShell. However, there is currently no configurable option in the Azure portal for you to enable direct server return (DSR) when creating a listener. This tutorial focuses on using PowerShell to create a listener for an Availability Group that includes Azure replicas. For more information on how to configure listeners using SSMS or Transact-SQL, see Create or Configure an Availability Group Listener.

Step 1: Create load-balanced VM endpoints with direct server return in Azure

First, you need to create a load-balanced endpoint for each VM hosting an Azure replica. If you have replicas in multiple regions, each replica for that region must be in the same cloud service in the same VNet. Creating Availability Group replicas that span multiple Azure regions requires configuring multiple VNets. For more information on configuring cross VNet connectivity, see Configure VNet to VNet Connectivity.

  1. In the Azure portal, navigate to each VM hosting a replica and view the details.

  2. Click the Endpoints tab for each of the VMs.

  3. Verify that the Name and Public Port of the listener endpoint you want to use is not already in use.

  4. On your local client, download and install Azure PowerShell June 2013 or later.

  5. Launch Azure PowerShell. A new PowerShell session is opened with the Azure administrative modules loaded.

  6. Run Get-AzurePublishSettingsFile. This cmdlet directs you to a browser to download a publish settings file to a local directory. You may be prompted for your log-in credentials for your Azure subscription.

  7. Run the following command with the path of the publish settings file that you downloaded.

    Import-AzurePublishSettingsFile -PublishSettingsFile <PublishSettingsFilePath>
    

    Once the publish settings file is imported, you can manage your Azure subscription in the PowerShell session.

  8. Copy the PowerShell script below into a text editor and set the variable values to suit your environment.

    # Define variables
    $AGNodes = "<VM1>","<VM2>","<VM3>" # all availability group nodes should be included, separated by commas
    $ServiceName = "<MyCloudService>" # the name of the cloud service that contains the availability group nodes
    $EndpointName = "<MyEndpoint>" # name of the endpoint
    $EndpointPort = "<PortNumber>" # public port to use for the endpoint
    
    # Configure a load balanced endpoint for each node in $AGNodes, with direct server return enabled
    ForEach ($node in $AGNodes)
    {
        Get-AzureVM -ServiceName $ServiceName -Name $node | Add-AzureEndpoint -Name $EndpointName -Protocol "TCP" -PublicPort $EndpointPort -LocalPort $EndpointPort -LBSetName "$EndpointName-LB" -ProbePort 59999 -ProbeProtocol "TCP" -DirectServerReturn $true | Update-AzureVM
    }
    
  9. Once you have set the variables, copy the script from the text editor into your Azure PowerShell session to run it. If the prompt still shows >>, type ENTER again to make sure the script starts running.

Step 2: Make sure KB2854082 is installed on all Windows Server 2008 R2 and Windows Server 2012 cluster nodes

Next, you need to make sure that the hotfix KB2854082 is installed on each of the on-premises server or Azure VM that is part of the cluster. Any server or VM that is in the cluster, but not in the availability group, should also have this hotfix installed.

In the remote desktop session for each of the cluster nodes, download KB2854082 to a local directory. Then, install the hotfix on each of the cluster nodes sequentially. If the cluster service is currently running on the cluster node, the server is restarted at the end of the hotfix installation.

WarningWarning
Stopping the cluster service or restarting the server affects the quorum health of your cluster and the availability group, and may cause your cluster to go offline. To maintain the high availability of your cluster during installation, make sure that:

  • The cluster is in optimal quorum health,

  • All cluster nodes are online before installing the hotfix on any node, and

  • Allow the hotfix installation to run to completion on one node, including fully restarting the server, before installing the hotfix on any other node in the cluster.

Step 3: Open the firewall ports in availability group nodes in Azure

In this step, you create a firewall rule to open the probe port for the load-balanced endpoint (59999 as specified earlier), and another rule to open the availability group listener port. Since you created the load-balanced endpoint on the Azure VMs that contain availability group replicas, you need to open the probe port and the listener port on the respective Azure VMs.

  1. On VM hosting a replica, launch Windows Firewall with Advanced Security.

  2. Right-click Inbound Rules and click New Rule.

  3. In the Rule Type page, select Port, then click Next.

  4. In the Protocol and Ports page, select TCP and type 59999 in the Specific local ports box. Then, click Next.

  5. In the Action page, keep Allow the connection selected and click Next.

  6. In the Profile page, accept the default settings and click Next.

  7. In the Name page, specify a rule name, such as AlwaysOn Listener Probe Port in the Name text box, and click Finish.

  8. Repeat the above steps for the availability group listener port (as specified earlier in the $EndpointPort parameter) and specify an appropriate rule name, such as AlwaysOn Listener Port.

Step 4: Create the availability group listener

In this step, you manually create the availability group listener in Failover Cluster Manager and SQL Server Management Studio (SSMS).

  1. Open Failover Cluster Manager from the node hosting the primary replica.

  2. Expand the cluster name, then click Roles.

  3. In the Roles pane, right-click the availability group name and then select Add Resource > Client Access Point.

    Add Client Access Point for Availability Group

  4. In the Name box, type the desired listener name, then click Next twice, and then click Finish.

  5. Click the Resources tab, then expand the Client Access Point you just created. You will see the IP address resource for each of the cluster networks in your cluster.

  6. If you are configuring a hybrid solution, continue with this step. If you are configuring an Azure only solution, skip to the next step.

    1. Right-click the IP Address resource that corresponds to your on-premises subnet, then select Properties. Note the IP Address Name and the Network Name.

    2. Select Static IP Address, assign an unused IP address and then click OK.



  7. Right-click the IP resource that corresponds to your Azure subnet and then select Properties. Note the IP Address Name and the Network Name. Repeat this step for each IP resource if your solution spans multiple Azure VNets.

  8. Log into the Azure portal. Navigate to the cloud service that contains your availability group VM. Open the Dashboard view. Note the address shown under Public Virtual IP (VIP) Address. Repeat this step for each cloud service that contains a VM that hosts an availability replica in this solution.

  9. On each Azure VM, copy the PowerShell script below into a text editor and set the variables to the values you noted earlier. Make sure to enter the values specific for the subnet for the VM you are working on.

    # Define variables
    $ClusterNetworkName = "<ClusterNetworkName>" # the cluster network name
    $IPResourceName = "<IPResourceName>" # the IP Address resource name 
    $CloudServiceIP = "X.X.X.X" # IP address of your cloud service
    Import-Module FailoverClusters
    Get-ClusterResource $IPResourceName | Set-ClusterParameter -Multiple @{"Address"="$CloudServiceIP";"ProbePort"="59999";SubnetMask="255.255.255.255";"Network"="$ClusterNetworkName";"OverrideAddressMatch"=1;"EnableDhcp"=0}
    
    
  10. Once you have set the variables, open an elevated Windows PowerShell window, then copy the script from the text editor and paste into your Azure PowerShell session to run it. If the prompt still shows >>, type ENTER again to make sure the script starts running. Repeat this on each VM.

    This script configures the IP Address resource with the IP address of the cloud service and sets other parameters like the probe port. When the IP Address resource is brought online, it can then respond to the polling on the probe port from the load-balanced endpoint created earlier in this tutorial.

  11. Navigate back to Failover Cluster Manager. Expand Roles and then highlight your Availability Group. On the Resources tab, right-click the listener name and click Properties.

  12. Click the Dependencies tab, verify the IP addresses have OR, not AND, dependencies. Click OK.

  13. Right-click the listener name and click Bring Online .

  14. Once the listener is online, from the Resources tab, right-click the availability group and click Properties.

    Configure the Availability Group Resource

  15. Create a dependency on the listener name resource.

    Add Dependency on the Listener Name

  16. Launch SQL Server Management Studio and connect to the primary replica.

  17. Navigate to AlwaysOn High Availability > Availability Groups > <AvailabilityGroupName> > Availability Group Listeners. You should now see the listener name that you created in Failover Cluster Manager. Right-click the listener name and click Properties.

  18. In the Port box, specify the port number for the availability group listener by using the $EndpointPort you used earlier, then click OK.

Step 5: Follow-up after creating the availability group listener

After the availability group listener is created, it may be necessary to adjust the RegisterAllProvidersIP and HostRecordTTL cluster parameters for the listener resource. These parameters may reduce reconnection time after a failover which may prevent connection timeouts. For more information on these parameters, as well as sample code, see Create or Configure an Availability Group Listener.

Step 6: Test the availability group listener

In this step, you test the availability group listener using a client application. An easy way to complete this test is to try to connect SSMS to the availability group listener. Another simple method is to run SQLCMD.exe as follows:

sqlcmd –S "<ListenerName>,<EndpointPort>" -d "<DatabaseName>" -Q "select @@servername, db_name()" -l 15

When testing the listener, be sure to fail over the availability group to make sure that clients can connect to the listener across failovers.

Community-inhoud

Toevoegen
Weergeven:
© 2014 Microsoft