在Windows Server 2012 R2中搭建SQL Server 2012故障轉(zhuǎn)移集群
Jun 07, 2016 pm 04:33 PM本文講解下在Windows Server 2012 R2中搭建SQL Server 2012故障轉(zhuǎn)移集群的詳細(xì)過程。需要說明的是我們搭建的SQL Server故障轉(zhuǎn)移集
本文講解下在Windows Server 2012 R2中搭建SQL Server 2012故障轉(zhuǎn)移集群的詳細(xì)過程。
需要說明的是我們搭建的SQL Server故障轉(zhuǎn)移集群(SQL Server Failover Cluster)是可用性集群,而不是負(fù)載均衡集群,其目的是為了保證服務(wù)的連續(xù)性和可用性,而不是為了提高服務(wù)的性能。
SQL Server始終在負(fù)載均衡集群方面都缺少自己的產(chǎn)品,多由第三方廠家提供,但SQL Server故障轉(zhuǎn)移集群卻由來已久,在SQL Server 2012還提供了一個(gè)可用性組(AlwaysOn High Availability Groups)的新特性,我們知道微軟的故障轉(zhuǎn)移集群(Windows Server Failover Clustering , WSFC)一般需要共享存儲(chǔ),SQL Server故障轉(zhuǎn)移集群也是建立在WSFC的基礎(chǔ)之上,可用性組卻可以不依賴于共享存儲(chǔ)實(shí)現(xiàn)SQL Server的故障轉(zhuǎn)移,這為沒有共享存儲(chǔ)的環(huán)境提供了一個(gè)實(shí)現(xiàn)SQL Server高可用的解決方案,關(guān)于AlwaysOn特性可以參閱相關(guān)文檔,這里我們實(shí)現(xiàn)的是仍是基于共享存儲(chǔ)的包含兩個(gè)節(jié)點(diǎn)的SQL Server故障轉(zhuǎn)移集群。
一、搭建Windows故障轉(zhuǎn)移集群(WSFC)
SQL Server故障轉(zhuǎn)移集群是基于WSFC的,因而我們需要事先在兩個(gè)節(jié)點(diǎn)中搭建一個(gè)WSFC,這里需WSFC僅是一個(gè)容器,可以放置多個(gè)角色以實(shí)現(xiàn)這些角色的故障轉(zhuǎn)移。為搭建一個(gè)WSFC,除了需要域環(huán)境,還需要在節(jié)點(diǎn),存儲(chǔ),網(wǎng)絡(luò)等方面做準(zhǔn)備。
1、在各節(jié)點(diǎn)中添加Failover Clustering服務(wù)器功能。
2、確保各節(jié)點(diǎn)操作系統(tǒng)的更新一致,新安裝的系統(tǒng)要么更新到最新,要么暫不更新。
3、在各節(jié)點(diǎn)中配置管理網(wǎng)絡(luò)和心跳網(wǎng)絡(luò),雖然一個(gè)可用網(wǎng)絡(luò)既可以搭建集群,但是最佳實(shí)踐還是分開。
4、在各節(jié)點(diǎn)中配置共享存儲(chǔ)磁盤,初始化并格式化磁盤,分配盤符。這里的共享存儲(chǔ)磁盤可以是基于IP SAN和FC SAN的磁盤,也可以是基于文件服務(wù)器的虛擬磁盤,具體可以參考Windows Server 2012 虛擬化測(cè)試:存儲(chǔ)。在節(jié)點(diǎn)中可見磁盤如下:
為搭建SQL Server故障轉(zhuǎn)移集群,至少需要準(zhǔn)備兩塊共享磁盤:集群見證磁盤Q、為存儲(chǔ)SQL Server數(shù)據(jù)庫和日志文件準(zhǔn)備的集群磁盤S。另外我們需要為SQL Server的集群實(shí)例配置分布式事務(wù)協(xié)調(diào)器(Distributed Transaction Coordinator, DTC),因而需要為DTC準(zhǔn)備磁盤M。微軟建議將SQL Server各類文件分開存儲(chǔ),最佳實(shí)踐需準(zhǔn)備兩塊以上共享磁盤,分別存儲(chǔ)User Database、Backup和User Database Log文件,這就至少需要另一個(gè)集群磁盤L。綜上我們對(duì)存儲(chǔ)做如下配置:
另外值得一提的是到SQL Server 2014才提供了對(duì)集群共享卷的支持,因而這里只能使用集群磁盤。
5、使用Failover Cluster Manager驗(yàn)證并創(chuàng)建集群。完成后的集群磁盤視圖如下:
?
二、安裝SQL Server故障轉(zhuǎn)移集群
Windows故障轉(zhuǎn)移集群(WSFC)搭建成功后即完成了SQL Server故障轉(zhuǎn)移集群的基礎(chǔ),接下來我們繼續(xù)完成SQL Server部分。先在一個(gè)節(jié)點(diǎn)上安裝SQL Server Failover Cluster,然后再另一個(gè)節(jié)點(diǎn)安裝加入集群節(jié)點(diǎn)。
SQL Server集群部分,先通過驗(yàn)證,這里的警告主要是搭建Windows故障轉(zhuǎn)移集群存在警告的警告,升級(jí)警告以及防火墻警告,可以繼續(xù)。
選擇Database Engine Services和管理組件,注意這里只有Database Engine Services和Analysis Services支持集群,其他服務(wù)都不支持。其他組件如需要也可以隨后再添加,但是添加其他組建時(shí)選擇Add features to an existing installation,然后選擇Perfom a new installation of SQL Server 2012,而不是Add features to an existing instance of SQL Server 2012,否則最后會(huì)出現(xiàn)Existing clustered or cluster-prepared instance的錯(cuò)誤,具體參考Installing SQL Integration Services after SQL Cluster Setup has Completed。
配置一個(gè)網(wǎng)絡(luò)名稱,類似于計(jì)算機(jī)名稱,今后將通過該名稱訪問數(shù)據(jù)庫實(shí)例。
?
?
三、配置DTC和SQL Server 集群
分布式事務(wù)協(xié)調(diào)器(Distributed Transaction Coordinator, DTC)在Windows中是默認(rèn)安裝并運(yùn)行的服務(wù)。DTC的主要目的是為了實(shí)現(xiàn)分布式事務(wù),確??邕M(jìn)程通信的一致性,這里的進(jìn)程可以是同一計(jì)算機(jī)中的兩個(gè)進(jìn)程,也可以是不同計(jì)算機(jī)中的進(jìn)程。因而在微軟的世界里,常??吹紻TC的身影。
如果只是獨(dú)立安裝SQL Server數(shù)據(jù)庫引擎則無需配置DTC。但是在同時(shí)運(yùn)行SQL Serve集成服務(wù)(SQL Server Integration Services, SSIS)或者搭建SQL Sever故障轉(zhuǎn)移集群等需要分布式事務(wù)的場(chǎng)景中,則需要配置DTC。不配置DTC并不影響SQL Server集群的安裝,但是DTC沒能正確配置,SQL Server集群的功能將受到影響。
Windows Server 2008及以后版本在一個(gè)Windows集群中可以有多個(gè)DTC實(shí)例,這些DTC實(shí)例可以是集群實(shí)例也可以是本地實(shí)例(這里“實(shí)例”概念的類似于SQL Server數(shù)據(jù)庫引擎實(shí)例,是作為操作系統(tǒng)服務(wù)運(yùn)行的,是同一個(gè)可執(zhí)行程序的副本,在Windows集群中運(yùn)行的各類服務(wù)都是以實(shí)例的形式存在,這些實(shí)例依賴Windows集群實(shí)現(xiàn)故障轉(zhuǎn)移),甚至可以為SQL Server集群中每個(gè)SQL Server實(shí)例配置一個(gè)專屬的DTC實(shí)例。SQL Server集群實(shí)例按照如下的是順序選擇DTC實(shí)例:
使用SQL Server實(shí)例專屬的DTC實(shí)例,該DTC實(shí)例作為SQL Server實(shí)例以來的資源,如果DTC實(shí)例失敗,將造成SQL Server實(shí)例的失敗。SQL Server 2008及以后版本才有此項(xiàng)。
使用映射給SQL Server實(shí)例的DTC實(shí)例,使用命令msdtc可以為SQL Server實(shí)例映射DTC實(shí)例。

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

