SQL Server 2016 AlwaysOn搭建

AlwaysOn可用性組信息

 

角色

節點

節點類型

同步方式

支持故障轉移類型

Availability Group

 

Primay Replica

SQLC01

 

SQL Cluster

Synchronous-commit

Automatic failover

 

Secondary Replica

A06

Instance

Synchronous -commit

Automatic failover

 

Secondary Replica

A08

Instance

Asynchronous -commit

Forced failover

 

示意圖如下,可用性組FrontDBServer由三個節點組成,A06爲主副本,A08和SQLC01爲從副本,A08爲同步提交數據,自動故障轉移,可供查詢,SQLC01爲異步提交數據,手工強制故障轉移,只有只讀直連時可供查詢;[ 客戶端通過公共網絡進行訪問,節點之間通過私有網絡進行通信。


1 配置所本支持AlwaysOn

Sql Server Configuration Manager,點SQL Server屬性,開AlwaysOn可用性組,重SQL Server Service

注意:AlwaysOn是基於Windows故障轉移羣集的,所以所有節點必須入同一Windows故障轉移羣集

 

如果不是羣集節點則提示:

This computer is not a node in a failover cluster.

打算用SQL故障轉移集羣做主本的,可是羣集做主副本不支持自動故障轉移,只好做罷,改做個只讀備份

 

2 用嚮導創建一AlwaysOn用性組

2.1 打SQL Server Management Studio,連接任一副本,選擇菜單AlwaysOn High Availability->Availability Group鍵選擇菜單New Availability Group Wizard…

 

 


2.2 下一步,命名組,勾Database Level Health DetectionDatabase Level Health Detection是開啓數據庫級別的健康檢查,是推薦配置,更多參考https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/sql-server-always-on-database-health-detection-failover-option

 

 

2.3 勾包含的數據庫,這些庫將成一個可用性組,若出現異常則爲一個整體進行故障轉移

求數庫恢復模式爲完全,且已做過完整備份

 

 

無備份則提示

 

若非恢復模式

 


2.4 設置屬性

2.4.1 設置轉移方式,提交方式及副本的可

Readable Secondary有三種取值,如:No

No

Direct connections are allowed to secondary databases of this replica. They are not available for read access. This is the default setting.

Read-intent only

Only direct read-only connections are allowed to secondary databases of this replica. The secondary database(s) are all available for read access.

Yes

All connections are allowed to secondary databases of this replica, but only for read access. The secondary database(s) are all available for read access.

 

 

2.4.2 設置副本通訊信息

A06A08設置私有網卡的IP,SQLC01是集羣,看來只能用實例名,好在只是個只讀備份

注意最後一列SQL Server Service Account,要使用域賬號,且對數據庫有讀寫權限.

 

2.4.3 設置監聽器

設置監聽器DNS名和虛擬IP,用於連接可用組.這個是給客戶端使用的,所以用公共網卡IP

 

 

使用本地賬號則會提示:

 

2.5 副本上數據庫的初始化方式

 

 

2.6 下一步 運行驗證

 

 

2.7 下一步

 

2.8 下一步,創建成功

 

創建成功後,可用管理器直接連監聽器名FrontDBServer,查看副本狀態,如有錯誤,可通過SQL Server錯誤日誌定位問題,如下是有一個SQL Server實例是用本地賬戶運行導致的.

 

C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Log

ErrorLog

 

2017-07-14 13:32:43.82 Logon       Database Mirroring login attempt by user 'WSW\WIN2012R2A06$.' failed with error: 'Connection handshake failed. The login 'WSW\WIN2012R2A06$' does not have CONNECT permission on the endpoint. State 84.'.  [SERVER: 192.168.187.155]

 

 

連接只讀副本時需要指定ApplicationIntent=ReadOnly,下圖是SQL Server Managerment Studio連接時的設置,.Net代碼連接串也要加這個

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章