日期:2014-05-16  浏览次数:20473 次

搭建DB2 HADR
两台数据库服务器
主A:96.0.43.61
备B:96.0.43.62

实例用户/密码::

准备环境
1、在A中创建样本数据库sampl
db2sampl


2、修改A日志方式为归档日志,并作备份
db2 get db cfg for sample | grep -i log
mkdir -p sample/redo
mkdir -p sample/archive
db2 update db cfg for sample using NEWLOGPATH /home/db2inst2/sample/redo
db2 update db cfg for sample using LOGARCHMETH1 /home/db2inst2/sample/archive
db2stop
db2start
db2 backup db sample online to "/nfs_backup/db2_fulbak/" with 3 buffers buffer 2000 parallelism 2 include logs


3、在B中恢复备份
db2 list db directory
db2 restore db sample from "/nfs_backup/db2_fulbak/"
db2 rollforward db sample to end of logs


4、配置hadr参数
--在Primary端:
db2 update db cfg for sample using HADR_LOCAL_HOST 96.0.43.61  
db2 update db cfg for sample using HADR_LOCAL_SVC 70002 
db2 update db cfg for sample using HADR_REMOTE_HOST 96.0.43.62
db2 update db cfg for sample using HADR_REMOTE_SVC 70012  
db2 update db cfg for sample using HADR_REMOTE_INST db2inst2 
db2 update db cfg for sample using HADR_SYNCMODE SYNC  
db2 update db cfg for sample using HADR_TIMEOUT 3  
db2 update db cfg for sample using HADR_PEER_WINDOW 120
db2 connect to sample
db2 quiesce database immediate force connections  
db2 unquiesce database 
db2 connect reset

--在Standby端:
db2 update db cfg for sample using HADR_LOCAL_HOST 96.0.43.62
db2 update db cfg for sample using HADR_LOCAL_SVC 70012
db2 update db cfg for sample using HADR_REMOTE_HOST 96.0.43.61
db2 update db cfg for sample using HADR_REMOTE_SVC 70002
db2 update db cfg for sample using HADR_REMOTE_INST db2inst2
db2 update db cfg for sample using HADR_SYNCMODE SYNC  
db2 update db cfg for sample using HADR_TIMEOUT 3  
db2 update db cfg for sample using HADR_PEER_WINDOW 120 


5、开启hadr集群
--在Primary端
db2 deactivate db sample
db2 start hadr on db sample as standby


--在Standby端
db2 deactivate db sample
db2 start hadr on db sample as primary

6、检查命令
db2 get db cfg for sample | grep -i hadr
db2pd -d sample -hadr


7、接管/故障转移
db2 takeover hadr on db sample
db2 takeover hadr on db sample by force


8、停止hadr
--Standby
db2 deactivate db sample
db2 stop hadr on db sample


--Primary
db2 deactivate db sample
db2 stop hadr on db sample