Linux

導致此錯誤的原因:可用性組 ag1 的指定副本均未映射到您連接到的 SQL Server 實例

  • July 17, 2019

我正在按照https://docs.microsoft.com/en-us/sql/linux/sql-server-linux為 Linux 配置 Always-on for SQL Server 2017 RC1(14.0.80.90,日期為 2017-7-18) -可用性-組-配置-ha。此安裝使用 docker 映像,全部位於同一物理主機上。在我到達步驟之前,所有步驟都有效:

CREATE AVAILABILITY GROUP [ag1]
   WITH (DB_FAILOVER = ON, CLUSTER_TYPE = EXTERNAL)
   FOR REPLICA ON
       N'always-onA' 
        WITH (
           ENDPOINT_URL = N'tcp://always-onA:5022',
           AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
           FAILOVER_MODE = EXTERNAL,
           SEEDING_MODE = AUTOMATIC
           ),
       N'always-onB' 
        WITH ( 
           ENDPOINT_URL = N'tcp://always-onB:5022', 
           AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
           FAILOVER_MODE = EXTERNAL,
           SEEDING_MODE = AUTOMATIC
           ),
       N'always-onC'
       WITH( 
          ENDPOINT_URL = N'tcp://always-onC:5022', 
          AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
          FAILOVER_MODE = EXTERNAL,
          SEEDING_MODE = AUTOMATIC
          );

我收到錯誤消息:

Msg 35237, Level 16, State 1, Line 2
None of the specified replicas for availability group ag1 maps to the instance of SQL Server to which you are connected. Reenter the command, specifying this server instance to host one of the replicas. This replica will be the initial primary replica. 

我已經查看了https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-release-notes上的發行說明,以確保沒有已知問題,並且應該支持此功能此時。

在每個 docker 容器中,名稱“always-onX”解析:

>     root@5194403487fe:/# ping always-onA
>     PING always-onA (172.17.0.10): 56 data bytes
>     64 bytes from 172.17.0.10: icmp_seq=0 ttl=64 time=0.125 ms
>     ^C--- always-onA ping statistics ---
>     1 packets transmitted, 1 packets received, 0% packet loss
>     round-trip min/avg/max/stddev = 0.125/0.125/0.125/0.000 ms
>     root@5194403487fe:/# ping always-onB
>     PING always-onB (172.17.0.11): 56 data bytes
>     64 bytes from 172.17.0.11: icmp_seq=0 ttl=64 time=0.156 ms
>     ^C--- always-onB ping statistics ---
>     1 packets transmitted, 1 packets received, 0% packet loss
>     round-trip min/avg/max/stddev = 0.156/0.156/0.156/0.000 ms
>     root@5194403487fe:/# ping always-onC
>     PING always-onC (172.17.0.12): 56 data bytes
>     64 bytes from 172.17.0.12: icmp_seq=0 ttl=64 time=0.308 ms
>     ^C--- always-onC ping statistics ---
>     1 packets transmitted, 1 packets received, 0% packet loss
>     round-trip min/avg/max/stddev = 0.308/0.308/0.308/0.000 ms

SQL Server 還在每個實例上偵聽埠 5022(這對所有實例都顯示相同):

# netstat -alnp | grep 5022
tcp        0      0 0.0.0.0:5022            0.0.0.0:*               LISTEN      9/sqlservr

此外,系統上不存在可能導致混淆的其他 IP:

# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:0a
         inet addr:172.17.0.10  Bcast:0.0.0.0  Mask:255.255.0.0
         inet6 addr: fe80::42:acff:fe11:a/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:4058 errors:0 dropped:0 overruns:0 frame:0
         TX packets:2016 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:2771303 (2.7 MB)  TX bytes:241070 (241.0 KB)

lo        Link encap:Local Loopback
         inet addr:127.0.0.1  Mask:255.0.0.0
         inet6 addr: ::1/128 Scope:Host
         UP LOOPBACK RUNNING  MTU:65536  Metric:1
         RX packets:470 errors:0 dropped:0 overruns:0 frame:0
         TX packets:470 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:1870657 (1.8 MB)  TX bytes:1870657 (1.8 MB)

名稱 always-onA/B/C 在 docker 映像的主機文件中和通過 DNS 解析,因此那裡也不應該有任何問題:

# nslookup always-onA
Server:         192.168.1.1
Address:        192.168.1.1#53

Name:   always-onA
Address: 172.17.0.10

最後,SQL Server 日誌顯示鏡像端點正在偵聽連接:

# docker logs always-onA | tail -2
2017-07-23 16:53:27.76 spid56      Server is listening on [ 0.0.0.0 <ipv4> 5022].
2017-07-23 16:53:27.76 spid56      The Database Mirroring endpoint is now listening for connections.

似乎 SQL Server 無法清楚地辨識可用性組中的配置節點之一實際上是它自己,因此得到錯誤,但我看不到任何調試方法。我嘗試使用以下名稱而不是名稱“always-onA”:

永遠線上 127.0.0.1 本地主機 0.0.0.0

錯誤總是一樣的。尋找有關如何解決此問題的任何想法。

已解決:問題是在創建可用性組時,節點說明符,即N'name'需要使用根據"hostname"命令返回的 EXACT 名稱。使用任何其他標識符,即使它解析為正確的 IP,似乎也不起作用。

在我的例子中是可用性組的名稱,它被刪掉了,因為它很長。

引用自:https://dba.stackexchange.com/questions/181580