您好,欢迎访问一九零五行业门户网

Linux DB2 HADR 双机搭建

搞了好几天总算是把hadr弄好啦,下面分享下 系统环境: os:suse 11sp1-64bit db: db29.7.0.5 db2server1:192.168.5.151 db2in
搞了好几天总算是把hadr弄好啦,,下面分享下
系统环境:
os:suse 11sp1-64bit
db: db29.7.0.5
db2server1:192.168.5.151  db2inst1
db2server2:192.168.5.152 db2inst2
步骤:
db2server1上操作:
db2inst1@db2server1:~> db2 create database oga;
db2inst1@db2server1:~> db2 get dbm cfg | grep svc
db2inst1@db2server1:~> db2set db2comm=tcpip
db2inst1@db2server1:~> db2 update dbm cfg usingsvcename 50001
db2inst1@db2server1:~> db2 update db cfg for ogausing logretain on
db2inst1@db2server1:~> db2 update db cfg for ogausing trackmod on;
db2inst1@db2server1:~> db2 update db cfg for ogausing logindexbuild on;
db2inst2@db2server1:~> db2 backup db oga
db2inst1@db2server1:~> db2 create tablecert(orgid int not null,entid int not null,certnum char(20) not null primarykey,issuedate date)
db2inst1@db2server1:~> db2 alter table certdata capture changes
db2inst1@db2server1:~> db2 create tableorg(orgid int not null primary key, orgname char(20)) date capturechanges
db2inst1@db2server1:~> db2 insert into orgvalues(1, 'org1')
db2inst1@db2server1:~> db2 insert into orgvalues(2, 'org2')
db2inst1@db2server1:~> db2 insert into orgvalues(3, 'org3')
db2inst1@db2server1:~> db2 insert into certvalues(1, 2, 'cert1','2009-12-5')
db2inst1@db2server1:~> db2 insert into certvalues(2, 2, 'cert2','2010-3-5')
db2inst1@db2server1:~> db2 insert into certvalues(3, 2, 'cert3', current date)
db2inst1@db2server1:~> db2 update db cfg for ogausing hadr_local_svc 44455
db20000i  theupdate database configuration command completed successfully.
db2inst1@db2server1:~> db2 update db cfg for ogausing hadr_remote_host 192.168.5.152
db20000i  theupdate database configuration command completed successfully.
db2inst1@db2server1:~> db2 update db cfg for ogausing hadr_local_host 192.168.5.151
db20000i  theupdate database configuration command completed successfully.
db2inst1@db2server1:~> db2 update db cfg for ogausing hadr_remote_svc 33344
db20000i  theupdate database configuration command completed successfully.
db2inst1@db2server1:~> db2 update db cfg for ogausing hadr_remote_inst db2inst2
db20000i  theupdate database configuration command completed successfully.
db2inst1@db2server1:~> db2 update db cfg for ogausing hadr_syncmode nearsync
db20000i  theupdate database configuration command completed successfully.
db2 update alternate server for database sample usinghostname 192.168.5.151 port 50001
db2inst1@db2server1:~> db2 get db cfg for oga | grep-i hadr
db2server2上的操作
db2inst1@db2server2:~> db2 create database oga;
db2inst1@db2server2:~> db2 get dbm cfg | grep svc
db2inst1@db2server2:~> db2set db2comm=tcpip
db2inst1@db2server2:~> db2 update dbm cfg usingsvcename 50001
db2inst1@db2server2:~> db2 update db cfg for ogausing logretain on
db2inst1@db2server2:~> db2 update db cfg for ogausing trackmod on;
db2inst1@db2server2:~> db2 update db cfg for ogausing logindexbuild on;
db2inst1@db2server1:/opt/bak> db2 backup db oga to/opt/bak
db2inst1@db2server2:~> db2 create tablecert(orgid int not null,entid int not null,certnum char(20) not null primarykey,issuedate date)
db2inst1@db2server2:~> db2 alter table certdata capture changes
db2inst1@db2server2:~> db2 create tableorg(orgid int not null primary key, orgname char(20)) date capturechanges
db2inst2@db2server2:~> db2 update db cfg for ogausing hadr_local_host 192.168.5.152
db20000i  theupdate database configuration command completed successfully.
db2inst2@db2server2:~> db2 update db cfg for ogausing hadr_local_svc 44455
db20000i  theupdate database configuration command completed successfully.
db2inst2@db2server2:~> db2 update db cfg for ogausing hadr_remote_host 192.168.5.151
db20000i  theupdate database configuration command completed successfully.
db2inst2@db2server2:~> db2 update db cfg for ogausing hadr_remote_svc 33344
db20000i  theupdate database configuration command completed successfully.
db2inst2@db2server2:~> db2 update db cfg for ogausing hadr_syncmode nearsync
db20000i  theupdate database configuration command completed successfully.
db2inst2@db2server2:~> db2 update db cfg for ogausing hadr_remote_inst db2inst1
db20000i  theupdate database configuration command completed successfully.
db2 update alternate server for database sample usinghostname 192.168.5.152 port 50001
db2inst1@db2server2:~> db2 get db cfg for oga | grep-i hadr
db2inst2@db2server2:/opt/bak> cd /opt/bak/
重定向恢复
db2 restore db oga on /data_inst2/db2inst2/oga/ dbpathon /data_inst2/db2inst2/ into oga
db2 rollforward db oga stop  ——这个不需要执行,否则在启动备库的时候会提示sql1767n  start hadr cannot complete. reason code =1.
将表恢复到了db2inst1下面,保证db2inst2可以看到这些表
db2inst2@db2server2:~> db2 connect to sample userdb2inst1 using db2inst
db2inst2@db2server2:/opt/bak> db2 connect to sample
b2inst1@db2server1:/opt/bak> db2 grant dbadm ondatabase to db2inst2
db20000i  the sqlcommand completed successfully.
db2inst1@db2server1:/opt/bak> db2 grant secadm ondatabase  to db2inst2
db20000i  the sqlcommand completed successfully.
db2inst2@db2server2:~> db2 select * from db2inst1.cert
orgid      entid       certnum              issuedate
----------- ----------- -------------------- ----------
          1           2 cert1                12/05/2009
          2           2 cert2                03/05/2010
          3           2 cert3                03/23/2012
