Skip to content

Latest commit

 

History

History
220 lines (158 loc) · 11.8 KB

File metadata and controls

220 lines (158 loc) · 11.8 KB
title Configure SQL Server Always On Availability Group for high availability on Linux | Microsoft Docs
description
author MikeRayMSFT
ms.author mikeray
manager craigg
ms.date 02/14/2018
ms.topic article
ms.prod sql
ms.component
ms.suite sql
ms.custom sql-linux
ms.technology linux
ms.assetid

Configure SQL Server Always On Availability Group for high availability on Linux

[!INCLUDEappliesto-ss-xxxx-xxxx-xxx-md-linuxonly]

This article describes how to create a SQL Server Always On Availability Group (AG) for high availability on Linux. There are two configuration types for AGs. A high availability configuration uses a cluster manager to provide business continuity. This configuration can also include read-scale replicas. This document explains how to create the AG for high availability.

You can also create an AG without a cluster manager for read-scale. The AG for read scale only provides read-only replicas for performance scale-out. It does not provide high availability. To create an AG for read-scale, see Configure a SQL Server Availability Group for read-scale on Linux.

Configurations that guarantee high availability and data protection require either two or three synchronous commit replicas. With three synchronous replicas, the AG can automatically recover even if one server is not available. For more information, see High availability and data protection for Availability Group configurations.

All servers must be either physical or virtual, and virtual servers must be on the same virtualization platform. This requirement is because the fencing agents are platform specific. See Policies for Guest Clusters.

Roadmap

The steps to create an AG on Linux servers for high availability are different from the steps on a Windows Server failover cluster. The following list describes the high-level steps:

  1. Configure SQL Server on three cluster servers.

    [!IMPORTANT] All three servers in the AG need to be on the same platform - physical or virtual - because Linux high availability uses fencing agents to isolate resources on servers. The fencing agents are specific for each platform.

  2. Create the AG. This step is covered in this current article.

  3. Configure a cluster resource manager, like Pacemaker.

    The way to configure a cluster resource manager depends on the specific Linux distribution. See the following links for distribution specific instructions:

    [!IMPORTANT] Production environments require a fencing agent, like STONITH for high availability. The demonstrations in this documentation do not use fencing agents. The demonstrations are for testing and validation only.

    A Linux cluster uses fencing to return the cluster to a known state. The way to configure fencing depends on the distribution and the environment. Currently, fencing is not available in some cloud environments. For more information, see Support Policies for RHEL High Availability Clusters - Virtualization Platforms.

    For SLES, see SUSE Linux Enterprise High Availability Extension.

  4. Add the AG as a resource in the cluster.

    The way to add the AG as a resource in the cluster depends on the Linux distribution. See the following links for distribution specific instructions:

[!INCLUDE Create Prerequisites]

Create the AG

For a high availability configuration that ensures automatic failover, the AG requires at least three replicas. Either of the following configurations can support high availability:

For information, see High availability and data protection for Availability Group configurations.

Note

The availability groups can include additional synchronous or asynchronous replicas.

Create the AG for high availability on Linux. Use the CREATE AVAILABILITY GROUP with CLUSTER_TYPE = EXTERNAL.

  • Availability group - CLUSTER_TYPE = EXTERNAL Specifies that an external cluster entity manages the AG. Pacemaker is an example of an external cluster entity. When the AG cluster type is external,

  • Set Primary and secondary replicas FAILOVER_MODE = EXTERNAL. Specifies that the replica interacts with an external cluster manager, like Pacemaker.

The following Transact-SQL scripts create an AG for high availability named ag1. The script configures the AG replicas with SEEDING_MODE = AUTOMATIC. This setting causes SQL Server to automatically create the database on each secondary server. Update the following script for your environment. Replace the <node1>, <node2>, or <node3> values with the names of the SQL Server instances that host the replicas. Replace the <5022> with the port you set for the data mirroring endpoint. To create the AG, run the following Transact-SQL on the SQL Server instance that hosts the primary replica.

