Alwayson--使用证书创建高可用性组
--场景:
--有服务器SQLNode11,SQLNODE21,SQLNODE31三台在同一故障转移群集SQLNode01中
--的数据库服务器,安装SQL SERVER 2012 并配置启动alwayson高可用性组,服务使
--用localsystem运行,为SQLNode11上数据库DB1和DB2创建高可用性组,并将
--SQLNode21和SQLNode31加入到可用性组中。
--实现步骤概述:在各个节点上创建证书和端点并备份证书,使用备份依次在其他
--两个节点上创建登陆用户,在各个节点创建证书并为将连接权限赋予登陆用户,
--激活alwayson回话服务,在主节点SQLNode11上备份数据库并使用WITH NORECOVERY
--在从节点SQLNode21和SQLNode31上还原数据库,在主节点SQLNode11创建高可用性
--组,在从节点SQLNode21和SQLNode31上加入到可用性组,并在从节点SQLNode21
--和SQLNode31上将数据库添加到可用组中。
--1. 在节点SQLNode11创建和备份证书和创建镜像端点
USE master;
USE master;
GO
--=========================================================================================================
--创建Master key
IF NOT EXISTS(SELECT 1 FROM sys.symmetric_keys k WHERE k.Name='##MS_DatabaseMasterKey##')
BEGIN
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='Master@key'
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.databases db WHERE db.[is_master_key_encrypted_by_server]=1)
BEGIN
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY
END
GO
--=========================================================================================================
--创建和备份证书
IF NOT EXISTS (SELECT 1 FROM sys.certificates C WHERE C.Name='ServerCert_SQLNode11' )
BEGIN
CREATE CERTIFICATE ServerCert_SQLNode11 WITH SUBJECT ='ServerCert_SQLNode11'
END
GO
BACKUP CERTIFICATE ServerCert_SQLNode11 TO FILE='D:\ServerCert_SQLNode11.cer'
GO
--=========================================================================================================
--创建镜像专用的端点,并使用证书加密
--同一个实例上只能存在一个镜像端点
IF NOT EXISTS(SELECT * FROM sys.endpoints e WHERE e.[Type]=4)
BEGIN
CREATE ENDPOINT DBMirrorEndPoint
STATE=STARTED AS
TCP(LISTENER_PORT=5022)
FOR DATABASE_MIRRORING(AUTHENTICATION=CERTIFICATE ServerCert_SQLNode11, ENCRYPTION=REQUIRED,ROLE=ALL)
END
GO
--2. 在节点SQLNode21创建和备份证书和创建镜像端点
USE master;
GO
--=========================================================================================================
--创建Master key
IF NOT EXISTS(SELECT 1 FROM sys.symmetric_keys k WHERE k.Name='##MS_DatabaseMasterKey##')
BEGIN
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='Master@key'
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.databases db WHERE db.[is_master_key_encrypted_by_server]=1)
BEGIN
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY
END
GO
--=========================================================================================================
--创建和备份证书
IF NOT EXISTS (SELECT 1 FROM sys.certificates C WHERE C.Name='ServerCert_SQLNode21' )
BEGIN
CREATE CERTIFICATE ServerCert_SQLNode21 WITH SUBJECT ='ServerCert_SQLNode21'
END
GO
BACKUP CERTIFICATE ServerCert_SQLNode21 TO FILE='D:\ServerCert_SQLNode21.cer'
GO
--=========================================================================================================
--创建镜像专用的端点,并使用证书加密
--同一个实例上只能存在一个镜像端点
IF NOT EXISTS(SELECT * FROM sys.endpoints e WHERE e.[Type]=4)
BEGIN
CREATE ENDPOINT DBMirrorEndPoint
STATE=STARTED AS
TCP(LISTENER_PORT=5022)
FOR DATABASE_MIRRORING(AUTHENTICATION=CERTIFICATE ServerCert_SQLNode21, ENCRYPTION=REQUIRED,ROLE=ALL)
END
GO
--3. 在节点SQLNode31创建和备份证书和创建镜像端点
USE master;
GO
--=========================================================================================================
--创建Master key
IF NOT EXISTS(SELECT 1 FROM sys.symmetric_keys k WHERE k.Name='##MS_DatabaseMasterKey##')
BEGIN
CREATE MASTER KEY ENCRYPTION BY PASSWORD ='Master@key'
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.databases db WHERE db.[is_master_key_encrypted_by_server]=1)
BEGIN
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY
END
GO
--=========================================================================================================
--创建和备份证书
IF NOT EXISTS (SELECT 1 FROM sys.certificates C WHERE C.Name='ServerCert_SQLNode31' )
BEGIN
CREATE CERTIFICATE ServerCert_SQLNode31 WITH SUBJECT ='ServerCert_SQLNode31'
END
GO
BACKUP CERTIFICATE ServerCert_SQLNode31 TO FILE='D:\ServerCert_SQLNode31.cer'
GO
--=========================================================================================================
--创建镜像专用的端点,并使用证书加密
--同一个实例上只能存在一个镜像端点
IF NOT EXISTS(SELECT * FROM sys.endpoints e WHERE e.[Type]=4)
BEGIN
CREATE ENDPOINT DBMirrorEndPoint
STATE=STARTED AS
TCP(LISTENER_PORT=5022)
FOR DATABASE_MIRRORING(AUTHENTICATION=CERTIFICATE ServerCert_SQLNode31, ENCRYPTION=REQUIRED,ROLE=ALL)
END
GO
--4. 在SQLNode11上创建登陆和用户,并赋予连接端点权限
USE master;
GO
--=========================================================================================================
--创建登陆和用户,并赋予连接端点权限
IF NOT EXISTS(SELECT 1 FROM sys.syslogins l WHERE l.[Name] ='ServerLogin_SQLNode21')
BEGIN
CREATE LOGIN ServerLogin_SQLNode21 WITH PASSWORD ='Auto@sql'
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.sysusers u WHERE u.[Name]= 'ServerUser_SQLNode21')
BEGIN
CREATE USER ServerUser_SQLNode21 FOR LOGIN ServerLogin_SQLNode21
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.certificates c WHERE c.[Name]= 'ServerCert_SQLNode21')
BEGIN
CREATE CERTIFICATE ServerCert_SQLNode21 AUTHORIZATION ServerUser_SQLNode21 FROM FILE='D:\ServerCert_SQLNode21.cer'
END
GO
GRANT CONNECT ON ENDPOINT::DBMirrorEndPoint TO ServerLogin_SQLNode21
GO
USE master;
GO
--=========================================================================================================
--创建登陆和用户,并赋予连接端点权限
IF NOT EXISTS(SELECT 1 FROM sys.syslogins l WHERE l.[Name] ='ServerLogin_SQLNode31')
BEGIN
CREATE LOGIN ServerLogin_SQLNode31 WITH PASSWORD ='Auto@sql'
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.sysusers u WHERE u.[Name]= 'ServerUser_SQLNode31')
BEGIN
CREATE USER ServerUser_SQLNode31 FOR LOGIN ServerLogin_SQLNode31
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.certificates c WHERE c.[Name]= 'ServerCert_SQLNode31')
BEGIN
CREATE CERTIFICATE ServerCert_SQLNode31 AUTHORIZATION ServerUser_SQLNode31 FROM FILE='D:\ServerCert_SQLNode31.cer'
END
GO
GRANT CONNECT ON ENDPOINT::DBMirrorEndPoint TO ServerLogin_SQLNode31
GO
--5. 在SQLNode21上创建登陆和用户,并赋予连接端点权限
USE master;
GO
--=========================================================================================================
--创建登陆和用户,并赋予连接端点权限
IF NOT EXISTS(SELECT 1 FROM sys.syslogins l WHERE l.[Name] ='ServerLogin_SQLNode11')
BEGIN
CREATE LOGIN ServerLogin_SQLNode11 WITH PASSWORD ='Auto@sql'
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.sysusers u WHERE u.[Name]= 'ServerUser_SQLNode11')
BEGIN
CREATE USER ServerUser_SQLNode11 FOR LOGIN ServerLogin_SQLNode11
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.certificates c WHERE c.[Name]= 'ServerCert_SQLNode11')
BEGIN
CREATE CERTIFICATE ServerCert_SQLNode11 AUTHORIZATION ServerUser_SQLNode11 FROM FILE='D:\ServerCert_SQLNode11.cer'
END
GO
GRANT CONNECT ON ENDPOINT::DBMirrorEndPoint TO ServerLogin_SQLNode11
GO
USE master;
GO
--=========================================================================================================
--创建登陆和用户,并赋予连接端点权限
IF NOT EXISTS(SELECT 1 FROM sys.syslogins l WHERE l.[Name] ='ServerLogin_SQLNode31')
BEGIN
CREATE LOGIN ServerLogin_SQLNode31 WITH PASSWORD ='Auto@sql'
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.sysusers u WHERE u.[Name]= 'ServerUser_SQLNode31')
BEGIN
CREATE USER ServerUser_SQLNode31 FOR LOGIN ServerLogin_SQLNode31
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.certificates c WHERE c.[Name]= 'ServerCert_SQLNode31')
BEGIN
CREATE CERTIFICATE ServerCert_SQLNode31 AUTHORIZATION ServerUser_SQLNode31 FROM FILE='D:\ServerCert_SQLNode31.cer'
END
GO
GRANT CONNECT ON ENDPOINT::DBMirrorEndPoint TO ServerLogin_SQLNode31
GO
--6. 在SQLNode31上创建登陆和用户,并赋予连接端点权限
USE master;
GO
--=========================================================================================================
--创建登陆和用户,并赋予连接端点权限
IF NOT EXISTS(SELECT 1 FROM sys.syslogins l WHERE l.[Name] ='ServerLogin_SQLNode11')
BEGIN
CREATE LOGIN ServerLogin_SQLNode11 WITH PASSWORD ='Auto@sql'
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.sysusers u WHERE u.[Name]= 'ServerUser_SQLNode11')
BEGIN
CREATE USER ServerUser_SQLNode11 FOR LOGIN ServerLogin_SQLNode11
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.certificates c WHERE c.[Name]= 'ServerCert_SQLNode11')
BEGIN
CREATE CERTIFICATE ServerCert_SQLNode11 AUTHORIZATION ServerUser_SQLNode11 FROM FILE='D:\ServerCert_SQLNode11.cer'
END
GO
GRANT CONNECT ON ENDPOINT::DBMirrorEndPoint TO ServerLogin_SQLNode11
GO
USE master;
GO
--=========================================================================================================
--创建登陆和用户,并赋予连接端点权限
IF NOT EXISTS(SELECT 1 FROM sys.syslogins l WHERE l.[Name] ='ServerLogin_SQLNode21')
BEGIN
CREATE LOGIN ServerLogin_SQLNode21 WITH PASSWORD ='Auto@sql'
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.sysusers u WHERE u.[Name]= 'ServerUser_SQLNode21')
BEGIN
CREATE USER ServerUser_SQLNode21 FOR LOGIN ServerLogin_SQLNode21
END
GO
IF NOT EXISTS(SELECT 1 FROM sys.certificates c WHERE c.[Name]= 'ServerCert_SQLNode21')
BEGIN
CREATE CERTIFICATE ServerCert_SQLNode21 AUTHORIZATION ServerUser_SQLNode21 FROM FILE='D:\ServerCert_SQLNode21.cer'
END
GO
GRANT CONNECT ON ENDPOINT::DBMirrorEndPoint TO ServerLogin_SQLNode21
GO
--7. 在SQLNode11上激活alwayson回话
USE master;
GO
IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name='AlwaysOn_health')
BEGIN
ALTER EVENT SESSION [AlwaysOn_health] ON SERVER WITH (STARTUP_STATE=ON);
END
IF NOT EXISTS(SELECT * FROM sys.dm_xe_sessions WHERE name='AlwaysOn_health')
BEGIN
ALTER EVENT SESSION [AlwaysOn_health] ON SERVER STATE=START;
END
GO
--8. 在书在SQLNode21上激活alwayson回话
USE master;
GO
IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name='AlwaysOn_health')
BEGIN
ALTER EVENT SESSION [AlwaysOn_health] ON SERVER WITH (STARTUP_STATE=ON);
END
IF NOT EXISTS(SELECT * FROM sys.dm_xe_sessions WHERE name='AlwaysOn_health')
BEGIN
ALTER EVENT SESSION [AlwaysOn_health] ON SERVER STATE=START;
END
GO
--9. 在SQLNode31上激活alwayson回话
USE master;
GO
IF EXISTS(SELECT * FROM sys.server_event_sessions WHERE name='AlwaysOn_health')
BEGIN
ALTER EVENT SESSION [AlwaysOn_health] ON SERVER WITH (STARTUP_STATE=ON);
END
IF NOT EXISTS(SELECT * FROM sys.dm_xe_sessions WHERE name='AlwaysOn_health')
BEGIN
ALTER EVENT SESSION [AlwaysOn_health] ON SERVER STATE=START;
END
GO
--10. 在SQLNode11上备份数据库
USE master;
GO
BACKUP DATABASE [DB1] TO DISK = N'D:\DB1_F1.bak' WITH NOFORMAT, NOINIT, NAME = N'DB1-完整数据库备份', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
BACKUP DATABASE [DB2] TO DISK = N'D:\DB2_F1.bak' WITH NOFORMAT, NOINIT, NAME = N'DB2-完整数据库备份', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
--11. 在SQLNode11上创建可用性组
USE [master]
GO
CREATE AVAILABILITY GROUP [SQLNode01_AG001]
WITH (AUTOMATED_BACKUP_PREFERENCE = SECONDARY)
FOR DATABASE [DB1], [DB2]
REPLICA ON N'SQLNODE11' WITH
(
ENDPOINT_URL = N'TCP://SQLNode11.DCDemo.com:5022',
FAILOVER_MODE = AUTOMATIC, AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
BACKUP_PRIORITY = 50,
SECONDARY_ROLE(ALLOW_CONNECTIONS = NO)
),
N'SQLNODE21' WITH
(
ENDPOINT_URL = N'TCP://SqlNode21.DCDemo.com:5022',
FAILOVER_MODE = AUTOMATIC,
AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
BACKUP_PRIORITY = 50,
SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL)
),
N'SQLNODE31' WITH
(
ENDPOINT_URL = N'TCP://SqlNode31.DCDemo.com:5022',
FAILOVER_MODE = MANUAL,
AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
BACKUP_PRIORITY = 50,
SECONDARY_ROLE(ALLOW_CONNECTIONS = READ_ONLY)
);
GO
--12. 在SQLNode21和SQLNode31上加入可用性组
USE master;
GO
ALTER AVAILABILITY GROUP [SQLNode01_AG001] JOIN;
GO
--13. 将数据库备份拷贝到SQLNode21和SQLNode31上并还原数据库
USE master;
GO
RESTORE DATABASE [DB1] FROM DISK = N'D:\DB1_F1.bak' WITH NORECOVERY, NOUNLOAD, STATS = 5
GO
RESTORE DATABASE [DB2] FROM DISK = N'D:\DB2_F1.bak' WITH NORECOVERY, NOUNLOAD, STATS = 5
GO
--14. 在SQLNode11上备份日志
USE master;
GO
BACKUP LOG [DB1] TO DISK = N'D:\DB1_L1.trn' WITH NOFORMAT, NOINIT, NOSKIP, REWIND, NOUNLOAD, COMPRESSION, STATS = 5
GO
BACKUP LOG [DB2] TO DISK = N'D:\DB2_L1.trn' WITH NOFORMAT, NOINIT, NOSKIP, REWIND, NOUNLOAD, COMPRESSION, STATS = 5
GO
--15. 在SQLNode21和SQLNOde31上还原日志备份
USE master;
GO
RESTORE LOG [DB1] FROM DISK = N'D:\DB1_L1.trn' WITH NORECOVERY, NOUNLOAD, STATS = 5
GO
GO
RESTORE LOG [DB2] FROM DISK = N'D:\DB2_L1.trn' WITH NORECOVERY, NOUNLOAD, STATS = 5
GO
--16. 在SQLNode21和SQLNOde31上将DB添加到可用性组
USE master;
GO
ALTER DATABASE [DB1] SET HADR AVAILABILITY GROUP = [SQLNode01_AG001];
GO
ALTER DATABASE [DB2] SET HADR AVAILABILITY GROUP = [SQLNode01_AG001];
GO
Alwayson--使用证书创建高可用性组的更多相关文章
- 部署AlwaysOn第二步:配置AlwaysOn,创建可用性组
AlwaysOn是在SQL Server 2012中新引入的一种高可用技术,从名称中可以看出,AlwaysOn的设计目标是保持数据库系统永远可用.AlwaysOn利用了Windows服务器故障转移集群 ...
- 如何在 Azure 中均衡 Linux 虚拟机负载以创建高可用性应用程序
负载均衡通过将传入请求分布到多个虚拟机来提供更高级别的可用性. 本教程介绍了 Azure 负载均衡器的不同组件,这些组件用于分发流量和提供高可用性. 你将学习如何执行以下操作: 创建 Azure 负载 ...
- Linux LVM学习总结——创建卷组VG
在Linux平台如何创建一个卷组(VG)呢?下面简单介绍一下卷组(VG)的创建步骤.本文实验平台为Red Hat Enterprise Linux Server release 6.6 (Santia ...
- Makecert.exe(证书创建工具)
Makecert.exe(证书创建工具) .NET Framework 4.5 其他版本 2(共 3)对本文的评价是有帮助 - 评价此主题 证书创建工具生成仅用于测试目的的 X.509 证 ...
- C# linq创建嵌套组
以下示例演示如何在 LINQ 查询表达式中创建嵌套组. 首先根据学生年级创建每个组,然后根据每个人的姓名进一步细分为小组. public void QueryNestedGroups() { var ...
- lvm创建卷组和格式化
* 前提条件:/dev/sdb为一块空的硬盘 * 创建物理卷:pvcreate /dev/sdb * 创建卷组:vgcreate vol_name /dev/sdb (vol_name 为卷组名字) ...
- XMPP系列(六)---创建群组
最近公司项目需要,要做一个自己的IMSDK,顺便先把之前没有记录的群聊功能记录一下. 先上资料,查看XMPP群聊相关的资料,可以去这里看协议:XEP-0045 . 创建群组 XMPP 框架里有一个类X ...
- SAP Brazil J1BTAX 为税收例外创建税收组(翻译)
很多人对如何维持巴西的税收仍有疑问.前段时间,一家有几个税务问题的公司联系我帮助他们,我发现多年来,由于他们的税务计算系统缺少配置,他们正在进行手动调整. 维持税收的第一条规则是: TAXBRJ = ...
- C#程序证书创建工具 (Makecert.exe)
原文地址:https://msdn.microsoft.com/zh-cn/library/bfsktky3(VS.80).aspx 证书创建工具生成仅用于测试目的的 X.509 证书.它创建用于数字 ...
随机推荐
- python获取当前日期
今天群里一个人问了怎么获取当前时间的问题,以前接触过计算日期之差的,具体代码如下: import datetime d1=datetime.datetime(2014,3,14) d2=datetim ...
- Loadrunner进行参数化
Loadrunner进行参数化 Loadrunner中进行参数化,这里有三种方法. 对需要多次使用的变量进行参数化,比如登录信息的用户名和密码,首先需要选中需要参数化的值,然后右键选择Replace ...
- Cookie的Domain属性
Cookie 加了Domain后就写不进去了(不加domain就可以写进去了) 本地测试的时候需要把domain换成localhost cookie跨域的问题,意思就是说A.com下能访问B.com域 ...
- Maven项目标准目录结构
-----------------------siwuxie095 Maven 项目标准目录结构 1.Maven 项目分为两种 (1)Java 项目 (2)Web 项目 2.对于 Java 项目 其中 ...
- leetcdoe 175. Combine Two Tables
给定两个表,一个是人,一个是地址,要求查询所有人,可以没有地址. select a.FirstName, a.LastName, b.City, b.State from Person as a le ...
- 【JVM】浅谈双亲委派和破坏双亲委派
一.前言 笔者曾经阅读过周志明的<深入理解Java虚拟机>这本书,阅读完后自以为对jvm有了一定的了解,然而当真正碰到问题的时候,才发现自己读的有多粗糙,也体会到只有实践才能加深理解,正应 ...
- DLL另類劫持注入法
// Win32Project2.cpp : 定义 DLL 应用程序的导出函数. // //////////////////////////////////////////////////////// ...
- linux下xampp(apache)中配置域名访问,以及遇到的问题
xampp中apache使用域名访问 一.首先找到/opt/lampp/etc/httpd.conf: # Virtual hosts Include etc/extra/httpd-vhosts.c ...
- 品味性能之道<十>:Oracle Hint
Hint 是Oracle 提供的一种SQL语法,它允许用户在SQL语句中插入相关的语法,从而影响SQL的执行方式. 因为Hint的特殊作用,所以对于开发人员不应该在代码中使用它,Hint 更像是Ora ...
- crontab定时任务操作
一.查看定时任务 crontab -l 二.添加定时任务 crontab -e (一)执行外部链接 //每隔10分钟执行1次 */ * * * * /usr/bin/curl "http:/ ...