使用证书配置的镜像基本安装微软次序做就可以了

http://msdn.microsoft.com/zh-cn/library/ms191140.aspx

备份还原首先要转换成完全备份模式没什么好多说的

 USE master;
GO
ALTER DATABASE
SET RECOVERY FULL;
GO

直接备份数据库不能直接写C盘,目录自己建

 BACKUP DATABASE [AdventureWorks2012]
TO DISK = 'C:\HOSTA\AdventureWorks2012.bak'
WITH FORMAT
GO

同样还原也需要指定,注意一定要使用WITH NORECOVERY

 USE [master]
RESTORE DATABASE [AdventureWorks2012]
FROM DISK = N'C:\HOSTB\AdventureWorks2012.bak'
WITH NORECOVERY,
MOVE N'AdventureWorks2012_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2\MSSQL\DATA\AdventureWorks2012_Data.mdf',
MOVE N'AdventureWorks2012_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2\MSSQL\DATA\AdventureWorks2012_log.ldf'
GO

证书创建和对倒部分其实就一步步做就可以了,注意端口号,路径用刚才的路径就成。密码偷懒也可以不改,原则上机器用的密码不要设置过期日期

HOSTA上

 USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<1_Strong_Password!>';
GO
USE master;
CREATE CERTIFICATE HOST_A_cert
WITH SUBJECT = 'HOST_A certificate';
GO
CREATE ENDPOINT Endpoint_Mirroring
STATE = STARTED
AS TCP (
LISTENER_PORT=7024
, LISTENER_IP = ALL
)
FOR DATABASE_MIRRORING (
AUTHENTICATION = CERTIFICATE HOST_A_cert
, ENCRYPTION = REQUIRED ALGORITHM AES
, ROLE = ALL
);
GO
BACKUP CERTIFICATE HOST_A_cert TO FILE = 'C:\HOSTA\HOST_A_cert.cer';
GO

HOSTB上

 USE master;
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '<Strong_Password_#2>';
GO
CREATE CERTIFICATE HOST_B_cert
WITH SUBJECT = 'HOST_B certificate for database mirroring';
GO
CREATE ENDPOINT Endpoint_Mirroring
STATE = STARTED
AS TCP (
LISTENER_PORT=7024
, LISTENER_IP = ALL
)
FOR DATABASE_MIRRORING (
AUTHENTICATION = CERTIFICATE HOST_B_cert
, ENCRYPTION = REQUIRED ALGORITHM AES
, ROLE = ALL
);
GO
BACKUP CERTIFICATE HOST_B_cert TO FILE = 'C:\HOSTB\HOST_B_cert.cer';
GO

HOSTA上的证书copy到HOSTB上,HOSTB上的证书copy到HOSTA上,随后创建用户导入证书

HOSTA

 USE master;
CREATE LOGIN HOST_B_login WITH PASSWORD = '1Sample_Strong_Password!@#';
GO
CREATE USER HOST_B_user FOR LOGIN HOST_B_login;
GO
CREATE CERTIFICATE HOST_B_cert
AUTHORIZATION HOST_B_user
FROM FILE = 'C:\HOSTA\HOST_B_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_B_login];
GO

HOSTB

 USE master;
CREATE LOGIN HOST_A_login WITH PASSWORD = '=Sample#2_Strong_Password2';
GO
CREATE USER
FOR LOGIN HOST_A_login;
GO
CREATE CERTIFICATE HOST_A_cert
AUTHORIZATION HOST_A_user
FROM FILE = 'C:\HOSTB\HOST_A_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_A_login];
GO

在HOSTB上首先运行, 可以使用IP地址或者主机名

 --At HOST_B, set server instance on HOST_A as partner (principal server):
ALTER DATABASE [AdventureWorks2012]
SET PARTNER = 'TCP://192.168.100.101:7024';
GO

随后在HOSTA上运行

 --At HOST_A, set server instance on HOST_B as partner (mirror server).
ALTER DATABASE [AdventureWorks2012]
SET PARTNER = 'TCP://192.168.100.102:7024';
GO

主库上应该显示为,主体已同步,备库上显示为正在恢复。

强制关闭HOSTA,在HOSTB使用以下语句进行切换,需要等待几秒。数据库显示为主体已断开连接

 USE master;
alter database [AdventureWorks2012] set partner FORCE_SERVICE_ALLOW_DATA_LOSS;

http://msdn.microsoft.com/zh-cn/library/bb522476.aspx

此时恢复HOSTA,数据库状态为镜像,挂起/正在还原。。。在HOSTB中操作

 USE master;
alter database [AdventureWorks2012] set partner resume;

这样HOSTB 就成为了主体,假如要将HOSTA在设置为主体,在HOSTB上的运行一下语句,切换为HOSTA为主题

 USE master;
alter database [AdventureWorks2012] set partner resume;

Reference

http://msdn.microsoft.com/zh-cn/library/ms189852(v=sql.110).aspx

