您好,登錄后才能下訂單哦!
部署SQL Server 2016基于工作組的AlwaysOn AG
部署說明:
以下部署基于工作組環境、不用證書、啟動賬號為Users組成員、各節點位于同一網段。
前期環境準備參考之前的文章:
部署Windows Server 2016基于工作組的集群
安裝和配置SQL Server 2016 With SP1
Part1:創建測試數據庫
CREATE DATABASE Chapter5App1Customers ; GO ALTER DATABASE Chapter5App1Customers SET RECOVERY FULL ; GO USE Chapter5App1Customers GO CREATE TABLE App1Customers ( ID INT PRIMARY KEY IDENTITY, FirstName NVARCHAR(30), LastName NVARCHAR(30), CreditCardNumber VARBINARY(8000) ) ; GO --Populate the table DECLARE @Numbers TABLE ( Number INT ) ;WITH CTE(Number) AS ( SELECT 1 Number UNION ALL SELECT Number + 1 FROM CTE WHERE Number < 100 ) INSERT INTO @Numbers SELECT Number FROM CTE DECLARE @Names TABLE ( FirstName VARCHAR(30), LastName VARCHAR(30) ) ; INSERT INTO @Names VALUES('Peter', 'Carter'), ('Michael', 'Smith'), ('Danielle', 'Mead'), ('Reuben', 'Roberts'), ('Iris', 'Jones'), ('Sylvia', 'Davies'), ('Finola', 'Wright'), ('Edward', 'James'), ('Marie', 'Andrews'), ('Jennifer', 'Abraham'), ('Margaret', 'Jones') INSERT INTO App1Customers(Firstname, LastName, CreditCardNumber) SELECT FirstName, LastName, CreditCardNumber FROM (SELECT (SELECT TOP 1 FirstName FROM @Names ORDER BY NEWID()) FirstName ,(SELECT TOP 1 LastName FROM @Names ORDER BY NEWID()) LastName ,(SELECT CONVERT(VARBINARY(8000) ,(SELECT TOP 1 CAST(Number * 100 AS CHAR(4)) FROM @Numbers WHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' + (SELECT TOP 1 CAST(Number * 100 AS CHAR(4)) FROM @Numbers WHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' + (SELECT TOP 1 CAST(Number * 100 AS CHAR(4)) FROM @Numbers WHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' + (SELECT TOP 1 CAST(Number * 100 AS CHAR(4)) FROM @Numbers WHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()))) CreditCardNumber FROM @Numbers a CROSS JOIN @Numbers b CROSS JOIN @Numbers c ) d ; CREATE DATABASE Chapter5App1Sales ; GO ALTER DATABASE Chapter5App1Sales SET RECOVERY FULL ; GO USE Chapter5App1Sales GO CREATE TABLE dbo.Orders( OrderNumber int NOT NULL IDENTITY(1,1) PRIMARY KEY CLUSTERED, OrderDate date NOT NULL, CustomerID int NOT NULL, ProductID int NOT NULL, Quantity int NOT NULL, NetAmount money NOT NULL, TaxAmount money NOT NULL, InvoiceAddressID int NOT NULL, DeliveryAddressID int NOT NULL, DeliveryDate date NULL, ) ; DECLARE @Numbers TABLE ( Number INT ) ;WITH CTE(Number) AS ( SELECT 1 Number UNION ALL SELECT Number + 1 FROM CTE WHERE Number < 100 ) INSERT INTO @Numbers SELECT Number FROM CTE --Populate ExistingOrders with data INSERT INTO Orders SELECT (SELECT CAST(DATEADD(dd,(SELECT TOP 1 Number FROM @Numbers ORDER BY NEWID()),getdate())as DATE)), (SELECT TOP 1 Number -10 FROM @Numbers ORDER BY NEWID()), (SELECT TOP 1 Number FROM @Numbers ORDER BY NEWID()), (SELECT TOP 1 Number FROM @Numbers ORDER BY NEWID()), 500, 100, (SELECT TOP 1 Number FROM @Numbers ORDER BY NEWID()), (SELECT TOP 1 Number FROM @Numbers ORDER BY NEWID()), (SELECT CAST(DATEADD(dd,(SELECT TOP 1 Number - 10 FROM @Numbers ORDER BY NEWID()),getdate()) as DATE)) FROM @Numbers a CROSS JOIN @Numbers b CROSS JOIN @Numbers c ; CREATE DATABASE Chapter5App2Customers ; GO ALTER DATABASE Chapter5App2Customers SET RECOVERY FULL ; GO USE Chapter5App2Customers GO CREATE TABLE App2Customers ( ID INT PRIMARY KEY IDENTITY, FirstName NVARCHAR(30), LastName NVARCHAR(30), CreditCardNumber VARBINARY(8000) ) ; GO --Populate the table DECLARE @Numbers TABLE ( Number INT ) ; ;WITH CTE(Number) AS ( SELECT 1 Number UNION ALL SELECT Number + 1 FROM CTE WHERE Number < 100 ) INSERT INTO @Numbers SELECT Number FROM CTE ; DECLARE @Names TABLE ( FirstName VARCHAR(30), LastName VARCHAR(30) ) ; INSERT INTO @Names VALUES('Peter', 'Carter'), ('Michael', 'Smith'), ('Danielle', 'Mead'), ('Reuben', 'Roberts'), ('Iris', 'Jones'), ('Sylvia', 'Davies'), ('Finola', 'Wright'), ('Edward', 'James'), ('Marie', 'Andrews'), ('Jennifer', 'Abraham'), ('Margaret', 'Jones') INSERT INTO App2Customers(Firstname, LastName, CreditCardNumber) SELECT FirstName, LastName, CreditCardNumber FROM (SELECT (SELECT TOP 1 FirstName FROM @Names ORDER BY NEWID()) FirstName ,(SELECT TOP 1 LastName FROM @Names ORDER BY NEWID()) LastName ,(SELECT CONVERT(VARBINARY(8000) ,(SELECT TOP 1 CAST(Number * 100 AS CHAR(4)) FROM @Numbers WHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' + (SELECT TOP 1 CAST(Number * 100 AS CHAR(4)) FROM @Numbers WHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' + (SELECT TOP 1 CAST(Number * 100 AS CHAR(4)) FROM @Numbers WHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' + (SELECT TOP 1 CAST(Number * 100 AS CHAR(4)) FROM @Numbers WHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()))) CreditCardNumber FROM @Numbers a CROSS JOIN @Numbers b CROSS JOIN @Numbers c ) d ;
Part2:配置SQL Server
Part4:創建AG內數據庫的完整備份
BACKUP DATABASE Chapter5App1Customers TO DISK = N'C:\Backups\Chapter5App1Customers.bak' WITH NAME = N'Chapter5App1Customers-Full Database Backup' ; GO BACKUP DATABASE Chapter5App1Sales TO DISK = N'C:\Backups\Chapter5App1Sales.bak' WITH NAME = N'Chapter5App1Sales-Full Database Backup' ; GO
Part5:將備份在AG內的其他副本上恢復為NORECOVERY
Part6:將啟動賬號添加到Logins
--提前創建端點 USE [master] GO CREATE ENDPOINT [Hadr_endpoint] STATE=STARTED AS TCP (LISTENER_PORT = 5022, LISTENER_IP = ALL) FOR DATA_MIRRORING (ROLE = ALL, AUTHENTICATION = WINDOWS NEGOTIATE , ENCRYPTION = REQUIRED ALGORITHM AES) GO DECLARE @Server sysname, @HostName sysname, @Login sysname, @SQL nvarchar(max) ; --獲取實例名 SET @Server = CAST(SERVERPROPERTY('ServerName') AS sysname); --獲取機器名(遠程執行時HOST_NAME()函數不代表遠程主機) IF CHARINDEX('\\',@Server,1) <> 0 SET @HostName = SUBSTRING(@Server,1,CHARINDEX('\\',@Server,1)-1); ELSE SET @HostName = @Server; --用到SQL Server Database Engine服務啟動賬號 SET @Login = @HostName + '\SQLService'; IF NOT EXISTS(SELECT name FROM sys.syslogins WHERE isntuser=1 AND name = @Login) BEGIN --SELECT @Login EXEC sp_grantlogin @Login; --EXEC sp_addsrvrolemember @Login, 'sysadmin'; --端點訪問授權 SET @SQL = N'GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [' + @Login + ']'; --SELECT @SQL EXEC sp_executesql @SQL; END
Part7:創建AG
SQL Server 2016 AlwaysOn AG有很多提升,令我影響深刻的是日志吞吐量的提升和redo的提升。這里講介紹它的另一項關鍵提升,也就是這個配置選項:Database Level Health Detection。
SQL Server 2016使用數據庫健康檢測增強了AlwaysOn健康診斷。如果你的AG的該選項被勾選,而其中某個數據庫變為非ONLINE狀態,那么整個AG將會自動故障轉移。
Part8:檢查AG狀態
Part9:測試Server01宕機后
Part10:測試Server02恢復后
參考:
Workgroup and Multi-domain clusters in Windows Server 2016
《SQL Server AlwaysOn Revealed》
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。