search
HomeDatabaseMysql TutorialSQLServer2012数据库镜像配置完整篇

“数据库镜像”是一种提高 SQL Server 数据库的可用性的解决方案。镜像基于每个数据库实现,并且只适用于使用完整恢复模式的数据库。数据库镜像维护一个数据库的两个副本,这两个副本必须驻留在不同的 SQL Server 数据库引擎 服务器实例上。通常,这些服务器

“数据库镜像”是一种提高 SQL Server 数据库的可用性的解决方案。 镜像基于每个数据库实现,并且只适用于使用完整恢复模式的数据库。数据库镜像维护一个数据库的两个副本,这两个副本必须驻留在不同的 SQL Server 数据库引擎 服务器实例上。 通常,这些服务器实例驻留在不同位置的计算机上。 启动数据库上的数据库镜像操作时,在这些服务器实例之间形成一种关系,称为“数据库镜像会话”。其中一个服务器实例使数据库服务于客户端(“主体服务器”), 另一个服务器实例则根据镜像会话的配置和状态,充当热备用或温备用服务器(“镜像服务器”)。 具有自动故障转移功能的高安全性模式要求使用第三个服务器实例,称为“见证服务器”。

 

  • 主体服务器 (principal server)

在数据库镜像中,是指当前作为主体数据库的数据库所属于的伙伴。

  • 镜像服务器 (mirror server)

在数据库镜像配置中,镜像数据库所在的服务器实例。

  • 见证服务器 (Witness)

仅用于高安全性模式,SQL Server 的一个可选实例,它能使镜像服务器识别何时要启动自动故障转移。 与这两个故障转移伙伴不同的是,见证服务器并不能用于数据库。 见证服务器的唯一角色是支持自动故障转移。

 

 

所有数据库镜像会话都只支持一台主体服务器和一台镜像服务器。 下图显示了该配置:

 wKioL1Yu3EDydbOWAAA_vBv08J8159.gif

 

 

 

下图显示了包含见证服务器的配置:

wKioL1Yu3E-gNtOhAABEM5NwqdE502.gif

 

 

更多关于SQL数据库镜像概念请参考Technet网站,链接如下:

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

 

*****************************************************************************************************

 

整个SQL Server 2012 数据库镜像的配置分为以下6个小章节

 

  • 环境准备

  • 安装数据库功能

  • 启用TCP/IP协议和RemoteDAC

  • 数据库准备工作

  • 数据库镜像配置

  • 功能验证

 

 *****************************************************************************************

1.  环境准备

1.1   本次Demo使用的服务器清单如下:

No.

主机名

服务器角色

操作系统

IP地址

1

DC01.huangjh.com

AD/DNS

Windows Server 2012 R2

192.168.8.8/24

2

SQL01.huangjh.com

数据库服务器

(主体)

Windows Server 2012 R2

SQL Server Enterprise 2012 SP1

192.168.8.10/24

3

SQL02.huangjh.com

数据库服务器

 (镜像)

Windows Server 2012 R2

SQL Server Enterprise 2012 SP1

192.168.8.20/24

4

SQL03.huangjh.com

数据库服务器

(见证)

Windows Server 2012 R2

SQL Server Enterprise 2012 SP1

192.168.8.30/24

 

 

1.2 准备好一台域控服务器和三台数据库服务器,配置网络并加入域huangjh.com

wKioL1Yu3JXgeWOuAACA8O5LBlM915.jpg

 

1.3 三台SQL服务器需要开放1433和5022端口,为了实验方便本次Demo直接手动关闭防火墙

wKiom1Yu3HDxHvTMAAKYX5VvLwg551.jpg

 

 

2.  安装数据库功能

2.1 在SQL01、SQL02和SQL03三台数据库服务器,打开服务器管理器并根据向导完成.Net framework 3.5的安装

 

wKiom1Yu3IyjgrQgAAIgKZ6Ayr4286.jpg

 

wKioL1Yu3M7yp5dsAAFxUflsvNQ825.jpg

wKiom1Yu3KjS0sFhAAFmCK39_0E115.jpg

 2.2在SQL01、SQL02和SQL03三台数据库服务器分别插入并运行SQL Server 2012 Enterprise SP1安装程序,点击“安装”—“全新SQL Server独立安装或向现有安装添加功能”,根据向导完成SQL功能的安装

wKiom1Yu3Lnz93cOAAMAME4W5AI741.jpg

2.3 在”功能选择”页面,根据实际应用需求勾选所需的功能,下一步