Run only one of the following scripts:

  • Create AG with three synchronous replicas

    CREATE AVAILABILITY GROUP [ag1]
        WITH (DB_FAILOVER = ON, CLUSTER_TYPE = EXTERNAL)
        FOR REPLICA ON
            N'<node1>' 
    	      	WITH (
     	       ENDPOINT_URL = N'tcp://<node1>:<5022>',
     	       AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
     	       FAILOVER_MODE = EXTERNAL,
     	       SEEDING_MODE = AUTOMATIC
     	       ),
            N'<node2>' 
     	    WITH ( 
     	       ENDPOINT_URL = N'tcp://<node2>:<5022>', 
     	       AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
     	       FAILOVER_MODE = EXTERNAL,
     	       SEEDING_MODE = AUTOMATIC
     	       ),
     	   N'<node3>'
            WITH( 
     	      ENDPOINT_URL = N'tcp://<node3>:<5022>', 
     	      AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
     	      FAILOVER_MODE = EXTERNAL,
     	      SEEDING_MODE = AUTOMATIC
     	      );
    		
    ALTER AVAILABILITY GROUP [ag1] GRANT CREATE ANY DATABASE;

    [!IMPORTANT] After you run the preceding script to create an AG with three synchronous replicas, do not run the following script:

  • Create AG with two synchronous replicas and a configuration replica:

    [!IMPORTANT] This architecture allows any edition of SQL Server to host the third replica. For example, the third replica can be hosted on SQL Server Enterprise Edition. On Enterprise Edition, the only valid endpoint type is WITNESS.

    CREATE AVAILABILITY GROUP [ag1] 
       WITH (CLUSTER_TYPE = EXTERNAL) 
       FOR REPLICA ON 
        N'<node1>' WITH ( 
           ENDPOINT_URL = N'tcp://<node1>:<5022>', 
           AVAILABILITY_MODE = SYNCHRONOUS_COMMIT, 
           FAILOVER_MODE = EXTERNAL, 
           SEEDING_MODE = AUTOMATIC 
           ), 
        N'<node2>' WITH (  
           ENDPOINT_URL = N'tcp://<node2>:<5022>',  
           AVAILABILITY_MODE = SYNCHRONOUS_COMMIT, 
           FAILOVER_MODE = EXTERNAL, 
           SEEDING_MODE = AUTOMATIC 
           ), 
        N'<node3>' WITH ( 
           ENDPOINT_URL = N'tcp://<node3>:<5022>', 
           AVAILABILITY_MODE = CONFIGURATION_ONLY  
           );
    ALTER AVAILABILITY GROUP [ag1] GRANT CREATE ANY DATABASE;

  • Create AG with two synchronous replicas

    Include two replicas with synchronous availability mode. For example, the following script creates an AG called ag1. node1 and node2 host replicas in synchronous mode, with automatic seeding and automatic failover.

    [!IMPORTANT] Only run the following script to create an AG with two synchronous replicas. Do not run the following script if you ran either preceding script.

    CREATE AVAILABILITY GROUP [ag1]
       WITH (CLUSTER_TYPE = EXTERNAL)
       FOR REPLICA ON
       N'node1' WITH (
          ENDPOINT_URL = N'tcp://node1:5022',
          AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
          FAILOVER_MODE = EXTERNAL,
          SEEDING_MODE = AUTOMATIC
       ),
       N'node2' WITH ( 
          ENDPOINT_URL = N'tcp://node2:5022', 
          AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
          FAILOVER_MODE = EXTERNAL,
          SEEDING_MODE = AUTOMATIC
       );
    		
    ALTER AVAILABILITY GROUP [ag1] GRANT CREATE ANY DATABASE;

You can also configure an AG with CLUSTER_TYPE=EXTERNAL using SQL Server Management Studio or PowerShell.

Join secondary replicas to the AG

The following Transact-SQL script joins a SQL Server instance to an AG named ag1. Update the script for your environment. On each SQL Server instance that hosts a secondary replica, run the following Transact-SQL to join the AG.

ALTER AVAILABILITY GROUP [ag1] JOIN WITH (CLUSTER_TYPE = EXTERNAL);
		 
ALTER AVAILABILITY GROUP [ag1] GRANT CREATE ANY DATABASE;

[!INCLUDE Create Post]

Important

After you create the AG, you must configure integration with a cluster technology like Pacemaker for high availability. For a read-scale configuration using AGs, starting with [!INCLUDE SQL Server version], setting up a cluster is not required.

If you followed the steps in this document, you have an AG that is not yet clustered. The next step is to add the cluster. This configuration is valid for read-scale/load balancing scenarios, it is not complete for high availability. For high availability, you need to add the AG as a cluster resource. See Next steps for instructions.

Notes

Important

After you configure the cluster and add the AG as a cluster resource, you cannot use Transact-SQL to fail over the AG resources. SQL Server cluster resources on Linux are not coupled as tightly with the operating system as they are on a Windows Server Failover Cluster (WSFC). SQL Server service is not aware of the presence of the cluster. All orchestration is done through the cluster management tools. In RHEL or Ubuntu use pcs. In SLES use crm.

Important

If the AG is a cluster resource, there is a known issue in current release where forced failover with data loss to an asynchronous replica does not work. This will be fixed in the upcoming release. Manual or automatic failover to a synchronous replica succeeds.

Next steps

Configure Red Hat Enterprise Linux Cluster for SQL Server Availability Group Cluster Resources

Configure SUSE Linux Enterprise Server Cluster for SQL Server Availability Group Cluster Resources

Configure Ubuntu Cluster for SQL Server Availability Group Cluster Resources