部署SQL Server 2016基于工作组的AlwaysOn AG
发表于:2025-01-22 作者:千家信息网编辑
千家信息网最后更新 2025年01月22日,部署SQL Server 2016基于工作组的AlwaysOn AG部署说明:以下部署基于工作组环境、不用证书、启动账号为Users组成员、各节点位于同一网段。前期环境准备参考之前的文章:部署Wind
千家信息网最后更新 2025年01月22日部署SQL Server 2016基于工作组的AlwaysOn AG
部署SQL Server 2016基于工作组的AlwaysOn AG
部署说明:
以下部署基于工作组环境、不用证书、启动账号为Users组成员、各节点位于同一网段。
前期环境准备参考之前的文章:
部署Windows Server 2016基于工作组的集群
安装和配置SQL Server 2016 With SP1
Part1:创建测试数据库
CREATE DATABASE Chapter5App1Customers ;GOALTER DATABASE Chapter5App1Customers SET RECOVERY FULL ;GOUSE Chapter5App1CustomersGOCREATE TABLE App1Customers(ID INT PRIMARY KEY IDENTITY,FirstName NVARCHAR(30),LastName NVARCHAR(30),CreditCardNumber VARBINARY(8000)) ;GO--Populate the tableDECLARE @Numbers TABLE(Number INT);WITH CTE(Number)AS(SELECT 1 NumberUNION ALLSELECT Number + 1FROM CTEWHERE Number < 100)INSERT INTO @NumbersSELECT Number FROM CTEDECLARE @Names TABLE(FirstName VARCHAR(30),LastName VARCHAR(30)) ;INSERT INTO @NamesVALUES('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 @NumbersWHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' +(SELECT TOP 1 CAST(Number * 100 AS CHAR(4))FROM @NumbersWHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' +(SELECT TOP 1 CAST(Number * 100 AS CHAR(4))FROM @NumbersWHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' +(SELECT TOP 1 CAST(Number * 100 AS CHAR(4))FROM @NumbersWHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()))) CreditCardNumberFROM @Numbers aCROSS JOIN @Numbers bCROSS JOIN @Numbers c) d ;CREATE DATABASE Chapter5App1Sales ;GOALTER DATABASE Chapter5App1Sales SET RECOVERY FULL ;GOUSE Chapter5App1SalesGOCREATE 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 NumberUNION ALLSELECT Number + 1FROM CTEWHERE Number < 100)INSERT INTO @NumbersSELECT Number FROM CTE--Populate ExistingOrders with dataINSERT INTO OrdersSELECT(SELECT CAST(DATEADD(dd,(SELECT TOP 1 NumberFROM @NumbersORDER 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 - 10FROM @NumbersORDER BY NEWID()),getdate()) as DATE))FROM @Numbers aCROSS JOIN @Numbers bCROSS JOIN @Numbers c ;CREATE DATABASE Chapter5App2Customers ;GOALTER DATABASE Chapter5App2Customers SET RECOVERY FULL ;GOUSE Chapter5App2CustomersGOCREATE TABLE App2Customers(ID INT PRIMARY KEY IDENTITY,FirstName NVARCHAR(30),LastName NVARCHAR(30),CreditCardNumber VARBINARY(8000)) ;GO--Populate the tableDECLARE @Numbers TABLE(Number INT) ;;WITH CTE(Number)AS(SELECT 1 NumberUNION ALLSELECT Number + 1FROM CTEWHERE Number < 100)INSERT INTO @NumbersSELECT Number FROM CTE ;DECLARE @Names TABLE(FirstName VARCHAR(30),LastName VARCHAR(30)) ;INSERT INTO @NamesVALUES('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 @NumbersWHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' +(SELECT TOP 1 CAST(Number * 100 AS CHAR(4))FROM @NumbersWHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' +(SELECT TOP 1 CAST(Number * 100 AS CHAR(4))FROM @NumbersWHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()) + '-' +(SELECT TOP 1 CAST(Number * 100 AS CHAR(4))FROM @NumbersWHERE Number BETWEEN 10 AND 99 ORDER BY NEWID()))) CreditCardNumberFROM @Numbers aCROSS JOIN @Numbers bCROSS JOIN @Numbers c) d ;
Part2:配置SQL Server
Part4:创建AG内数据库的完整备份
BACKUP DATABASE Chapter5App1CustomersTO DISK = N'C:\Backups\Chapter5App1Customers.bak'WITH NAME = N'Chapter5App1Customers-Full Database Backup' ;GOBACKUP DATABASE Chapter5App1SalesTO DISK = N'C:\Backups\Chapter5App1Sales.bak'WITH NAME = N'Chapter5App1Sales-Full Database Backup' ;GO
Part5:将备份在AG内的其他副本上恢复为NORECOVERY
Part6:将启动账号添加到Logins
--提前创建端点USE [master]GOCREATE 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)GODECLARE @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》
数据
数据库
工作组
工作
账号
测试
配置
健康
备份
状态
环境
端点
参考
不用
主机
也就是
代表
关键
函数
前期
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全行业可以考文职
阿里巴巴怎么刷数据库
全国地址信息数据库
软件开发可行性是指什么
国家网络安全优质课教案
中国工商银行软件开发中心视频
软件开发计算费
安徽企业软件开发价格多少
机房建设和服务器管理面试
抚州高性价比服务器价格
中金软件开发待遇
软件开发被说太笨
国外大学毕业论文数据库
软件开发的危机
打造网络安全奏响网络强国梦
软件开发一般多少钱一个人日
软件开发新领域论文
数据库是将许多具有相关性
杭州鼎承网络技术
浙江专业软件开发行业
生产企业网络安全防控措施
网络安全问题出现下降趋势
欧姆龙数据库发生错误
安全可靠的新药数据库
黑龙江网络安全保卫局
db2的实例和数据库分开
无锡项目软件开发来电咨询
如何在服务器中添加皮肤
中韩电商软件开发
支付宝网络技术有限快捷支付