SQL Server 2016 AlwaysOn搭建
AlwaysOn可用性組信息
| ? | 角色 | 節(jié)點 | 節(jié)點類型 | 同步方式 | 支持故障轉(zhuǎn)移類型 |
| 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由三個節(jié)點組成,A06為主副本,A08和SQLC01為從副本,A08為同步提交數(shù)據(jù),自動故障轉(zhuǎn)移,可供查詢,SQLC01為異步提交數(shù)據(jù),手工強制故障轉(zhuǎn)移,只有只讀直連時可供查詢;[ 客戶端通過公共網(wǎng)絡進行訪問,節(jié)點之間通過私有網(wǎng)絡進行通信。
1?配置所有副本支持AlwaysOn
打開Sql Server Configuration Manager,點開SQL Server屬性,開啟AlwaysOn可用性組,重啟SQL Server Service。
注意:AlwaysOn是基于Windows故障轉(zhuǎn)移群集的,所以所有節(jié)點必須加入同一Windows故障轉(zhuǎn)移群集。
?
如果不是群集節(jié)點則提示:
This computer is not a node in a failover cluster.
本打算用SQL故障轉(zhuǎn)移集群做主副本的,可是群集做主副本不支持自動故障轉(zhuǎn)移,只好做罷,改做個只讀備份。
?
2?用向?qū)?/span>創(chuàng)建一個AlwaysOn可用性組。
2.1?打開SQL Server Management Studio,連接任一副本,選擇菜單AlwaysOn High Availability->Availability Group,右鍵選擇菜單New Availability Group Wizard…
?
?
2.2?下一步,命名組,勾選Database Level Health Detection開啟Database Level Health Detection是開啟數(shù)據(jù)庫級別的健康檢查,是推薦配置,更多參考:https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/sql-server-always-on-database-health-detection-failover-option
?
?
2.3?勾選包含的數(shù)據(jù)庫,這些庫將組成一個可用性組,若出現(xiàn)異常則做為一個整體進行故障轉(zhuǎn)移。
要求數(shù)據(jù)庫恢復模式為完全,且已做過完整備份。
?
?
若無備份則提示:
?
若非完全恢復模式:
?
2.4?設置副本屬性
2.4.1?設置轉(zhuǎn)移方式,提交方式及副本的可讀性
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?設置副本之間通訊信息
A06和A08設置私有網(wǎng)卡的IP,SQLC01是集群,看來只能用實例名,好在只是個只讀備份
注意最后一列SQL Server Service Account,要使用域賬號,且對數(shù)據(jù)庫有讀寫權(quán)限.
?
2.4.3?設置監(jiān)聽器
設置監(jiān)聽器DNS名和虛擬IP,用于連接可用組.這個是給客戶端使用的,所以用公共網(wǎng)卡IP
?
?
使用本地賬號則會提示:
?
2.5?副本上數(shù)據(jù)庫的初始化方式
?
?
2.6?下一步 運行驗證
?
?
2.7?下一步
?
2.8?下一步,創(chuàng)建成功
?
創(chuàng)建成功后,可用管理器直接連監(jiān)聽器名FrontDBServer,查看副本狀態(tài),如有錯誤,可通過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代碼連接串也要加這個
?
總結(jié)
以上是生活随笔為你收集整理的SQL Server 2016 AlwaysOn搭建的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Verse on Premises 1.
- 下一篇: mysql时间戳转换日期