日期:2014-05-17 浏览次数:20417 次
一、建立证书: 主: 建立证书 drop master key drop certificate host_a_cert --证书名host_a_cert create master key encryption by password='mbooKsKmK_00e3syc' create certificate host_a_cert with subject='host_a',start_date='10/10/2010' 备机: 建立证书 drop master key drop certificate host_b_cert create master key encryption by password='mbooKsKmK_00e3syc' create certificate host_b_cert with subject='host_b',start_date='10/10/2010' 二、建立端点: 主: create endpoint endpoint_carpool state=started as tcp(listener_port=5022,listener_ip=all) for database_mirroring (authentication=certificate host_a_cert,encryption=REQUIRED ALGORITHM AES,role=all) 备: create endpoint endpoint_carpool state=started as tcp(listener_port=5022,listener_ip=all) for database_mirroring (AUTHENTICATION = CERTIFICATE HOST_B_cert , ENCRYPTION = REQUIRED ALGORITHM AES , ROLE = ALL) 三、备份证书 主: backup certificate host_a_cert to file='d:\host_a_cert.cer' 备: backup certificate host_b_cert to file='d:\host_b_cert.cer' 四、互换证书 HOST_A_cert.cer复制到备机的D:\ HOST_B_cert.cer复制到主机的D:\ 五、添加登录 主体: create login host_b_login with password='mbooKsKmK_00e3syc' create user host_b_user for login host_b_login; create certificate host_b_cert authorization host_b_user from file='d:\host_b_cert.cer'; grant connect on endpoint::endpoint_carpool to [host_b_login] 备: CREATE LOGIN host_a_login WITH PASSWORD = 'mbooKsKmK_00e3syc'; CREATE USER host_a_user FOR LOGIN host_a_login; CREATE CERTIFICATE host_a_cert AUTHORIZATION host_a_user FROM FILE = 'D:\HOST_A_cert.cer'; GRANT CONNECT ON ENDPOINT:: endpoint_carpool TO [host_a_login]; 六:建立镜像 主: alter database carpool set partner='tcp://备机ip:5022' 备: alter database carpool set partner='tcp://主机ip:5022' 其他事项: 1、alter database test set partner off 删除test数据库的数据库镜像;重建的时候需要先删除; 2、如果出现错误,可以通过查看系统日志来分析;通常情况是权限问题(需要重新分配证书和权限); 七:镜像高可用性实现 主备互换: 主(一定要在主上执行,备上执行与否无所谓): alter database 操作的数据库名 set partner failover; 备: alter database 操作的数据库名 set partner force_service_allow_data_loss; 主机出现问题需要启用备机则过程如下: 1\alter database 操作的数据库名 set partner force_service_allow_data_loss; 2\alter database test set partner off 过程不可颠倒 如果原来的主服务器恢复,则重新设定镜像 备: alter database 操作的数据库名 set partner resume; alter database 操作的数据库名 set partner failover;