wKiom1Yu3M7R_xjkAAM3hDUcvPk991.jpg

2.4 在”服务器配置”页面,修改服务账户为域账户(确保该账户密码永不过期),启动类型为”自动”

wKiom1Yu3NuzGrXuAALg1cyQW14818.jpg

2.5 根据向导在SQL01、SQL02、SQL03完成数据库功能的成功安装

wKiom1Yu3OuiTf6vAALCBM75VqU965.jpg

 

 

 

3.  启用TCP/IP协议和RemoteDAC

3.1 在SQL01、SQL02、SQL03中分别打开SQL Server配置管理器,启用TCP/IP协议

wKioL1Yu3UHRWTIdAAEtfnE0lQA923.jpg

3.2 在SQL01、SQL02、SQL03中分别打开SQL Server Management Studio,右键实例选择“方面”

wKioL1Yu3U_T5BRsAAJwl75je5E260.jpg

3.3 选择“外围应用配置器”—将属性“RemoteDACEnabled”的值改为“True”

wKioL1Yu3cuBkWiwAALXzg-o_Ps294.jpg

wKiom1Yu3UOTmpmEAALXYZD9zso804.jpg

wKiom1Yu3VKCVv2pAALt27Ig-cg921.jpg

 

 

4.  数据库准备工作(创建、备份和还原数据库)

4.1 在SQL01(主体服务器)右键”数据库”—“新建数据库”

wKiom1Yu3cqhabS3AAGMDrWNUKM161.jpg

4.2 在”常规“页面输入数据库名称

wKioL1Yu3hSTaL5tAAF5IWU_B_g063.jpg

4.3 在”选项”页面确保恢复模式为”完整“

wKiom1Yu3fOSq8O-AAH20izNdbk028.jpg

4.4 右键”DB01”选择”任务“—”备份“

wKioL1Yu3jWBFnHbAALNxmw1Ckg872.jpg

4.5 备份类型选择”完整“,点击”确定“

wKioL1Yu3mKTl8fGAAGrsiEOoDk293.jpg

4.6 备份成功完成后点击”确定“

wKiom1Yu3kCgZXvSAABf-S4c04s167.jpg

4.7 选择备份类型为”事务日志“,点击”确定“完成对事务日志的备份

wKioL1Yu3oCiqaLxAAGyTTcaZRA708.jpg

4.8 将备份文件拷贝到镜像服务器SQL02.huangjh.com对应的路径,默认备份路径为

“C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup”

wKiom1Yu3lnQoV97AAEYwJvuSvg735.jpg

4.9 在镜像服务器SQL02.huangjh.com打开SQL Server Management Studio,右键“数据库”选择“创建数据库”

wKiom1Yu3mfBnfutAAF-GeapmH8786.jpg

4.10 输入数据库名称,点击“确定”(此数据库名称必须与SQL01中创建的数据库名称保持一致)

wKioL1Yu3qbhrDgrAAFi_cr1R5E201.jpg

 4.11 右键新创建的数据库“DB01”--选择“任务”—“还原”—“数据库”

wKiom1Yu3oLCj_A_AAL_ESKfYKo335.jpg

4.12 选择“设备”,点击右边“…”

wKioL1Yu3sqhbUIpAAHMH3uS0w4408.jpg

4.13 点击”添加”

wKioL1Yu3t3BQje3AAChqkUtgkc648.jpg

4.14 选择刚才从SQL01复制的备份文件,点击”确定”

wKioL1Yu3uuxu1i1AAE02Uo4BSM649.jpg

4.15 点击“确定”

wKiom1Yu3texa8kOAADSFMHh6Ng274.jpg

4.16 勾选要还原的备份集

wKiom1Yu3unQewCIAAKXRN1Db_4498.jpg

 4.17 在“选项”页面勾选“覆盖现有数据库”,恢复状态选择“RESTORE WITH NORECOVERY”,取消勾选“还原前进行结尾日志备份”,点击“确定”

wKioL1Yu3yrQYdu5AALXsaHblW4684.jpg

4.18 点击“确定”

wKiom1Yu3wmQg3APAABURuH5LAs550.jpg

4.19 数据库DB01显示”正在还原…“

wKioL1Yu30ezh94qAAFbKvtSss8511.jpg

 

 

 

5.  数据库镜像配置

5.1 在主体服务器SQL01.huangjh.com右键“DB01”选择“任务”—“镜像”

wKioL1Yu31fDh9O1AALFggX9LPg294.jpg

5.2 点击“配置安全性”

wKioL1Yu32rAsWcaAAID-hPJxYQ490.jpg

