linux_hadr_环境搭建

http://guoyanxi.iteye.com/blog/1173906

 

搭建简单的DB2 HADR

博客分类: 
 
简单的HADR,只用一台虚拟机,两个实例间搭建。工作量不大,一般5分钟左右能够完成。 
步骤: 
1.设定归档模式 
2.使用备份建立standby数据库 
3.设定hadr相关的参数 
4.启动并测试 

Sql代码  收藏代码
  1. 环境:  
  2. Server: 127.0.0.1  
  3. Primary instance: db2inst4  
  4. Primary service/port: 42099  
  5. Standby instance: db2inst5  
  6. Standby service/port: 41099  
  7. DB name: SAMPLE  
  8. --注意,切勿使用与DBM SVCENAME 太接近的端口,因为实例会默认使用那端口之后的连续几个端口,所以应尝试更远一些的端口  


1.设定归档模式 
Sql代码  收藏代码
  1. --在Primary:  
  2. --启用归档模式  
  3. [db2inst4@localhost instance]$ db2 update db cfg for SAMPLE using LOGRETAIN on  
  4. DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.  
  5.   
  6. --启用LOGINDEXBUILD,以便日志有关索引的操作  
  7. [db2inst4@localhost instance]$ db2 update db cfg for SAMPLE using LOGINDEXBUILD on  
  8. DB20000I  The UPDATE DATABASE CONFIGURATION command completed successfully.  


2.使用备份建立standby数据库 
Sql代码  收藏代码
  1. --备份primary  
  2. [db2inst4@localhost arch]$ db2 list db directory  
  3.   
  4.  System Database Directory  
  5.   
  6.  Number of entries in the directory = 1  
  7.   
  8. Database 1 entry:  
  9.   
  10.  Database alias                       = SAMPLE  
  11.  Database name                        = SAMPLE  
  12.  Local database directory             = /home/db2inst4  
  13.  Database release level               = d.00  
  14.  Comment                              =  
  15.  Directory entry type                 = Indirect  
  16.  Catalog database partition number    = 0  
  17.  Alternate server hostname            =  
  18.  Alternate server port number         =  
  19.   
  20. [db2inst4@localhost arch]$ db2 backup db sample to /arch  
  21.   
  22. Backup successful. The timestamp for this backup image is : 20110430101950  
  23. [db2inst4@localhost arch]$ ls -atrl   
  24. total 135208  
  25. drwxr-x---  3 db2inst1 db2iadm1      4096 Dec  8 12:12 db2inst1  
  26. drwxr-xr-x 27 root     root          4096 Apr 22 23:45 ..  
  27. drwxrwxrwx  3 root     root          4096 Apr 30 10:19 .  
  28. -rw-------  1 db2inst4 db2iadm1 138297344 Apr 30 10:20 SAMPLE.0.db2inst4.NODE0000.CATN0000.20110430101950.001  
  29.   
  30. --注意修改备份文件属性,以便standby实例能够访问  
  31. [db2inst4@localhost arch]$ chmod 777 SAMPLE.0.db2inst4.NODE0000.CATN0000.20110430101950.001  
  32.   
  33. --在standby:  
  34. [db2inst5@localhost ~]$ db2 restore db sample from /arch/ on /home/db2inst5/  
  35. DB20000I  The RESTORE DATABASE command completed successfully.  
  36. [db2inst5@localhost ~]$ db2 list db directory  
  37.   
  38.  System Database Directory  
  39.   
  40.  Number of entries in the directory = 1  
  41.   
  42. Database 1 entry:  
  43.   
  44.  Database alias                       = SAMPLE  
  45.  Database name                        = SAMPLE  
  46.  Local database directory             = /home/db2inst5  
  47.  Database release level               = d.00  
  48.  Comment                              =  
  49.  Directory entry type                 = Indirect  
  50.  Catalog database partition number    = 0  
  51.  Alternate server hostname            =  
  52.  Alternate server port number         =  
  53.   
  54. --这时候standby的数据库应该是roll-forward pedning的状态,切勿手动roll-forward  
  55. [db2inst5@localhost ~]$ db2 connect to SAMPLE  
  56. SQL1117N  A connection to or activation of database "SAMPLE" cannot be made   
  57. because of ROLL-FORWARD PENDING.  SQLSTATE=57019  


3.设定hadr相关的参数 
Sql代码  收藏代码
  1. --在Primary:  
  2. db2 update db cfg for sample using HADR_LOCAL_HOST 127.0.0.1  
  3. db2 update db cfg for sample using HADR_LOCAL_SVC 42099  
  4. db2 update db cfg for sample using HADR_REMOTE_HOST 127.0.0.1  
  5. db2 update db cfg for sample using HADR_REMOTE_SVC 41099  
  6. db2 update db cfg for sample using HADR_REMOTE_INST db2inst5  
  7. db2 update db cfg for sample using HADR_SYNCMODE SYNC  
  8. db2 update db cfg for sample using HADR_TIMEOUT 3  
  9. db2 update db cfg for sample using HADR_PEER_WINDOW 120  
  10. db2 connect to sample  
  11. db2 quiesce database immediate force connections  
  12. db2 unquiesce database  
  13. db2 connect reset  
  14.   
  15. --在Standby:  
  16. db2 update db cfg for sample using HADR_LOCAL_HOST 127.0.0.1  
  17. db2 update db cfg for sample using HADR_LOCAL_SVC 41099  
  18. db2 update db cfg for sample using HADR_REMOTE_HOST 127.0.0.1  
  19. db2 update db cfg for sample using HADR_REMOTE_SVC 42099  
  20. db2 update db cfg for sample using HADR_REMOTE_INST db2inst4  
  21. db2 update db cfg for sample using HADR_SYNCMODE SYNC  
  22. db2 update db cfg for sample using HADR_TIMEOUT 3  
  23. db2 update db cfg for sample using HADR_PEER_WINDOW 120  