启动standby
db2inst2@db2server2:~>db2 deactivate database sample
sql1496w deactivate database is successful, but the database was not
activated.是断开关闭数据库
db2inst2@db2server2:~> db2 start hadr on db oga asstandby
sql1032n  nostart database manager command was issued.
注意:此时standby不可以连接数据库,否则会造成主库不一致的。
db2inst2@db2server2:~> db2 get snapshot for db onoga | grep role
  role                   = standby
db2inst2@db2server2:~>
启动主机
db2inst1@db2server1:/opt/bak> db2 activate db oga
db20000i  theactivate database command completed successfully.
db2inst2@db2server1:~> db2 start hadr on db oga as primary
db2inst1@db2server1:~> db2 get snapshot for db onsample | grep role
  role                   = primary
验证两台机的状态:
db2inst1@db2server1:~> db2 get snapshot for db onoga | grep state
commit statements attempted                = 16
rollback statements attempted              = 0
dynamic statements attempted               = 479
static statements attempted                = 30
failed statement operations                = 0
select sql statements executed             = 152
xquery statements executed                 = 0
update/insert/delete statements executed   = 9
ddl statements executed                    = 0
停止
db2inst2@db2server2:~> db2 deactivate database oga
db20000i  thedeactivate database command completed successfully.
db2inst2@db2server2:~> db2 stop hadr on database oga
db20000i  thestop hadr on database command completed successfully.
db2inst2@db2server1:~> db2 stop hadr on database oga
db20000i  thestop hadr on database command completed successfully.
测试:
db2inst1@db2server1:~> db2 insert into orgvalues (5,'org5')
db20000i  the sqlcommand completed successfully.
备库查看
db2inst2@db2server2:/opt/bak> db2 get snapshot fordb on oga | grep -i file
database files closed                      = not collected
file number of first active log            = not applicable
file number of last active log             = not applicable
file number of current active log          = 12
file number of log being archived          = not applicable
rollforward log file being processed       = 7
  primary logposition(file, page, lsn) = s0000012.log, 76, 0000000005374584
  standby logposition(file, page, lsn) = s0000012.log, 76, 0000000005374584
接管主库
原来的主库可以停掉也可以不停
db2inst2@db2server2:/opt/bak> db2 takeover hadr ondatabase oga user db2inst1 using db2inst1
db20000i  thetakeover hadr on database command completed successfully.
db2inst2@db2server2:/opt/bak> db2 connect to oga userdb2inst1 using db2inst1
db2inst2@db2server2:/opt/bak> db2 select *from org
orgid      orgname            
----------- --------------------
          1org1               
          2org2               
          3org3               
          4 org4               
          5org5
5 record(s)selected.
查看原来主机的状态
db2inst1@db2server1:~> db2 get snapshot for db onoga | more
database snapshot
database name                              = oga
database path                              =/data_inst1/db2inst1/db2inst1/node0000/sql00001/
input database alias                       = oga
database status                            = standby
catalog database partition number          = 0
catalog network node name                  =
operating system running at database server= linuxamd64
location of the database                   = local
first database connect timestamp           = 2012-03-28 15:21:16.354049
last reset timestamp                       =
last backup timestamp                      = 2012-03-2715:20:54.000000
snapshot timestamp                         = 2012-03-2816:26:47.497005
number of automatic storage paths          = 1
原来备库的状态
db2inst2@db2server2:/opt/bak> db2 get snapshot fordb on oga | more
database snapshot
database name                              = oga
database path                              =/data_inst2/db2inst2/db2inst2/node0000/sql00001/
input database alias                       = oga
database status                            = active
catalog database partition number          = 0
catalog network node name                  =
operating system running at database server= linuxamd64
location of the database                   = local
first database connect timestamp           = 03/28/2012 15:20:41.342208
last reset timestamp                       =
last backup timestamp                      =
snapshot timestamp                         = 03/28/201216:27:38.538201
number of automatic storage paths          = 1
其它类似信息

推荐信息