SQL Server AlwaysOn中445端口使用的调查报告


第一部分:来自微软官方的文档说明


Microsoft Knowledge Base article 832017: Service overview and network port requirements for Windows


针对我们生产环境SQL Server 2014 AlwaysOn FCI & AG混合部署,基于Active Directory和Cluster Service。


下面信息引用自KB 832017,描述了基于这两个服务的相关端口要求:


1. Active Directory (Local Security Authority)

Active Directory runs under the Lsass.exe process and includes the authentication and replication engines for Windows domain controllers. Domain controllers, client computers and application servers require network connectivity to Active Directory over specific hard-coded ports. Additionally, unless a tunneling protocol is used to encapsulate traffic to Active Directory, a range of ephemeral TCP ports between 1024 to 5000 and 49152 to 65535 are required.


依赖端口列表:

Application protocol

Protocol

Ports

Active Directory Web Services (ADWS)

TCP

9389

Active Directory Management Gateway Service

TCP

9389

Global Catalog

TCP

3269

Global Catalog

TCP

3268

ICMP


No port number

LDAP Server

TCP

389

LDAP Server

UDP

389

LDAP SSL

TCP

636

IPsec ISAKMP

UDP

500

NAT-T

UDP

4500

RPC

TCP

135

RPC randomly allocated high TCP ports¹

TCP

1024 - 5000
49152 - 65535²

SMB

TCP

445


2. Cluster Service

The Cluster service controls server cluster operations and manages the cluster database. A cluster is a collection of independent computers that act as a single computer. Managers, programmers, and users see the cluster as a single system. The software distributes data among the nodes of the cluster. If a node fails, other nodes provide the services and data that were formerly provided by the missing node. When a node is added or repaired, the cluster software migrates some data to that node.


System service name: ClusSvc

Application

Protocol

Ports

Cluster Service

UDP

3343

Cluster Service

TCP

3343 (This port is required during a node join operation.)

RPC

TCP

135

Cluster Administrator

UDP

137

Randomly allocated high UDP ports¹

UDP

Random port number between 1024 and 65535
Random port number between 49152 and 65535²

Note:

Additionally, for successful validation on Windows Failover Clusters on 2008 and above, allow inbound and outbound traffic for ICMP4, ICMP6, and port 445/TCP for SMB.


第二部分:来自微软Data Platform MVP Mail List的回复


SQL Server AlwaysOn中445端口使用的调查报告_SQL Server


第三部分:关于AD和WSFC原理的深入学习


1. AD对445的依赖

各个客户端开机时,需要访问AD里面DC上的一个sysvol共享,下载组策略。每次开机都要访问,通过这个共享下发组策略。


SYSVOL:

SYSVOL是指存储域公共文件服务器副本的共享文件夹,它们在域中所有的域控制器之间复制。 Sysvol文件夹是安装AD时创建的,它用来存放GPO、Script等信息。同时,存放在Sysvol文件夹中的信息,会复制到域中所有DC上。


Netlogon:

Netlogon(网络登录)服务为域控制器注册所有的srv资源纪录。这些记录出现在DNS服务器的正向查询区域你的域名中的_msdcs, _sites, _tcp, and _udp等文件夹中。其他计算机利用这些记录查询域活动目录相关的信息。


2. WSFC对445的依赖

群集数据库是WSFC的运作的主要概念之一,群集数据库里面会记载着群集应用当前的状态,例如当前节点1运行了一个DHCP角色,状态是上线,运行了一个文件服务器角色,状态是离线,以及群集配置,群集成员配置,群集资源的添加,创建,启动,删除,停止,下线等状态变化,群集数据库就是为了帮助各个节点知道对方上面运行了什么样的群集服务,一旦对方宕机之后,将按照群集数据库里面的进行的状态信息连接上共享存储进行故障转移上线操作。


