Skip to content

Commit cf112ce

Browse files
Merge pull request #105909 from VanMSFT/rhellist
Adding listener tutorial to RHEL VMs
2 parents e91cc07 + 13179ae commit cf112ce

File tree

5 files changed

+310
-8
lines changed

5 files changed

+310
-8
lines changed

articles/virtual-machines/linux/sql/TOC.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
href: provision-sql-server-linux-virtual-machine.md
99
- name: Tutorials
1010
items:
11-
- name: Setting up Azure RHEL VM Availability Group with STONITH
11+
- name: Setting up Azure RHEL VM availability group with STONITH
1212
href: sql-server-linux-rhel-ha-stonith-tutorial.md
13+
- name: Configure availability group listener for SQL Server on RHEL virtual machines in Azure
14+
href: sql-server-linux-rhel-ha-listener-tutorial.md
1315
- name: Reference
1416
items:
1517
- name: Azure CLI
88.6 KB
Loading
85.7 KB
Loading
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
---
2+
title: Configure availability group listener for SQL Server on RHEL virtual machines in Azure - Linux Virtual Machines | Microsoft Docs
3+
description: Learn about setting up an availability group listener in SQL Server on RHEL virtual machines in Azure
4+
ms.service: virtual-machines-linux
5+
ms.subservice:
6+
ms.topic: tutorial
7+
author: VanMSFT
8+
ms.author: vanto
9+
ms.reviewer: jroth
10+
ms.date: 03/11/2020
11+
---
12+
# Tutorial: Configure availability group listener for SQL Server on RHEL virtual machines in Azure
13+
14+
> [!NOTE]
15+
> The tutorial presented is in **public preview**.
16+
>
17+
> We use SQL Server 2017 with RHEL 7.6 in this tutorial, but it is possible to use SQL Server 2019 in RHEL 7 or RHEL 8 to configure HA. The commands to configure availability group resources has changed in RHEL 8, and you'll want to look at the article, [Create availability group resource](/sql/linux/sql-server-linux-availability-group-cluster-rhel#create-availability-group-resource) and RHEL 8 resources for more information on the correct commands.
18+
19+
This tutorial will go over steps on how to create an availability group listener for your SQL Servers on RHEL virtual machines in Azure. You will learn how to:
20+
21+
> [!div class="checklist"]
22+
> - Create a load balancer in the Azure portal
23+
> - Configure the back-end pool for the load balancer
24+
> - Create a probe for the load balancer
25+
> - Set the load balancing rules
26+
> - Create the load balancer resource in the cluster
27+
> - Create the availability group listener
28+
> - Test connecting to the listener
29+
> - Testing a failover
30+
31+
## Prerequisite
32+
33+
Completed [**Tutorial: Configure availability groups for SQL Server on RHEL virtual machines in Azure**](sql-server-linux-rhel-ha-stonith-tutorial.md)
34+
35+
## Create the load balancer in the Azure portal
36+
37+
The following instructions take you through steps 1 through 4 from the [Create and configure the load balancer in the Azure portal](../../../virtual-machines/windows/sql/virtual-machines-windows-portal-sql-alwayson-int-listener.md#create-and-configure-the-load-balancer-in-the-azure-portal) section of the [Load balancer - Azure portal](../../../virtual-machines/windows/sql/virtual-machines-windows-portal-sql-alwayson-int-listener.md) article.
38+
39+
### Create the load balancer
40+
41+
1. In the Azure portal, open the resource group that contains the SQL Server virtual machines.
42+
43+
2. In the resource group, click **Add**.
44+
45+
3. Search for **load balancer** and then, in the search results, select **Load Balancer**, which is published by **Microsoft**.
46+
47+
4. On the **Load Balancer** blade, click **Create**.
48+
49+
5. In the **Create load balancer** dialog box, configure the load balancer as follows:
50+
51+
| Setting | Value |
52+
| --- | --- |
53+
| **Name** |A text name representing the load balancer. For example, **sqlLB**. |
54+
| **Type** |**Internal** |
55+
| **Virtual network** |The default VNet that was created should be named **VM1VNET**. |
56+
| **Subnet** |Select the subnet that the SQL Server instances are in. The default should be **VM1Subnet**.|
57+
| **IP address assignment** |**Static** |
58+
| **Private IP address** |Use the `virtualip` IP address that was created in the cluster. |
59+
| **Subscription** |Use the subscription that was used for your resource group. |
60+
| **Resource group** |Select the resource group that the SQL Server instances are in. |
61+
| **Location** |Select the Azure location that the SQL Server instances are in. |
62+
63+
### Configure the back-end pool
64+
Azure calls the back-end address pool *backend pool*. In this case, the back-end pool is the addresses of the three SQL Server instances in your availability group.
65+
66+
1. In your resource group, click the load balancer that you created.
67+
68+
2. On **Settings**, click **Backend pools**.
69+
70+
3. On **Backend pools**, click **Add** to create a back-end address pool.
71+
72+
4. On **Add backend pool**, under **Name**, type a name for the back-end pool.
73+
74+
5. Under **Associated to**, select **Virtual machine**.
75+
76+
6. Select each virtual machine in the environment, and associate the appropriate IP address to each selection.
77+
78+
:::image type="content" source="media/sql-server-linux-rhel-ha-listener-tutorial/add-backend-pool.png" alt-text="Add backend pool":::
79+
80+
7. Click **Add**.
81+
82+
### Create a probe
83+
84+
The probe defines how Azure verifies which of the SQL Server instances currently owns the availability group listener. Azure probes the service based on the IP address on a port that you define when you create the probe.
85+
86+
1. On the load balancer **Settings** blade, click **Health probes**.
87+
88+
2. On the **Health probes** blade, click **Add**.
89+
90+
3. Configure the probe on the **Add probe** blade. Use the following values to configure the probe:
91+
92+
| Setting | Value |
93+
| --- | --- |
94+
| **Name** |A text name representing the probe. For example, **SQLAlwaysOnEndPointProbe**. |
95+
| **Protocol** |**TCP** |
96+
| **Port** |You can use any available port. For example, *59999*. |
97+
| **Interval** |*5* |
98+
| **Unhealthy threshold** |*2* |
99+
100+
4. Click **OK**.
101+
102+
5. Log into all your virtual machines, and open the probe port using the following commands:
103+
104+
```bash
105+
sudo firewall-cmd --zone=public --add-port=59999/tcp --permanent
106+
sudo firewall-cmd --reload
107+
```
108+
109+
Azure creates the probe and then uses it to test which SQL Server instance has the listener for the availability group.
110+
111+
### Set the load balancing rules
112+
113+
The load balancing rules configure how the load balancer routes traffic to the SQL Server instances. For this load balancer, you enable direct server return because only one of the three SQL Server instances owns the availability group listener resource at a time.
114+
115+
1. On the load balancer **Settings** blade, click **Load balancing rules**.
116+
117+
2. On the **Load balancing rules** blade, click **Add**.
118+
119+
3. On the **Add load balancing rules** blade, configure the load balancing rule. Use the following settings:
120+
121+
| Setting | Value |
122+
| --- | --- |
123+
| **Name** |A text name representing the load balancing rules. For example, **SQLAlwaysOnEndPointListener**. |
124+
| **Protocol** |**TCP** |
125+
| **Port** |*1433* |
126+
| **Backend Port** |*1433*. This value is ignored because this rule uses **Floating IP (direct server return)**. |
127+
| **Probe** |Use the name of the probe that you created for this load balancer. |
128+
| **Session persistence** |**None** |
129+
| **Idle timeout (minutes)** |*4* |
130+
| **Floating IP (direct server return)** |**Enabled** |
131+
132+
:::image type="content" source="media/sql-server-linux-rhel-ha-listener-tutorial/add-load-balancing-rule.png" alt-text="Add load balancing rule":::
133+
134+
4. Click **OK**.
135+
5. Azure configures the load balancing rule. Now the load balancer is configured to route traffic to the SQL Server instance that hosts the listener for the availability group.
136+
137+
At this point, the resource group has a load balancer that connects to all SQL Server machines. The load balancer also contains an IP address for the SQL Server Always On availability group listener, so that any machine can respond to requests for the availability groups.
138+
139+
## Create the load balancer resource in the cluster
140+
141+
1. Log into the primary virtual machine. We need to create the resource to enable the Azure load balancer probe port (59999 is used in our example). Run the following command:
142+
143+
```bash
144+
sudo pcs resource create azure_load_balancer azure-lb port=59999
145+
```
146+
147+
1. Create a group that contains the `virtualip` and `azure_load_balancer` resource:
148+
149+
```bash
150+
sudo pcs resource group add virtualip_group azure_load_balancer virtualip
151+
```
152+
153+
### Add constraints
154+
155+
1. A colocation constraint must be configured to ensure the Azure load balancer IP address and the AG resource are running on the same node. Run the following command:
156+
157+
```bash
158+
sudo pcs constraint colocation add azure_load_balancer ag_cluster-master INFINITY with-rsc-role=Master
159+
```
160+
1. Create an ordering constraint to ensure that the AG resource is up and running before the Azure load balancer IP address. While the colocation constraint implies an ordering constraint, this enforces it.
161+
162+
```bash
163+
sudo pcs constraint order promote ag_cluster-master then start azure_load_balancer
164+
```
165+
166+
1. To verify the constraints, run the following command:
167+
168+
```bash
169+
sudo pcs constraint list --full
170+
```
171+
172+
You should see the following output:
173+
174+
```output
175+
Location Constraints:
176+
Ordering Constraints:
177+
promote ag_cluster-master then start virtualip (kind:Mandatory) (id:order-ag_cluster-master-virtualip-mandatory)
178+
promote ag_cluster-master then start azure_load_balancer (kind:Mandatory) (id:order-ag_cluster-master-azure_load_balancer-mandatory)
179+
Colocation Constraints:
180+
virtualip with ag_cluster-master (score:INFINITY) (with-rsc-role:Master) (id:colocation-virtualip-ag_cluster-master-INFINITY)
181+
azure_load_balancer with ag_cluster-master (score:INFINITY) (with-rsc-role:Master) (id:colocation-azure_load_balancer-ag_cluster-master-INFINITY)
182+
Ticket Constraints:
183+
```
184+
185+
## Create the availability group listener
186+
187+
1. On the primary node, run the following command in SQLCMD or SSMS:
188+
189+
- Replace the IP address used below with the `virtualip` IP address.
190+
191+
```sql
192+
ALTER AVAILABILITY
193+
GROUP [ag1] ADD LISTENER 'ag1-listener' (
194+
WITH IP(('10.0.0.7' ,'255.255.255.0'))
195+
,PORT = 1433
196+
);
197+
GO
198+
```
199+
200+
1. Log into each VM node. Use the following command to open the hosts file and set up host name resolution for the `ag1-listener` on each machine.
201+
202+
```
203+
sudo vi /etc/hosts
204+
```
205+
206+
In the **vi** editor, enter `i` to insert text, and on a blank line, add the IP of the `ag1-listener`. Then add `ag1-listener` after a space next to the IP.
207+
208+
```output
209+
<IP of ag1-listener> ag1-listener
210+
```
211+
212+
To exit the **vi** editor, first hit the **Esc** key, and then enter the command `:wq` to write the file and quit. Do this on each node.
213+
214+
## Test the listener and a failover
215+
216+
### Test logging into SQL Server using the availability group listener
217+
218+
1. Use SQLCMD to log into the primary node of SQL Server using the availability group listener name:
219+
220+
- Use a login that was previously created and replace `<YourPassword>` with the correct password. The example below uses the `sa` login that was created with the SQL Server.
221+
222+
```bash
223+
sqlcmd -S ag1-listener -U sa -P <YourPassword>
224+
```
225+
226+
1. Check the name of the server that you are connected to. Run the following command in SQLCMD:
227+
228+
```sql
229+
SELECT @@SERVERNAME
230+
```
231+
232+
Your output should show the current primary node. This should be `VM1` if you have never tested a failover.
233+
234+
Exit the SQL session by typing the `exit` command.
235+
236+
### Test a failover
237+
238+
1. Run the following command to manually failover the primary replica to `<VM2>` or another replica. Replace `<VM2>` with the value of your server name.
239+
240+
```bash
241+
sudo pcs resource move ag_cluster-master <VM2> --master
242+
```
243+
244+
1. If you check your constraints, you'll see that another constraint was added because of the manual failover:
245+
246+
```bash
247+
sudo pcs constraint list --full
248+
```
249+
250+
You will see that a constraint with ID `cli-prefer-ag_cluster-master` was added.
251+
252+
1. Remove the constraint with ID `cli-prefer-ag_cluster-master` using the following command:
253+
254+
```bash
255+
sudo pcs constraint remove cli-prefer-ag_cluster-master
256+
```
257+
258+
1. Check your cluster resources using the command `sudo pcs resource`, and you should see that the primary instance is now `<VM2>`.
259+
260+
```output
261+
[<username>@<VM1> ~]$ sudo pcs resource
262+
Master/Slave Set: ag_cluster-master [ag_cluster]
263+
Masters: [ <VM2> ]
264+
Slaves: [ <VM1> <VM3> ]
265+
Resource Group: virtualip_group
266+
azure_load_balancer (ocf::heartbeat:azure-lb): Started <VM2>
267+
virtualip (ocf::heartbeat:IPaddr2): Started <VM2>
268+
```
269+
270+
1. Use SQLCMD to log into your primary replica using the listener name:
271+
272+
- Use a login that was previously created and replace `<YourPassword>` with the correct password. The example below uses the `sa` login that was created with the SQL Server.
273+
274+
```bash
275+
sqlcmd -S ag1-listener -U sa -P <YourPassword>
276+
```
277+
278+
1. Check the server that you are connected to. Run the following command in SQLCMD:
279+
280+
```sql
281+
SELECT @@SERVERNAME
282+
```
283+
284+
You should see that you are now connected to the VM that you failed-over to.
285+
286+
## Next steps
287+
288+
For more information on Load balancers in Azure, see:
289+
290+
> [!div class="nextstepaction"]
291+
> [Configure a load balancer for an availability group on Azure SQL Server VMs](../../../virtual-machines/windows/sql/virtual-machines-windows-portal-sql-alwayson-int-listener.md)

0 commit comments

Comments
 (0)