GTID (Global Transaction Identifier) ??solves the complexity of replication and failover in MySQL databases by assigning a unique identity to each transaction. 1. It simplifies replication management, automatically handles log files and locations, allowing slave servers to request transactions based on the last executed GTID. 2. Ensure consistency across servers, ensure that each transaction is applied only once on each server, and avoid data inconsistency. 3. Improve troubleshooting efficiency. GTID includes server UUID and serial number, which is convenient for tracking transaction flow and accurately locate problems. These three core advantages make MySQL replication more robust and easy to manage, significantly improving system reliability and data integrity.

MySQL main library failover mainly includes four steps. 1. Fault detection: Regularly check the main library process, connection status and simple query to determine whether it is downtime, set up a retry mechanism to avoid misjudgment, and can use tools such as MHA, Orchestrator or Keepalived to assist in detection; 2. Select the new main library: select the most suitable slave library to replace it according to the data synchronization progress (Seconds_Behind_Master), binlog data integrity, network delay and load conditions, and perform data compensation or manual intervention if necessary; 3. Switch topology: Point other slave libraries to the new master library, execute RESETMASTER or enable GTID, update the VIP, DNS or proxy configuration to

The steps to connect to the MySQL database are as follows: 1. Use the basic command format mysql-u username-p-h host address to connect, enter the username and password to log in; 2. If you need to directly enter the specified database, you can add the database name after the command, such as mysql-uroot-pmyproject; 3. If the port is not the default 3306, you need to add the -P parameter to specify the port number, such as mysql-uroot-p-h192.168.1.100-P3307; In addition, if you encounter a password error, you can re-enter it. If the connection fails, check the network, firewall or permission settings. If the client is missing, you can install mysql-client on Linux through the package manager. Master these commands

