SQL Server HA - 数据库镜像2 (Mirroring)(1418错误解决)
SQL Server2008數(shù)據(jù)庫(kù)鏡像的配置 (1418錯(cuò)誤解決)
準(zhǔn)備三臺(tái)安裝SQL的服務(wù)器,三臺(tái)中兩臺(tái)擔(dān)當(dāng)驚喜數(shù)據(jù)庫(kù),一天當(dāng)作監(jiān)控服務(wù)器
在要做鏡像的數(shù)據(jù)庫(kù)之上右鍵單擊,選擇備份
備份類(lèi)型為完整,注意記錄備份路徑
重復(fù)以上操作,此次備份類(lèi)型為事務(wù)日志
將剛剛備份的文件拷貝到另外一臺(tái)備份的數(shù)據(jù)庫(kù)內(nèi)
右鍵數(shù)據(jù)庫(kù),選擇恢復(fù)數(shù)據(jù)庫(kù)
選擇源設(shè)備
選擇完整備份的數(shù)據(jù)庫(kù)
單擊確定
勾選剛剛恢復(fù)的數(shù)據(jù)庫(kù)
點(diǎn)擊選項(xiàng),勾選不對(duì)數(shù)據(jù)庫(kù)執(zhí)行任何操作
右鍵選擇剛剛恢復(fù)的數(shù)據(jù)庫(kù),選擇還原任務(wù)日志
勾選從磁盤(pán)恢復(fù),選擇對(duì)應(yīng)的文件
同樣選擇不對(duì)數(shù)據(jù)庫(kù)執(zhí)行任何操作
可看到正在同步和還原
右鍵剛剛的數(shù)據(jù)庫(kù)選擇鏡像
點(diǎn)擊配置安全
勾選使用見(jiàn)證服務(wù)器
主服務(wù)器
選擇鏡像服務(wù)器
選擇見(jiàn)證服務(wù)器
設(shè)置服務(wù)器連接用戶名
設(shè)置服務(wù)器連接用戶名(注意:此處必須指定SQLServer服務(wù)啟動(dòng)的賬號(hào))
這個(gè)是引起1418錯(cuò)誤的原因,由于沒(méi)有
?? ???GRANT CONNECT on ENDPOINT::Mirroring TO [Domain\_TPSQLAccount];
Mirroring server network address cannotbe reached or ?does not exist
點(diǎn)擊完成結(jié)束
點(diǎn)擊開(kāi)始驚喜
鏡像結(jié)束
[TroubleShooting] The servernetwork address can not be reached or does not exist:
http://blog.csdn.net/wzhiu/article/details/24774987
Backtround:
I'm trying to set upmirroring between two sql 2008 R2?databases on different servers in myinternal network, as a test run before doing the same thing with two liveservers in different locations.
When I actually try and switch the mirroring on the target DB (with
ALTER DATABASE xxxdb SET PARTNER = TCP://myserverAddress:50221') I'm getting anerror telling me that the server network address can not be reached or does notexist. A little research suggests this is a fairly unhelpful message that popsup due to a number of possible causes, some of which are not directly relatedto the server existing or otherwise.
In fact, this is error isnot clear for us.Checking the log, I'mseeing the following errors.?"Database mirroringconnection error 5 'Connection handshake failed. The certificate used by thepeer is invalid due to the following reason: Certificate not found. State 89.'for 'TCP://myserverAddress:50221'." in event viewer(eventvwr).
Solution:
You can?manual copyingthe certificates around(Principal, Mirror and Witness). and drop login, user.and then create login, user with certificate responsed. Last, Grant connectendpoint.
CREATE LOGIN HOST_pro_login WITH PASSWORD ='Password01!'; CREATE USER HOST_pro_user FOR LOGIN HOST_pro_login; -- drop CERTIFICATE HOST_pro_cert CREATE CERTIFICATE HOST_pro_cert AUTHORIZATION HOST_pro_user ?FROM FILE ='D:\Hot backup\HOST_pro_cert.cer'; GRANT ?CONNECT ON ENDPOINT::Endpoint_Mirroring TO [HOST_pro_login]; |
CREATE?LOGIN?HOST_pro_login?WITH?PASSWORD?='Password01!';CREATE?USER?HOST_pro_user?FOR?LOGIN?HOST_pro_login;--?drop?CERTIFICATE?HOST_pro_certCREATE?CERTIFICATE?HOST_pro_cert?AUTHORIZATION?HOST_pro_user?FROM?FILE?='D:\Hot?backup\HOST_pro_cert.cer';GRANT?CONNECT?ON?ENDPOINT::Endpoint_Mirroring?TO?[HOST_pro_login];
?OtherSuggestions:
Thesolution to the above problem is very simple and as follows.
Fix/WorkAround/Solution:Tryall the suggestions one by one.
Suggestion1:Make sure that on Mirror Server the database is restored with NO RECOVERYoption (This is the most common problem).
Suggestion2:Make sure that from Principal the latest LOG backup is restored to mirrorserver. (Attempt this one more time even though the full backup has beenrestored recently).
-- Back up 1: GO BACKUP DATABASE ?[dbName] TO? DISK = N'D:\Hot ?backup\testbackup01.bak' WITH NOFORMAT, NOINIT,? NAME = N'TestBackup01-Full Database ?Backup', SKIP, NOREWIND, NOUNLOAD,? ?STATS = 10 GO ? BACKUP LOG [dbName] ?TO? DISK = N'D:\Hot ?backup\TestBackup01.trn' WITH NOFORMAT, NOINIT,? NAME = N'TestBackup01-Transaction Log? Backup', SKIP, NOREWIND, NOUNLOAD,? STATS = 10 GO -- Restore 1: RESTORE DATABASE ?dbName ?FROM DISK = 'D:\Hot backup\dbName.bak' ?WITH FILE = 1, MOVE 'dbName' TO ?'C:\Program Files\Microsoft SQL ?Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\dbName.mdf', MOVE 'dbName_log' TO ?'C:\Program Files\Microsoft SQL ?Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\dbName_log.ldf', NORECOVERY, ?NOUNLOAD, REPLACE, STATS = 10 GO ? -- Restore 2: RESTORE DATABASE ?dbName FROM DISK = 'D:\Hot backup\backup_TestBackup01.bak' WITH FILE = 1, ?NORECOVERY, NOUNLOAD; RESTORE LOG dbName ?FROM DISK = 'D:\Hot backup\backup_TestBackup01.trn' WITH NORECOVERY |
--?Restore?2:RESTORE?DATABASE?dbName?FROM?DISK?=?'D:\Hot?backup\backup_TestBackup01.bak'?WITH?FILE?=?1,?NORECOVERY,?NOUNLOAD;RESTORE?LOG?dbName?FROM?DISK?=?'D:\Hot?backup\backup_TestBackup01.trn'?WITH?NORECOVERY
Suggestion3:Check if you can telnet to your ports using command TELNET ServerName Portslike “telnet SQLServerName 50221″.(Please add feature lelnet client|Server inserver?2k8, if it not exsit.)
Suggestion4:Make sure your firewall is turned off.
Suggestion5:Verify that the endpoints are started on the partners by using thestate or state_desc column the ofthe sys.database_mirroring_endpointscatalog view. You can start end point by executing an ALTER ENDPOINT statement.
Suggestion6:Try the following command as one of the last options.
GRANTCONNECT ON ENDPOINT::Mirroring TO ALL
Suggestion7:Delete the end points and recreate them.
Suggestion8: CheckSQL log.
Ifany of above solutions does not fix your problem, do leave comment here. Basedon the comment, I will update this article with additional suggestions.
Pleasenote that some of the above suggestions can be security threat to your system.Please use them responsibly and review your system with security expert in yourcompany.
?
?SQL SERVER 2008 數(shù)據(jù)庫(kù)鏡像動(dòng)手實(shí)驗(yàn)筆記
----判斷數(shù)據(jù)庫(kù)是否正在被使用,如果被使用中,那么中止使用數(shù)據(jù)庫(kù)的進(jìn)程
IF EXISTS(SELECT * FROM sys.sysprocesses WHEREdbid=DB_ID(N'SampleData'))
?? BEGIN
???? DECLARE @sNVARCHAR(1000)
???? DECLARE myCurCURSOR FOR?
??? ?SELECT 'kill '+CAST(spid AS VARCHAR) FROMsys.sysprocesses WHERE dbid=DB_ID(N'SampleData')
???? OPEN myCur
???? FETCH NEXT FROMmyCur INTO @s
???? WHILE@@FETCH_STATUS =0
???? BEGIN
?????? EXEC(@S)
?????? FETCH NEXT FROMmyCur INTO @s
???? END
???? CLOSE myCur
???? DEALLOCATEmyCur????
?? END?????
???
----新建數(shù)據(jù)庫(kù)
IF EXISTS(SELECT * FROM sys.sysdatabases WHERE dbid=db_id(N'SampleData'))
DROP DATABASE SampleData???
---IF DB_ID(N'SampleData') IS NOT NULL??
---?? DROP DATABASESampleData??
CREATE DATABASE SampleData ON PRIMARY?
? (NAME=N'SampleData',FILENAME=N'E:\Sample\SampleData.MDF',SIZE=10MB,MAXSIZE=UNLIMITED,FILEGROWTH=10%),??
? FILEGROUP FG1DEFAULT?
?(NAME=N'SampleData_01',FILENAME=N'E:\Sample\SampleData_01.ndf',SIZE=10MB,MAXSIZE=UNLIMITED,FILEGROWTH=10%),??
?(NAME=N'SampleData_02',FILENAME=N'E:\Sample\SampleData_02.ndf',SIZE=10MB,MAXSIZE=UNLIMITED,FILEGROWTH=10%)
? LOG ON?
?(NAME=N'SampleData_Log',FILENAME=N'E:\Sample\SampleData_Log.ldf',SIZE=10MB,MAXSIZE=UNLIMITED,FILEGROWTH=10%)??
? COLLATEChinese_PRC_CI_AS??
GO??
?
----將數(shù)據(jù)庫(kù)的恢復(fù)模式設(shè)定為【FULL】
IF NOT EXISTS(SELECT recovery_model FROM sys.databases WHEREdatabase_id =DB_ID(N'SampleData') AND recovery_model=1)
?? ALTER DATABASESampleData SET RECOVERY FULL
?
----在數(shù)據(jù)庫(kù)中新建表[TestTable],并添加測(cè)試數(shù)據(jù)??
USE SampleData?
IF EXISTS(SELECT * FROM sys.objects WHERE object_id=OBJECT_ID(N'dbo.TestTable') AND type IN (N'U'))
DROP TABLE dbo.TestTable
CREATE TABLE dbo.TestTable
(ID?????? INT?????????????????? IDENTITY(1,1),
?Column1? VARCHAR(50)??NOT NULL,
?CONSTRAINTpk_testtableID PRIMARY KEY(ID))
?GO
?
INSERT INTO dbo.TestTable(Column1) VALUES('ROWA')
INSERT INTO dbo.TestTable(Column1) VALUES('ROWB')
INSERT INTO dbo.TestTable(Column1) VALUES('ROWC')
INSERT INTO dbo.TestTable(Column1) VALUES('ROWD')
INSERT INTO dbo.TestTable(Column1) VALUES('ROWE')
?
----完整備份數(shù)據(jù)庫(kù)
BACKUP DATABASE [SampleData] TO? DISK = N'E:\SampleBack\SampleDataAllback.bak'WITH NOFORMAT, NOINIT,? NAME =N'SampleData-完整數(shù)據(jù)庫(kù)備份', SKIP, NOREWIND, NOUNLOAD,? STATS = 10
----事務(wù)日志備份(截?cái)嗳罩?#xff09;
BACKUP LOG [SampleData] TO?DISK = N'E:\SampleBack\SampleDataLogBack.bak' WITH NOFORMAT,NOINIT,? NAME = N'SampleData-事務(wù)日志備份', SKIP, NOREWIND, NOUNLOAD,? STATS = 10
?
----在輔助數(shù)據(jù)庫(kù)服務(wù)器上執(zhí)行還原
------還原完整備份
--------RESTORE DATABASE [SampleData] FROM? DISK = N'E:\SampleBack\SampleDataAllback.bak'WITH? FILE = 1,? MOVE N'SampleData_01' TON'E:\Sample\SampleData_1.ndf',? MOVEN'SampleData_02' TO N'E:\Sample\SampleData_2.ndf',? MOVE N'SampleData_Log' TON'E:\Sample\SampleData_3.ldf',?NORECOVERY,? NOUNLOAD,? STATS = 10
--------GO
------還原事務(wù)日志備份
--------RESTORE LOG [SampleData] FROM? DISK = N'E:\SampleBack\SampleDataLogBack.bak'WITH? FILE = 1, NORECOVERY,NOUNLOAD,? STATS = 10
?
----說(shuō)明:數(shù)據(jù)庫(kù)鏡像的兩種身份驗(yàn)證方式:證書(shū)和Windows身份驗(yàn)證
?
----使用基于證書(shū)的身份驗(yàn)證方式設(shè)置數(shù)據(jù)庫(kù)鏡像
-------第一步:配置[出站連接]
---------配置主機(jī)服務(wù)器的出站連接
------------在master數(shù)據(jù)庫(kù)中創(chuàng)建數(shù)據(jù)庫(kù)主密鑰
USE master?
CREATE MASTER KEY ENCRYPTION BY PASSWORD='hdf007@163.com'
------------為主機(jī)服務(wù)器數(shù)據(jù)庫(kù)實(shí)例制作一個(gè)證書(shū)
USE master?
CREATE CERTIFICATE HOST_A_Cert WITH SUBJECT='HOST_Acertificate'
------------使用該證書(shū)為主機(jī)服務(wù)器數(shù)據(jù)庫(kù)實(shí)例創(chuàng)建一個(gè)鏡像端口
CREATE ENDPOINT Endpoint_Mirroring
STATE=STARTED?
AS TCP (LISTENER_PORT=7024,LISTENER_IP=ALL)
FOR DATABASE_MIRRORING (AUTHENTICATION=CERTIFICATE HOST_A_Cert,ENCRYPTION=REQUIREDALGORITHM AES,ROLE=ALL)
------------備份HOST_A證書(shū),并將其復(fù)制到輔助服務(wù)器、見(jiàn)證服務(wù)器
BACKUP CERTIFICATE HOST_A_Cert TO FILE='C:\HOST_A_Cert.cer'
?
---------配置輔助服務(wù)器的出站連接
------------在master數(shù)據(jù)庫(kù)中創(chuàng)建數(shù)據(jù)庫(kù)主密鑰
USE master?
CREATE MASTER KEY ENCRYPTION BY PASSWORD='hdf007@163.com'
------------為輔助服務(wù)器數(shù)據(jù)庫(kù)實(shí)例制作一個(gè)證書(shū)
USE master?
CREATE CERTIFICATE HOST_B_Cert WITH SUBJECT='HOST_Bcertificate'
------------使用該證書(shū)為輔助服務(wù)器數(shù)據(jù)庫(kù)實(shí)例創(chuàng)建一個(gè)鏡像端口
CREATE ENDPOINT Endpoint_Mirroring
STATE=STARTED?
AS TCP (LISTENER_PORT=7024,LISTENER_IP=ALL)
FOR DATABASE_MIRRORING (AUTHENTICATION=CERTIFICATEHOST_B_Cert,ENCRYPTION=REQUIRED ALGORITHM AES,ROLE=ALL)
------------備份HOST_B證書(shū),并將其復(fù)制到主機(jī)服務(wù)器、見(jiàn)證服務(wù)器
BACKUP CERTIFICATE HOST_B_Cert TO FILE='C:\HOST_B_Cert.cer'
?
----------配置見(jiàn)證服務(wù)器的出站連接
USE master?
CREATE MASTER KEY ENCRYPTION BY PASSWORD='hdf007@163.com'
---------為見(jiàn)證服務(wù)器數(shù)據(jù)庫(kù)實(shí)例制作一個(gè)證書(shū)
USE master?
CREATE CERTIFICATE HOST_C_Cert WITHSUBJECT='HOST_C_certificate'
---------使用該證書(shū)為見(jiàn)證服務(wù)器數(shù)據(jù)庫(kù)實(shí)例創(chuàng)建一個(gè)鏡像端口
CREATE ENDPOINT Endpoint_Mirroring
STATE=STARTED
AS TCP (LISTENER_PORT=7024,LISTENER_IP=ALL)
FOR DATABASE_MIRRORING (AUTHENTICATION=CERTIFICATEHOST_C_Cert,ENCRYPTION=REQUIRED ALGORITHM AES,ROLE=ALL)
---------備份HOST_C證書(shū),并將其復(fù)制到主機(jī)服務(wù)器、輔助服務(wù)器
BACKUP CERTIFICATE HOST_C_Cert TO FILE='C:\HOST_C_Cert.cer'
?
-------第二步:配置[入站連接]
---------配置主機(jī)服務(wù)器的入站連接
------------在主機(jī)服務(wù)器上為鏡像服務(wù)器創(chuàng)建一個(gè)登錄名
USE master?
CREATE LOGIN HOST_B_Login WITH PASSWORD='hdf007@163.com'
------------創(chuàng)建一個(gè)該登錄名的用戶
CREATE USER HOST_B_User FROM LOGIN HOST_B_Login?
------------使用從鏡像服務(wù)器復(fù)制過(guò)來(lái)的證書(shū)與此用戶關(guān)聯(lián)
CREATE CERTIFICATE HOST_B_Cert AUTHORIZATION HOST_B_UserFROM FILE='C:\HOST_B_Cert.cer'
------------授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的 CONNECT 權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO[HOST_B_Login]
------------在主機(jī)服務(wù)器上為見(jiàn)證服務(wù)器創(chuàng)建一個(gè)登錄名
USE master?
CREATE LOGIN HOST_C_Login WITH PASSWORD='hdf007@163.com'
------------創(chuàng)建一個(gè)該登錄名的用戶
CREATE USER HOST_C_User FROM LOGIN HOST_C_Login?
------------使用從見(jiàn)證服務(wù)器復(fù)制過(guò)來(lái)的證書(shū)與此用戶關(guān)聯(lián)
CREATE CERTIFICATE HOST_C_Cert AUTHORIZATION HOST_C_UserFROM FILE='C:\HOST_C_Cert.cer'
------------授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的CONNECT權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO[HOST_C_Login]
?
---------配置輔助服務(wù)器的入站連接
------------在輔助服務(wù)器上為主機(jī)服務(wù)器創(chuàng)建一個(gè)登錄名
USE master?
CREATE LOGIN HOST_A_Login WITH PASSWORD='hdf007@163.com'
------------創(chuàng)建一個(gè)該登錄名的用戶
CREATE USER HOST_A_User FROM LOGIN HOST_A_Login?
------------使用從主機(jī)服務(wù)器復(fù)制過(guò)來(lái)的證書(shū)與此用戶關(guān)聯(lián)
CREATE CERTIFICATE HOST_A_Cert AUTHORIZATION HOST_A_UserFROM FILE='C:\HOST_A_Cert.cer'
------------授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的 CONNECT 權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO[HOST_A_Login]
------------在輔助服務(wù)器上為見(jiàn)證服務(wù)器創(chuàng)建一個(gè)登錄名
USE master?
CREATE LOGIN HOST_C_Login WITH PASSWORD='hdf007@163.com'
------------創(chuàng)建一個(gè)該登錄名的用戶
CREATE USER HOST_C_User FROM LOGIN HOST_C_Login?
------------使用從見(jiàn)證服務(wù)器復(fù)制過(guò)來(lái)的證書(shū)與此用戶關(guān)聯(lián)
CREATE CERTIFICATE HOST_C_Cert AUTHORIZATION HOST_C_UserFROM FILE='C:\HOST_C_Cert.cer'
------------授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的CONNECT權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO[HOST_C_Login]
?
---------配置見(jiàn)證服務(wù)器的入站連接
------------在見(jiàn)證服務(wù)器上為主機(jī)服務(wù)器創(chuàng)建一個(gè)登錄名
USE master?
CREATE LOGIN HOST_A_Login WITH PASSWORD='hdf007@163.com'
------------創(chuàng)建一個(gè)該登錄名的用戶
CREATE USER HOST_A_User FROM LOGIN HOST_A_Login?
------------使用從主機(jī)服務(wù)器復(fù)制過(guò)來(lái)的證書(shū)與此用戶關(guān)聯(lián)
CREATE CERTIFICATE HOST_A_Cert AUTHORIZATION HOST_A_UserFROM FILE='C:\HOST_A_Cert.cer'
------------授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的 CONNECT 權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO[HOST_A_Login]
------------在見(jiàn)證服務(wù)器上為輔助服務(wù)器創(chuàng)建一個(gè)登錄名
USE master?
CREATE LOGIN HOST_B_Login WITH PASSWORD='hdf007@163.com'
------------創(chuàng)建一個(gè)該登錄名的用戶
CREATE USER HOST_B_User FROM LOGIN HOST_B_Login?
------------使用從見(jiàn)證服務(wù)器復(fù)制過(guò)來(lái)的證書(shū)與此用戶關(guān)聯(lián)
CREATE CERTIFICATE HOST_B_Cert AUTHORIZATION HOST_B_UserFROM FILE='C:\HOST_B_Cert.cer'
------------授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的CONNECT權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO[HOST_B_Login]
?
-------第三步:配置鏡像伙伴
---------在鏡像服務(wù)器上將主機(jī)服務(wù)器設(shè)置為伙伴
ALTER DATABASE SampleData SET PARTNER='TCP://S1:7024'
---------在主機(jī)服務(wù)器上將鏡像服務(wù)器設(shè)置為伙伴
ALTER DATABASE SampleData SET PARTNER='TCP://S2:7024'
---------在主機(jī)服務(wù)器上設(shè)置見(jiàn)證服務(wù)器
ALTER DATABASE SampleData SET WITNESS='TCP://S2:7024'
GO
?
-----以下代碼是在沒(méi)有見(jiàn)證服務(wù)器的情況下實(shí)現(xiàn)手動(dòng)故障轉(zhuǎn)移
---------若要在高性能模式下配置此會(huì)話,在主體服務(wù)器實(shí)例上,將事務(wù)安全性設(shè)置為 OFF。
ALTER DATABASE SampleData SET PARTNER SAFETY OFF
---------若要在高安全模式下配置些會(huì)話,在主體服務(wù)器實(shí)例上,將事務(wù)安全性設(shè)置為FULL
ALTER DATABASE SampleData SET PARTNER SAFETY FULL
?
---------在高性能模式下,使用下列語(yǔ)句在鏡像服務(wù)器上強(qiáng)制執(zhí)行實(shí)現(xiàn)故障轉(zhuǎn)移,會(huì)丟失數(shù)據(jù)
ALTER DATABASE SampleData SET PARTNERFORCE_SERVICE_ALLOW_DATA_LOSS
---------在高安全模式下,使用下列語(yǔ)句實(shí)現(xiàn)手工故障轉(zhuǎn)移
ALTER DATABASE SampleData SET PARTNER FAILOVER
?
---------原來(lái)的主服務(wù)器恢復(fù),可以繼續(xù)工作,需要重新設(shè)定鏡像
---------在輔助服務(wù)器上執(zhí)行:
USE master
ALTER DATABASE SampleData SET PARTNER RESUME? --恢復(fù)鏡像
ALTER DATABASE SampleData SET PARTNER FAILOVER --切換主備
?
?
?
----使用基于Windows的身份驗(yàn)證方式設(shè)置數(shù)據(jù)庫(kù)鏡像
------------------------------------------------------------
-- 主機(jī)服務(wù)器??????????????S1????????? ??????S1\S1User?? --
-- 輔助服務(wù)器??????????????S2??????????????? S2\S2User?? --
-- 見(jiàn)證服務(wù)器??????????????S3??????????????? S3\S3User?? --
------------------------------------------------------------
---在主機(jī)服務(wù)器上創(chuàng)建一個(gè)鏡像端點(diǎn)
CREATE ENDPOINT Endpoint_Mirroring STATE=STARTED AS TCP(LISTENER_PORT=7024) FOR DATABASE_MIRRORING (ROLE=ALL)
---在主機(jī)服務(wù)器上為輔助服務(wù)器創(chuàng)建一個(gè)登錄
CREATE LOGIN [S2\S2User] FROM WINDOWS
---授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的CONNECT權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [S2\S2User]
---在主機(jī)服務(wù)器上為見(jiàn)證服務(wù)器創(chuàng)建一個(gè)登錄
CREATE LOGIN [S3\S3User] FROM WINDOWS
---授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的CONNECT權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [S3\S3User]
?
---在輔助服務(wù)器上創(chuàng)建一個(gè)鏡像端點(diǎn)
CREATE ENDPOINT Endpoint_Mirroring STATE=STARTED AS TCP(LISTENER_PORT=7024) FOR DATABASE_MIRRORING (ROLE=ALL)
---在輔助服務(wù)器上為主機(jī)服務(wù)器創(chuàng)建一個(gè)登錄
CREATE LOGIN [S1\S2User] FROM WINDOWS
---授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的CONNECT權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [S1\S2User]
---在輔助服務(wù)器上為見(jiàn)證服務(wù)器創(chuàng)建一個(gè)登錄
CREATE LOGIN [S3\S3User] FROM WINDOWS
---授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的CONNECT權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [S3\S3User]
?
---在見(jiàn)證服務(wù)器上創(chuàng)建一個(gè)鏡像端點(diǎn)
CREATE ENDPOINT Endpoint_Mirroring STATE=STARTED AS TCP(LISTENER_PORT=7024) FOR DATABASE_MIRRORING (ROLE=ALL)
---在見(jiàn)證服務(wù)器上為主機(jī)服務(wù)器創(chuàng)建一個(gè)登錄
CREATE LOGIN [S1\S1User] FROM WINDOWS
---授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的CONNECT權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [S1\S1User]
---在見(jiàn)證服務(wù)器上為輔助服務(wù)器創(chuàng)建一個(gè)登錄
CREATE LOGIN [S2\S2User] FROM WINDOWS
---授予對(duì)遠(yuǎn)程鏡像端點(diǎn)的登錄名的CONNECT權(quán)限
GRANT CONNECT ON ENDPOINT::Endpoint_Mirroring TO [S2\S2User]
?
----配置鏡像伙伴
---------在鏡像服務(wù)器上將主機(jī)服務(wù)器設(shè)置為伙伴
ALTER DATABASE SampleData SET PARTNER='TCP://S1:7024'
---------在主機(jī)服務(wù)器上將鏡像服務(wù)器設(shè)置為伙伴
ALTER DATABASE SampleData SET PARTNER='TCP://S2:7024'
---------在主機(jī)服務(wù)器上設(shè)置見(jiàn)證服務(wù)器
ALTER DATABASE SampleData SET WITNESS='TCP://S2:7024'
?
將客戶端連接到數(shù)據(jù)庫(kù)鏡像會(huì)話 (SQL Server)
Failover Partner 屬性
除了初始伙伴名稱(chēng)以外,客戶端還可以指定應(yīng)標(biāo)識(shí)當(dāng)前鏡像服務(wù)器實(shí)例的故障轉(zhuǎn)移伙伴名稱(chēng)。 故障轉(zhuǎn)移伙伴是由 failover partner 屬性的某個(gè)關(guān)鍵字指定的。 具體由該屬性的哪個(gè)關(guān)鍵字指定取決于您所使用的 API。 下表列出了這些關(guān)鍵字:
| OLE DB 訪問(wèn)接口 | FailoverPartner |
| ODBC 驅(qū)動(dòng)程序 | Failover_Partner |
| ActiveX 數(shù)據(jù)對(duì)象 (ADO) | Failover Partner |
標(biāo)識(shí)服務(wù)器實(shí)例的最簡(jiǎn)單方法是指定其名稱(chēng) <server_name>[\<SQL_Server_instance_name>]。
連接字符串示例
例如,為了使用 TCP/IP 顯式連接到 Partner_A 或 Partner_B 上的 AdventureWorks 數(shù)據(jù)庫(kù),使用 ODBC 驅(qū)動(dòng)程序的客戶端應(yīng)用程序可能會(huì)提供以下連接字符串:
另外,客戶端還可以使用 IP 地址和端口號(hào)標(biāo)識(shí)初始伙伴 Partner_A;例如,如果 IP 地址為 250.65.43.21,端口號(hào)為 4734,則連接字符串將為:
參考:
http://liulike.blog.51cto.com/1355103/339183/
http://hdf007.blog.51cto.com/42396/824297
http://jingyan.baidu.com/article/3c343ff70c10e10d37796389.html
https://technet.microsoft.com/zh-cn/library/ms175484.aspx?
轉(zhuǎn)載于:https://blog.51cto.com/57388/1851107
總結(jié)
以上是生活随笔為你收集整理的SQL Server HA - 数据库镜像2 (Mirroring)(1418错误解决)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Java异常处理终结篇——如何进行Jav
- 下一篇: hbase源码系列(五)Trie单词查找