Skip to content

Commit bc01a06

Browse files
authored
Merge pull request #22177 from PiJoCoder/ListenerPort_JoPilov052322
Organizing the AG Listener paragraph a bit and adding exercise/demo of how it works
2 parents b662b16 + c909387 commit bc01a06

File tree

2 files changed

+119
-27
lines changed

2 files changed

+119
-27
lines changed

docs/database-engine/availability-groups/windows/availability-group-listener-overview.md

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "An overview of the Always On availability group listener and how i
44
ms.custom:
55
- seodec18
66
- intro-overview
7-
ms.date: "02/27/2020"
7+
ms.date: "05/23/2022"
88
ms.prod: sql
99
ms.reviewer: ""
1010
ms.technology: availability-groups
@@ -24,7 +24,7 @@ ms.author: mathoma
2424
# What is an availability group listener?
2525
[!INCLUDE [SQL Server](../../../includes/applies-to-version/sqlserver.md)]
2626

27-
An availability group listener is a virtual network name (VNN) that clients can connect to in order to access a database in a primary or secondary replica of an Always On availability group. A listener allows a client to connect to a replica without having to know the physical instance name of the SQL Server. Since the listener routes traffic, the client connection string does not need to be modified after a failover occurs.
27+
An availability group listener is a virtual network name (VNN) that clients can connect to in order to access a database in a primary or secondary replica of an Always On availability group. A listener allows a client to connect to a replica without having to know the physical instance name of the SQL Server. Since the listener routes traffic, the client connection string doesn't need to be modified after a failover occurs.
2828

2929
An availability group listener consists of a Domain Name System (DNS) listener name, listener port designation, and one or more IP addresses. Only the TCP protocol is supported by availability group listener. The DNS name of the listener must be unique in the domain and in NetBIOS. When you create a listener, it becomes a resource in a cluster with an associated virtual network name (VNN), virtual IP (VIP), and availability group dependency. A client uses DNS to resolve the VNN into multiple IP addresses and then tries to connect to each address, until a connection request succeeds or until the connection requests time out.
3030

@@ -48,13 +48,52 @@ This article provides an overview of an availability group listener. You can als
4848

4949

5050
## <a name="SelectListenerPort"></a> Listener port
51-
When configuring an availability group listener, you must designate a port. You can configure the default port to 1433 in order to allow for simplicity of the client connection strings. If using 1433, you do not need to designate a port number in a connection string. Also, since each availability group listener will have a separate virtual network name, each availability group listener configured on a single WSFC can be configured to reference the same default port of 1433.
52-
53-
You can also designate a non-standard listener port; however this means that you will also need to explicitly specify a target port in your connection string whenever connecting to the availability group listener. You will also need to open permission on the firewall for the non-standard port.
54-
55-
If you use the default port of 1433 for availability group listener VNNs, you will still need to ensure that no other services on the cluster node are using this port; otherwise this would cause a port conflict.
56-
57-
If one of the instances of SQL Server is already listening on TCP port 1433 via the instance listener and there are no other services (including additional instances of SQL Server) on the computer listening on port 1433, this will not cause a port conflict with the availability group listener. This is because the availability group listener can share the same TCP port inside the same service process. However multiple instances of SQL Server (side-by-side) should not be configured to listen on the same port.
51+
When configuring an availability group listener, you must designate a port via SSMS. You can configure the default port to 1433 in order to allow for simplicity of the client connection strings. This means, that if you use 1433, you don't need to include a port number in a connection string of your application. Also, since each availability group listener will have a separate virtual network name, each availability group listener configured on a single WSFC can be configured to reference the same default port of 1433.
52+
53+
If you use the default port of 1433 for availability group listener VNNs, you'll still need to ensure that no other services on the cluster node are using this port; otherwise this would cause a port conflict.
54+
55+
If one of the instances of SQL Server is already listening on TCP port 1433 via the instance listener and there are no other services (including additional instances of SQL Server) on the computer listening on port 1433, this won't cause a port conflict with the availability group listener. This is because the availability group listener can share the same TCP port inside the same process. However multiple instances of SQL Server (side-by-side) must not be configured to listen on the same port because one of them will fail to listen for connections.
56+
57+
You can also designate a non-standard availability group listener port. However, you also need to explicitly use the target port in your application connection string when connecting to a listener. You also need to open permission on the firewall for this port.
58+
59+
You can connect to the listener using the name and port (if not 1433). The port can be either the listener port or the underlying SQL Server port that it's configured to listen on.
60+
61+
The following examples demonstrate some of the functionality of the listener:
62+
63+
**Set up:**
64+
- IP that SQL Server is listening on: 192.168.20.2
65+
- Port that SQL Server is listening on: 50254
66+
- Listener IP that was configured: 192.168.20.15
67+
- Listener name was configured: aglistener19
68+
- Listener port that was configured: 50123
69+
70+
1. Connect to the listener via IP address and port. This connection is successful.
71+
72+
```console
73+
sqlcmd -S 192.168.20.15,50123
74+
1>
75+
```
76+
77+
1. Connect to the listener by name only, no port. This connection will fail because a non-default port was used. You must specify that port.
78+
79+
```console
80+
sqlcmd -S aglistener19
81+
```
82+
83+
1. Connect to the listener by listener name and configured port. This connection is successful.
84+
85+
```console
86+
sqlcmd -S aglistener19,50123
87+
1>
88+
```
89+
90+
91+
1. Finally, connect to the listener and the SQL Server port. Notice that in this case you're using the port SQL Server is listening on, not the listener port. This connection also succeeds.
92+
93+
```console
94+
sqlcmd -S aglistener19,50254
95+
1>
96+
```
5897
5998
6099
## <a name="CCBehaviorOnFailover"></a> Behavior of client connections on failover

docs/database-engine/availability-groups/windows/troubleshoot-always-on-availability-groups-configuration-sql-server.md

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ ms.author: mathoma
2727

2828
|Section|Description|
2929
|-------------|-----------------|
30-
|[Always On Availability Groups Is Not Enabled](#IsHadrEnabled)|If an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] is not enabled for [!INCLUDE[ssHADR](../../../includes/sshadr-md.md)], the instance doesn't support availability group creation and cannot host any availability replicas.|
30+
|[Always On Availability Groups Isn't Enabled](#IsHadrEnabled)|If an instance of [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] is not enabled for [!INCLUDE[ssHADR](../../../includes/sshadr-md.md)], the instance doesn't support availability group creation and can't host any availability replicas.|
3131
|[Accounts](#Accounts)|Discusses requirements for correctly configuring the accounts under which [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] is running.|
3232
|[Endpoints](#Endpoints)|Discusses how to diagnose issues with the database mirroring endpoint of a server instance.|
3333
|[Network access](#NetworkAccess)|Documents the requirement that each server instance that is hosting an availability replica must be able to access the port of each of the other server instances over TCP.|
34+
|[Listener](#Listener)|Documents how to establish the IP address and port of the listener and make sure it is running and listening for incoming connections|
3435
|[Endpoint Access (SQL Server Error 1418)](#Msg1418)|Contains information about this [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] error message.|
3536
|[Join Database Fails (SQL Server Error 35250)](#JoinDbFails)|Discusses the possible causes and resolution of a failure to join secondary databases to an availability group because the connection to the primary replica isn't active.|
3637
|[Read-Only Routing is Not Working Correctly](#ROR)||
@@ -108,7 +109,7 @@ For more information, see [Enable and Disable Always On Availability Groups &#40
108109
GO
109110
```
110111

111-
3. For [!INCLUDE[ssHADR](../../../includes/sshadr-md.md)] setup issues that are difficult to explain, we recommend that you inspect each server instance to determine whether it is listening on the correct ports.
112+
3. For [!INCLUDE[ssHADR](../../../includes/sshadr-md.md)] setup issues that are difficult to explain, we recommend that you inspect each server instance to determine whether it's listening on the correct ports.
112113
113114
4. Make sure that the endpoints are started (STATE=STARTED). On each server instance, use the following [!INCLUDE[tsql](../../../includes/tsql-md.md)] statement:
114115
@@ -155,17 +156,20 @@ For more information, see [Enable and Disable Always On Availability Groups &#40
155156
select endpoint_url from sys.availability_replicas
156157
```
157158
158-
Next, compare the endpoint_url output to the server name (Netbios or FQDN).
159-
To query the Netbios and FQDN, run the following command in a Command Prompt on the replica locally:
159+
Next, compare the endpoint_url output to the server name (NetBIOS name or FQDN).
160+
To query the server name, run the following commands in a PowerShell on the replica locally:
160161
161-
```dos
162-
hostname & echo %COMPUTERNAME%.%USERDNSDOMAIN%
162+
```PowerShell
163+
$env:COMPUTERNAME
164+
[System.Net.Dns]::GetHostEntry([string]$env:computername).HostName
163165
```
164166
165-
For query the server name of a remote computer, run this command from a Command Prompt. Then compare the endpoint_url
167+
To validate the server name on a remote computer, run this command from PowerShell.
166168
167-
```dos
168-
ping -a servername_from_endpoint_url
169+
```PowerShell
170+
$servername_from_endpoint_url = "server_from_endpoint_url_output"
171+
172+
Test-NetConnection -ComputerName $servername_from_endpoint_url
169173
```
170174
171175
@@ -174,11 +178,16 @@ For more information, see [Enable and Disable Always On Availability Groups &#40
174178
## <a name="NetworkAccess"></a> Network Access
175179
Each server instance that is hosting an availability replica must be able to access the port of each of the other server instance over TCP. This is especially important if the server instances are in different domains that don't trust each other (untrusted domains). Check if you can connect to the endpoints by following these steps:
176180

177-
- Use Telnet to validate connectivity. Here are examples of commands you can use:
181+
- Use Test-NetConnection (equivalent to Telnet) to validate connectivity. Here are examples of commands you can use:
182+
183+
```PowerShell
184+
$server_name = "your_server_name"
185+
$IP_address = "your_ip_address"
186+
$port_number = "your_port_number"
178187
179-
```DOS
180-
telnet ServerName Port
181-
telnet IP_Address Port
188+
Test-NetConnection -ComputerName $server_name -Port $port_number
189+
Test-NetConnection -ComputerName $IP_address -Port $port_number
190+
```
182191

183192
- If the Endpoint is listening and connection is successful, then you'll see a blank screen.  If not, you'll receive a connection error from Telnet
184193
- If Telnet connection to the IP address works but to the ServerName it doesn't, there's likely a DNS or name resolution issue
@@ -189,15 +198,59 @@ Run the following PowerShell script to examine for disabled inbound traffic rule
189198
190199
```powershell
191200
Get-NetFirewallRule -Action Block -Enabled True -Direction Inbound |Format-Table
201+
```
202+
203+
- Capture the output from Get-NetTCPConnection cmdlet (equivalent of NETSTAT -a) and verify the status is a LISTENING or ESTABLISHED on the IP:Port for the endpoint specified
204+
205+
```PowerShell
206+
Get-NetTCPConnection
207+
```
208+
209+
210+
## <a name="Listener"></a> Listener
192211
193-
- Capture a NETSTAT -a output and verify the status is a LISTENING or ESTABLISHED on the IP:Port for the endpoint specified
212+
For correct configuration of an Availability Group listener follow "[Configure a listener for an Always On availability group](create-or-configure-an-availability-group-listener-sql-server.md)"
194213
195-
```dos
196-
netstat -a
214+
1. Once the listener is configured you can validate the IP address and port it is listening on by using the following query:
215+
216+
```PowerShell
217+
$server_name = $env:computername #replace this with your sql instance "server\instance"
218+
219+
sqlcmd -E -S$server_name -Q"SELECT dns_name AS AG_listener_name, port, ip_configuration_string_from_cluster
220+
FROM sys.availability_group_listeners"
221+
```
197222
223+
1. You can also find the listener information together with the SQL Server ports using this query:
224+
225+
```PowerShell
226+
$server_name = $env:computername #replace this with your sql instance "server\instance"
227+
228+
sqlcmd -E -S($server_name) -Q("SELECT convert(varchar(32), SERVERPROPERTY ('servername')) servername, convert(varchar(32),ip_address) ip_address, port, type_desc,state_desc, start_time
229+
FROM sys.dm_tcp_listener_states
230+
WHERE ip_address not in ('127.0.0.1', '::1') and type <> 2")
231+
```
232+
233+
1. If you need to establish connectivity to the listener and suspect a port is blocked, you can perform a test using the PowerShell Test-NetConnection cmdlet (equivalent to telnet).
234+
235+
```PowerShell
236+
$listener_name = "your_ag_listener"
237+
$IP_address = "your_ip_address"
238+
$port_number = "your_port_number"
239+
240+
Test-NetConnection -ComputerName $listener_name -Port $port_number
241+
Test-NetConnection -ComputerName $IP_address -Port $port_number
242+
```
243+
244+
1. Finally, check if the listener is listening on the specified port:
245+
246+
```PowerShell
247+
$port_number = "your_port_number"
248+
249+
Get-NetTCPConnection -LocalPort $port_number -State Listen
250+
```
198251
199252
## <a name="Msg1418"></a> Endpoint Access (SQL Server Error 1418)
200-
This [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] message indicates that the server network address specified in the endpoint URL cannot be reached or doesn't exist, and it suggests that you verify the network address name and reissue the command.
253+
This [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] message indicates that the server network address specified in the endpoint URL can't be reached or doesn't exist, and it suggests that you verify the network address name and reissue the command.
201254
202255
## <a name="JoinDbFails"></a> Join Database Fails (SQL Server Error 35250)
203256
This section discusses the possible causes and resolution of a failure to join secondary databases to the availability group because the connection to the primary replica isn't active. This is the full error message:
@@ -300,7 +353,7 @@ For **detailed** step-by-step instructions, refer to Engine error [MSSQLSERVER_3
300353
>[!NOTE]
301354
> If you are running [!INCLUDE[ssNoVersion](../../../includes/ssnoversion-md.md)] on Azure VM, you must take additional configuration steps. Ensure that the network security group (NSG) of each replica VM allows traffic to the endpoint port and the DNN port, if you are using DNN listener. If you are using VNN listener, you must ensure the [load balancer is configured correctly](/azure/azure-sql/virtual-machines/windows/availability-group-load-balancer-portal-configure).
302355
303-
7. Ensure that the READ_ONLY_ROUTING_URL (TCP://system-address:port) contains the correct fully-qualified domain name (FQDN) and port number. See:
356+
7. Ensure that the READ_ONLY_ROUTING_URL (TCP://system-address:port) contains the correct fully qualified domain name (FQDN) and port number. See:
304357
- [Calculating read_only_routing_url for Always On](/archive/blogs/mattn/calculating-read_only_routing_url-for-alwayson)
305358
- [sys.availability_replicas (Transact-SQL)](../../../relational-databases/system-catalog-views/sys-availability-replicas-transact-sql.md)
306359
- [ALTER AVAILABILITY GROUP (Transact-SQL)](../../../t-sql/statements/alter-availability-group-transact-sql.md)

0 commit comments

Comments
 (0)