tutorial mirroring

3
Type to search the Web Home Lotus Show EF 100 Macro Talk about success How to test camera Good Words Photos My Ferrari Flash Exploded Dirt Colin McRae SQL 2005 Database Mirroring Tutorial Glory Road [movie] Electric Car SQL 2005 Database Mirroring Tutorial Introduction This tutorial is for people who are really really frustrated. One of my project need to use mirroring to replicate data between 2 database servers. I look for help online and found some useful websites. However, when I follow the instructions, some error messages stop me..... Most likely, you would get this error message: Error: 1418 - Microsoft SQL Server - The server network address can not be reached or does not exist. Check the network address name and reissue the command. The server network endpoint did not respond because the specified server network address cannot be reached or does not exist. That error message dosen't tell you the truth.... there is nothing to do with "can not be reached or does not exist". There are 2 possible causes: - You forgot to use "NO RECOVERY" when restoring database on the MIRROR server - NT Authentication fail.... some unknow reason... a lot of people reported this problem When you view the SQL Server Log, you would see some error message like : Error: 1474, Severity: 16, State: 1 Database mirroring connection error 4 'An error occurred while receiving data: '10054(An existing connection was forcibly closed by the remote host.)'.' for 'TCP://mymirror.mydomain:5022' or Error: 1443, Severity: 16, State: 2 or Database Mirroring login attempt by user 'NT AUTHORITY\ANONYMOUS LOGON.' failed with error: 'Connection handshake failed. The login 'NT AUTHORITY\ANONYMOUS LOGON' does not have CONNECT permission on the endpoint. State 84. Well, if you are having the above error messages, I hope this tutorial could help you. Solution: Using Certificates Forget about Windows Authentication or Domain Account..... just use Certificates is good enough. What you need is: - 2 Servers and 1 Witness - Create a database on Principal Server - Backup the database 2 times: 1st time do a "FULL" backup, 2nd time do a "Transaction Log" backup - Restore the database on Mirror Server, MUST use option "NO RECOVERY" !!! After restore, the mirror database will not take any request, that is completely normal. - Fully Qualified Domain Name for all 3 servers..... you can do this by: 1. Setup a domain, or 2. Change the computer name and modify the "HOSTS" and "NETWORKS" files on the 3 servers (C:\WINDOWS\system32 \drivers\etc) [if you use the 2nd way, when you change the computer name, press "More..." to input the DNS suffix] OK ! Now we shall start! HOST A = Principal Server HOST B = Mirror Server HOST W = Witness Server You need to copy the certificate between the servers manually. Here is the SQL code: -- HOST A create master key encryption by password = 'abc123!!'; GO create certificate HOST_A_cert with subject = 'HOST_A certificate', start_date = '2007/11/01', expiry_date = '2020/11/01'; Page 1 of 3 SQL 2005 Database Mirroring Tutorial 25/02/2008 http://alan328.com/SQL2005_Database_Mirroring_Tutorial.aspx

Upload: bima

Post on 08-Apr-2015

240 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Tutorial Mirroring

Type to search the Web

Home

Lotus Show

EF 100 Macro

Talk about success

How to test camera

Good Words

Photos

My Ferrari

Flash Exploded

Dirt Colin McRae

SQL 2005 Database Mirroring Tutorial

Glory Road [movie]

Electric Car

SQL 2005 Database Mirroring Tutorial

Introduction This tutorial is for people who are really really frustrated. One of my project need to use mirroring to replicate data between 2 database servers. I look for help online and found some useful websites. However, when I follow the instructions, some error messages stop me..... Most likely, you would get this error message: Error: 1418 - Microsoft SQL Server - The server net work address can not be reached or does not exist. Check the network address name and reissue the comm and. The server network endpoint did not respond because the specified server network addres s cannot be reached or does not exist. That error message dosen't tell you the truth.... there is nothing to do with "can not be reached or does not exist". There are 2 possible causes: - You forgot to use "NO RECOVERY" when restoring database on the MIRROR server - NT Authentication fail.... some unknow reason... a lot of people reported this problem When you view the SQL Server Log, you would see some error message like : Error: 1474, Severity: 16, State: 1 Database mirroring connection error 4 'An error occ urred while receiving data: '10054(An existing connection was forcibly closed by the remote host.) '.' for 'TCP://mymirror.mydomain:5022' or Error: 1443, Severity: 16, State: 2 or Database Mirroring login attempt by user 'NT AUTHOR ITY\ANONYMOUS LOGON.' failed with error: 'Connection handshake failed. The login 'NT AUTHORI TY\ANONYMOUS LOGON' does not have CONNECT permission on the endpoint. State 84. Well, if you are having the above error messages, I hope this tutorial could help you. Solution: Using Certificates Forget about Windows Authentication or Domain Account..... just use Certificates is good enough. What you need is: - 2 Servers and 1 Witness - Create a database on Principal Server - Backup the database 2 times: 1st time do a "FULL" backup, 2nd time do a "Transaction Log" backup - Restore the database on Mirror Server, MUST use option "NO RECOVERY" !!! After restore, the mirror database will not take any request, that is completely normal. - Fully Qualified Domain Name for all 3 servers..... you can do this by: 1. Setup a domain, or 2. Change the computer name and modify the "HOSTS" and "NETWORKS" files on the 3 servers (C:\WINDOWS\system32\drivers\etc) [if you use the 2nd way, when you change the computer name, press "More..." to input the DNS suffix] OK ! Now we shall start! HOST A = Principal Server HOST B = Mirror Server HOST W = Witness Server You need to copy the certificate between the servers manually. Here is the SQL code:

-- HOST A create master key encryption by password = 'abc123!!'; GO create certificate HOST_A_cert with subject = 'HOST_A certificate', start_date = '2007/11/01', expiry_date = '2020/11/01';

Page 1 of 3SQL 2005 Database Mirroring Tutorial

25/02/2008http://alan328.com/SQL2005_Database_Mirroring_Tutorial.aspx

Page 2: Tutorial Mirroring

GO Create endpoint endpoint_mirroring state = started as tcp(listener_port = 7024, listener_ip = all) for database_mirroring (authentication = certificate HOST_A_cert, encryption = disabled, role = all); GO Backup certificate HOST_A_cert to file = 'd:\HOST_A_cert.cer'; GO -- HOST B create master key encryption by password = 'abc123!!'; GO create certificate HOST_B_cert with subject = 'HOST_B certificate', start_date = '2007/11/01', expiry_date = '2020/11/01'; GO Create endpoint endpoint_mirroring state = started as tcp(listener_port = 7024, listener_ip = all) for database_mirroring (authentication = certificate HOST_B_cert, encryption = disabled, role = all); GO Backup certificate HOST_B_cert to file = 'd:\HOST_B_cert.cer'; GO -- HOST W create master key encryption by password = 'abc123!!'; GO create certificate HOST_W_cert with subject = 'HOST_W certificate', start_date = '2007/11/01', expiry_date = '2020/11/01'; GO Create endpoint endpoint_mirroring state = started as tcp(listener_port = 7024, listener_ip = all) for database_mirroring (authentication = certificate HOST_W_cert, encryption = disabled, role = witness); GO Backup certificate HOST_W_cert to file = 'd:\HOST_W_cert.cer'; GO -- HOST A again create login HOST_B_login with PASSWORD = 'abc123!!'; GO create user HOST_B_user from login HOST_B_login; GO Create certificate HOST_B_cert Authorization HOST_B_user From file = 'D:\HOST_B_cert.cer'; GO Grant CONNECT ON Endpoint::endpoint_mirroring to [HOST_B_login]; GO ------ create login HOST_W_login with PASSWORD = 'abc123!!'; GO create user HOST_W_user from login HOST_W_login; GO Create certificate HOST_W_cert Authorization HOST_W_user From file = 'D:\HOST_W_cert.cer'; GO Grant CONNECT ON Endpoint::endpoint_mirroring to [HOST_W_login]; GO -- HOST B again create login HOST_A_login with PASSWORD = 'abc123!!'; GO create user HOST_A_user from login HOST_A_login; GO Create certificate HOST_A_cert Authorization HOST_A_user

Page 2 of 3SQL 2005 Database Mirroring Tutorial

25/02/2008http://alan328.com/SQL2005_Database_Mirroring_Tutorial.aspx

Page 3: Tutorial Mirroring

Now, everything is fine! Hope you enjoy it! Alan - [email protected]

From file = 'D:\HOST_A_cert.cer'; GO Grant CONNECT ON Endpoint::Endpoint_mirroring to [HOST_A_login]; GO ------- create login HOST_W_login with PASSWORD = 'abc123!!'; GO create user HOST_W_user from login HOST_W_login; GO Create certificate HOST_W_cert Authorization HOST_W_user From file = 'D:\HOST_W_cert.cer'; GO Grant CONNECT ON Endpoint::Endpoint_mirroring to [HOST_W_login]; GO -- HOST W again create login HOST_A_login with PASSWORD = 'abc123!!'; GO create user HOST_A_user from login HOST_A_login; GO Create certificate HOST_A_cert Authorization HOST_A_user From file = 'D:\HOST_A_cert.cer'; GO Grant CONNECT ON Endpoint::Endpoint_mirroring to [HOST_A_login]; GO ------- create login HOST_B_login with PASSWORD = 'abc123!!'; GO create user HOST_B_user from login HOST_B_login; GO Create certificate HOST_B_cert Authorization HOST_B_user From file = 'D:\HOST_B_cert.cer'; GO Grant CONNECT ON Endpoint::endpoint_mirroring to [HOST_B_login]; GO -- HOST B again alter database good set partner = 'TCP://server1.ace.local:7024'; GO -- HOST A again alter database good set partner = 'TCP://server2.ace.local:7024'; GO alter database good set witness = 'TCP://mc.ace.local:7024'; GO

Home |Contact Us |About Us |Site Map

Page 3 of 3SQL 2005 Database Mirroring Tutorial

25/02/2008http://alan328.com/SQL2005_Database_Mirroring_Tutorial.aspx