InnoDB is MySQL's default storage engine because it outperforms other engines such as MyISAM in terms of reliability, concurrency performance and crash recovery. 1. It supports transaction processing, follows ACID principles, ensures data integrity, and is suitable for key data scenarios such as financial records or user accounts; 2. It adopts row-level locks instead of table-level locks to improve performance and throughput in high concurrent write environments; 3. It has a crash recovery mechanism and automatic repair function, and supports foreign key constraints to ensure data consistency and reference integrity, and prevent isolated records and data inconsistencies.

To add MySQL's bin directory to the system PATH, it needs to be configured according to the different operating systems. 1. Windows system: Find the bin folder in the MySQL installation directory (the default path is usually C:\ProgramFiles\MySQL\MySQLServerX.X\bin), right-click "This Computer" → "Properties" → "Advanced System Settings" → "Environment Variables", select Path in "System Variables" and edit it, add the MySQLbin path, save it and restart the command prompt and enter mysql--version verification; 2.macOS and Linux systems: Bash users edit ~/.bashrc or ~/.bash_

MySQL's default transaction isolation level is RepeatableRead, which prevents dirty reads and non-repeatable reads through MVCC and gap locks, and avoids phantom reading in most cases; other major levels include read uncommitted (ReadUncommitted), allowing dirty reads but the fastest performance, 1. Read Committed (ReadCommitted) ensures that the submitted data is read but may encounter non-repeatable reads and phantom readings, 2. RepeatableRead default level ensures that multiple reads within the transaction are consistent, 3. Serialization (Serializable) the highest level, prevents other transactions from modifying data through locks, ensuring data integrity but sacrificing performance;

MySQL transactions follow ACID characteristics to ensure the reliability and consistency of database transactions. First, atomicity ensures that transactions are executed as an indivisible whole, either all succeed or all fail to roll back. For example, withdrawals and deposits must be completed or not occur at the same time in the transfer operation; second, consistency ensures that transactions transition the database from one valid state to another, and maintains the correct data logic through mechanisms such as constraints and triggers; third, isolation controls the visibility of multiple transactions when concurrent execution, prevents dirty reading, non-repeatable reading and fantasy reading. MySQL supports ReadUncommitted and ReadCommi.

IndexesinMySQLimprovequeryspeedbyenablingfasterdataretrieval.1.Theyreducedatascanned,allowingMySQLtoquicklylocaterelevantrowsinWHEREorORDERBYclauses,especiallyimportantforlargeorfrequentlyqueriedtables.2.Theyspeedupjoinsandsorting,makingJOINoperation