WSFC会通过管理共享在复制集群数据库用到。群集数据库在各节点C盘和注册表,当一个节点修改群集信息,会复制到其他节点和见证磁盘。


SQL Server AlwaysOn中445端口使用的调查报告_SQL Server_02

SQL Server AlwaysOn中445端口使用的调查报告_SQL Server_03

一个节点宕机,其他节点参照群集数据库,访问共享磁盘,联机上线该节点承载的应用。日常运行时在各节点同步,确保各节点记录一致。


第四部分:关于Windows Server 2016和SQL Server 2016/2017相关新功能的学习


1. Domain Independent Availability Groups(a new feature introduced in SQL Server 2016)

https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/domain-independent-availability-groups


在Windows Server 2016 + SQL Server 2016环境下,AlwaysOn AG支持在工作组环境、或跨域环境搭建AG。即便搭建无域AG,AG还是需要WSFC的支持,而WSFC需要开通445端口;FCI到目前为止,仍然需要在域环境下部署。该特性无法消除445端口访问。


2. Distributed availability groups(a new feature introduced in SQL Server 2016)

https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/distributed-availability-groups


分布式可用性组,可将AlwaysOn AG跨两个不同的WSFC,来扩展AG。该特性同样无法消除445端口访问。


3. Read-scale availability groups(a new feature introduced in SQL Server 2017)

https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/read-scale-availability-groups


在 SQL Server 2016 及更早版本中,所有可用性组都需要群集。 群集用于提供业务连续性,实现高可用性和灾难恢复 (HADR)。 此外,配置次要副本以执行读取操作。 如果目标不是高可用性,配置和运行群集消耗了相当大的运营开销。 SQL Server 2017 引入了不需要群集的读取缩放可用性组。


如果业务要求是转换主要副本上运行的任务关键型工作负荷的资源,用户现在可以使用只读路由或直接连接到可读次要副本。 而无需依赖于与任何群集技术的集成。 Windows 和 Linux 平台上的 SQL Server 2017 支持这些新功能。


这不是高可用性配置。 不需要监视基础结构、协调故障检测和进行自动故障转移。 如果没有群集,SQL Server 无法提供自动化高可用性解决方案可提供的低恢复时间目标 (RTO)。 如果需要高可用×××,请使用群集管理器(Windows 上的 Windows Server 故障转移群集或 Linux 上的 Pacemaker)。


读取缩放可用性组可提供灾难恢复功能。 当只读副本处于同步提交模式时,可提供恢复点目标 (RPO) 0。 要对读取缩放可用性组进行故障转移,请参阅对读取缩放可用性组上的主要副本进行故障转移。


总体来说,该特性只有DR功能,不支持HA。该特性适用于只是为了在多个服务器上部署多个只读副本,分担读取压力。


4. SQL Server 2017 Availability Groups on linux

https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-availability-group-overview


在Linux上配置AG基于Pacemaker。


5. SQL Server 2017 Failover Cluster Instance on linux

https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-shared-disk-cluster-concepts


在Linux上配置FCI官方文档还很简陋,从共享存储来看,目前支持iSCSI、NFS和SMB协议。期待后续支持光纤协议,并与AG混合部署。


第五部分:关于防范蠕虫病毒的解决方案和建议


分析了下,有如下3个解决方案:

1. 升级相应安全补丁

对于重要的安全补丁建议打上,从Secondary到Primary在维护窗口滚动升级。


2. 修改数据库服务器共享端口

根据以往经验,可以修改客户端和服务器端的445端口,共享能正常运行。但该方案不能阻止对共享的访问。


3. 将数据库服务器放入核心隔离区域

根据以往经验,电商公司为了通过PCI国际权威认证,在搭建PCI环境时,会将生产支付和账号数据库放入该环境,其实是一个核心隔离区域,限制访问该区域数据库服务器的IP和端口。


我建议:

1. 打上SMB漏洞的安全补丁。

2. 将数据库服务器访问核心隔离区域。