4.启动并测试 
Sql代码  收藏代码
  1. --先启动standby  
  2. --在Standby:  
  3. [db2inst5@localhost ~]$ db2 start hadr on db sample as standby  
  4. DB20000I  The START HADR ON DATABASE command completed successfully.  
  5.   
  6. --这时候应该是remote catchup pending的状态:  
  7. [db2inst5@localhost ~]$ db2pd -d sample -hadr  
  8.   
  9. Database Partition 0 -- Database SAMPLE -- Standby -- Up 0 days 00:03:44  
  10.   
  11. HADR Information:  
  12. Role    State                SyncMode HeartBeatsMissed   LogGapRunAvg (bytes)  
  13. Standby RemoteCatchupPending Sync     0                  1                     
  14.   
  15. ConnectStatus ConnectTime                           Timeout     
  16. Disconnected  Sat Apr 30 14:09:54 2011 (1304143794) 3           
  17.   
  18. PeerWindowEnd                         PeerWindow  
  19. Null (0)                              120         
  20.   
  21. LocalHost                                LocalService        
  22. 127.0.0.1                                41099               
  23.   
  24. RemoteHost                               RemoteService      RemoteInstance      
  25. 127.0.0.1                                42099              db2inst4            
  26.   
  27. PrimaryFile  PrimaryPg  PrimaryLSN          
  28. S0000000.LOG 0          0x0000000002AC24A1  
  29.   
  30. StandByFile  StandByPg  StandByLSN         StandByRcvBufUsed  
  31. S0000000.LOG 0          0x0000000002AC24A1 0%    
  32.   
  33. --再启动Primary  
  34. --在Primary:  
  35. [db2inst4@localhost ~]$ db2 start hadr on database sample as primary  
  36. DB20000I  The START HADR ON DATABASE command completed successfully.  
  37. [db2inst4@localhost ~]$ db2pd -d sample -hadr  
  38.   
  39. Database Partition 0 -- Database SAMPLE -- Active -- Up 0 days 00:00:15  
  40.   
  41. HADR Information:  
  42. Role    State                SyncMode HeartBeatsMissed   LogGapRunAvg (bytes)  
  43. Primary Peer                 Sync     0                  0                     
  44.   
  45. ConnectStatus ConnectTime                           Timeout     
  46. Connected     Sat Apr 30 14:14:14 2011 (1304144054) 3           
  47.   
  48. PeerWindowEnd                         PeerWindow  
  49. Sat Apr 30 14:16:26 2011 (1304144186) 120         
  50.   
  51. LocalHost                                LocalService        
  52. 127.0.0.1                                42099               
  53.   
  54. RemoteHost                               RemoteService      RemoteInstance      
  55. 127.0.0.1                                41099              db2inst5            
  56.   
  57. PrimaryFile  PrimaryPg  PrimaryLSN          
  58. S0000002.LOG 0          0x0000000003288861  
  59.   
  60. StandByFile  StandByPg  StandByLSN          
  61. S0000002.LOG 0          0x0000000003288861  
  62.   
  63. --可以看到一旦Primary也起来了,hadr的状态就会变成peer  
  64.   
  65. --这时候尝试手动归档,看日志是否能够顺利传递到standby  
  66. [db2inst4@localhost ~]$ db2 archive log for DB sample  
  67. DB20000I  The ARCHIVE LOG command completed successfully.  
  68.   
  69. --在Standby观察  
  70. [db2inst5@localhost ~]$ db2pd -d sample -hadr  
  71.   
  72. Database Partition 0 -- Database SAMPLE -- Standby -- Up 0 days 00:05:25  
  73.   
  74. HADR Information:  
  75. Role    State                SyncMode HeartBeatsMissed   LogGapRunAvg (bytes)  
  76. Standby Peer                 Sync     0                  0                     
  77.   
  78. ConnectStatus ConnectTime                           Timeout     
  79. Connected     Sat Apr 30 14:14:14 2011 (1304144054) 3           
  80.   
  81. PeerWindowEnd                         PeerWindow  
  82. Sat Apr 30 14:17:18 2011 (1304144238) 120         
  83.   
  84. LocalHost                                LocalService        
  85. 127.0.0.1                                41099               
  86.   
  87. RemoteHost                               RemoteService      RemoteInstance      
  88. 127.0.0.1                                42099              db2inst4            
  89.   
  90. PrimaryFile  PrimaryPg  PrimaryLSN          
  91. S0000003.LOG 0          0x000000000366BA41  
  92.   
  93. StandByFile  StandByPg  StandByLSN         StandByRcvBufUsed  
  94. S0000003.LOG 0          0x000000000366BA41 0%    
  95.   
  96. --两边当前日志都是S0000003.LOG,测试成功  
 
 

posted on 2016-07-21 10:44  fantiejun0436  阅读(170)  评论(0)    收藏  举报

导航