http://msdn.microsoft.com/zh-cn/library/ms189053.aspx

http://msdn.microsoft.com/zh-cn/library/ms189921.aspx

http://www.mssqltips.com/sqlservertip/2464/configure-sql-server-database-mirroring-using-ssms/

Configure Database Mirroring的更多相关文章

  1. Database mirroring connection error 4 'An error occurred while receiving data: '10054(An existing connection was forcibly closed by the remote host.)

    公司一SQL Server镜像发生了故障转移(主备切换),检查SQL Server镜像发生主备切换的原因,在错误日志中发现下面错误: Date        2019/8/31 14:09:17   ...

  2. T-SQL 语句创建Database的SQL mirroring关系

    1 证书部分:principle 和 secondary 端执行同样操作,更改相应name即可 USE master; --1.1 Create the database Master Key, if ...

  3. Ubuntu上配置SQL Server Always On Availability Group(Configure Always On Availability Group for SQL Server on Ubuntu)

    下面简单介绍一下如何在Ubuntu上一步一步创建一个SQL Server AG(Always On Availability Group),以及配置过程中遇到的坑的填充方法. 目前在Linux上可以搭 ...

  4. Configure Always On Availability Group for SQL Server on RHEL——Red Hat Enterprise Linux上配置SQL Server Always On Availability Group

    下面简单介绍一下如何在Red Hat Enterprise Linux上一步一步创建一个SQL Server AG(Always On Availability Group),以及配置过程中遇到的坑的 ...

  5. Configure Always On Availability Group for SQL Server on Ubuntu——Ubuntu上配置SQL Server Always On Availability Group

    下面简单介绍一下如何在Ubuntu上一步一步创建一个SQL Server AG(Always On Availability Group),以及配置过程中遇到的坑的填充方法. 目前在Linux上可以搭 ...

  6. Configure Always On Availability Group for SQL Server on Ubuntu

    下面简单介绍一下如何在Ubuntu上一步一步创建一个SQL Server AG(Always On Availability Group),以及配置过程中遇到的坑的填充方法. 目前在Linux上可以搭 ...

  7. SQL Mirroring[Hot back up with Double machine]

    Background: It's fairly common for businesses to want to provide some high availability for their SQ ...

  8. Database 2 Day DBA guide_Chapter2

    website:http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/2day_dba/install/install ...

  9. Lerning Entity Framework 6 ------ Defining the Database Structure

    There are three ways to define the database structure by Entity Framework API. They are: Attributes ...

随机推荐

  1. Android使用MVP时应该注意的问题

    生命周期:因为Presenter是View创建的,我们需要确保完全地理解View的生命周期,特别是因为它将最有可能去处理状态更新和异步数据.举个例子,每一个Presenter应该在View destr ...

  2. NSURLConnection & NSRULSession

    NSURLConnection & NSRULSession NSURLSession是NSURLConnection 的替代者,在2013年苹果全球开发者大会(WWDC2013)随ios7一 ...

  3. 重构19-Extract Factory Class(提取工厂类)

    在代码中,通常需要一些复杂的对象创建工作,以使这些对象达到一种可以使用的状态.通常情况下,这种创建不过是新建对象实例,并以我们需要的方式进行工作.但是,有时候这种创建对象的需求会极具增长,并且混淆了创 ...

  4. VMware系统运维(八)vCenter Server安装

    1.终于开始安装vCenter Server了,需要配置数据源哦! 2.下一步 3.接受协议,下一步 4.输入许可密钥,也可以后面再输入,下一步 5.选择数据源,即我们前面配置的系统DSN,下一步 6 ...

  5. NIS客户端限制用户登录

    公司所有账号信息由一台 NIS Server 统一管理,但是有几台 NIS Client 只允许某几个用户登录.这里通过PAM机制来实现该需求. 1. 需要配置的文件 (/etc/pam.d/目录下) ...

  6. java.util.concurrent.CountDownLatch

    闭锁是一种同步工具类,可以延迟线程的进度直到闭锁到达终止状态. 闭锁的作用相当于一扇门,在闭锁到达结束状态之前,这扇门一直是关闭的,任何线程都不能通过这扇门,当闭锁到达结束状态时,这扇门会打开并允许所 ...

  7. 剑指Offer20 栈的压入弹出序列是否正确

    /************************************************************************* > File Name: 20_IsPopO ...

  8. Spring操作mongo排序,限制查询记录数

    Query query = new Query(); Criteria criteria = Criteria.where("timestamp").gt(from).lt(to) ...

  9. 【JS Note】undefined与null

    在Javascript中有这两种原始类型: Undefined与Null.而这两种原始类型都各自只有一个值,分别是undefined,null. undefined: 1.变量声明后未赋值,则变量会被 ...

  10. 程序代码创建IISWEB站点

    #region 新建立一个IISWEB站点 ///<summary> ///添加一个站点 ///</summary> public string CreateWebSite() ...