5.3 下一步

wKiom1Yu30PRk6XqAAE_qocsYCQ400.jpg

5.4 选择“是”,下一步

wKioL1Yu34TQbU4qAAEHnteWo7s830.jpg

5.5 勾选“见证服务器实例”,下一步

wKiom1Yu31_RtvWiAAF2h6VvClI346.jpg

5.6 下一步

wKiom1Yu337SnzWxAAFbOHzKkW8902.jpg

5.7 点击“浏览更多”

wKioL1Yu37yyLbBhAAGdofALICc583.jpg

5.8 输入镜像服务器名称SQL02,点击”连接”

wKioL1Yu38expByUAADolLSkgeA897.jpg

 5.9 选择镜像服务器实例SQL02,下一步

wKiom1Yu35-w2tUSAAFQtSJythc625.jpg

5.10 同样选择见证服务器实例SQL03,下一步

wKiom1Yu36uhSrbiAAFfTFbiF6M209.jpg

5.11 输入实例服务账户huangjh\administrator,下一步

wKioL1Yu3-mS9qYFAAFN-CeuS3s200.jpg

5.12 点击“完成”

wKiom1Yu38KzS92jAAF9F0yh2Qo523.jpg

5.13 成功配置后,点击”关闭”

wKioL1Yu3__j3PLfAAEOa_nlXqE113.jpg

5.14 点击“开始镜像”

wKioL1Yu4AzwvvFSAAEg2gLlGOM670.jpg

 

5.15 状态为“已同步:数据库已完全同步”,点击“确定”

wKioL1Yu4BnCq0LNAAEg2gLlGOM158.jpg

5.16 在主体服务器SQL01看到的数据库状态为”主体,正在同步”

wKioL1Yu4DbQqz2bAAGd57xdvjQ035.jpg

5.17 在镜像服务器SQL02看到的数据库状态为”正在还原…”

wKioL1Yu4EGQLgtgAAGdXtYsyJE144.jpg

 

 

 

 

6.  功能验证

6.1 在主体服务器SQL01右键数据库“DB01”选择“任务”—“启动数据库镜像监视器”

wKioL1Yu4E3Qr46VAAQWhBMx7GM063.jpg

6.2 在此页面可看到数据库镜像的同步状态等

wKioL1Yu4Kji6LCiAAIE4bVpBsU584.jpg

6.3在主体服务器SQL01右键数据库“DB01”选择“属性”

wKiom1Yu4IbAjJJ2AAIeVEgkYI8538.jpg

6.4 在选择页“镜像”点击“故障转移”

wKioL1Yu4MSxMOPaAAIyi4HfMlQ181.jpg

 

6.5 点击“是”

wKioL1Yu4M_RfTjrAADVlJYnWdY771.jpg

6.6 此时主体服务器为SQL02,镜像服务器SQL01,说明手动故障转移成功

wKioL1Yu4N-zvhuAAAIkcoeZJ-w707.jpg

 

6.7 将SQL02(此时的主体服务器)关机,此时自动将主体故障转移到SQL01中

wKiom1Yu4LqxS-AuAAJ0SAqyHGw658.jpg

6.8 此时又回到了原先的主体服务器SQL01,镜像服务器SQL02,状态为”没有连接:无法连接镜像服务器实例或见证服务器实例”

wKioL1Yu4PmD-DuBAAI96b-LqeI963.jpg

6.9 将SQL02开机后恢复正常后,状态为”已同步:数据库已完全同步”,说明自动故障转移成功。

wKiom1Yu4NTjdmdlAAIpx7oq6Ow720.jpg

 

~~~以上是整个SQL Server 2012 数据库镜像配置的分享~~~

 

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the role of InnoDB redo logs and undo logs.Explain the role of InnoDB redo logs and undo logs.Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?Apr 15, 2025 am 12:15 AM

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

What is the Using temporary status in EXPLAIN and how to avoid it?What is the Using temporary status in EXPLAIN and how to avoid it?Apr 15, 2025 am 12:14 AM

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Apr 15, 2025 am 12:11 AM

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL vs. Other Databases: Comparing the OptionsMySQL vs. Other Databases: Comparing the OptionsApr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

How does MySQL index cardinality affect query performance?How does MySQL index cardinality affect query performance?Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL: Resources and Tutorials for New UsersMySQL: Resources and Tutorials for New UsersApr 14, 2025 am 12:16 AM

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

Real-World MySQL: Examples and Use CasesReal-World MySQL: Examples and Use CasesApr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool