HADR实施步骤

来源:互联网 发布:少女前线数据配置获取 编辑:程序博客网 时间:2024/05/16 15:10

HADR规划

 

Hostname

hao111

localhost

数据库实例名

cms

端口

50001

根目录

/home/cms/db2fs 

在线日志路径

/home/cms/db2log/trans

归档日志路径

/home/cms/db2log/arch

db2 hadr service port

db2h_cmsinst1   70000/tcp 

IP

192.168.56.102  primary-node1

192.168.56.104  primary-node2

192.168.56.103  standby-node1

192.168.56.105  standby-node2

 

 

 

 

数据库安装 (主、备)

 [root@hao111 ~]# mount -o loop -t iso9660 db29.7_07_linux64.iso /mnt/db2rom/

 [root@hao111 ~]# cd /mnt/db2rom/

 [root@hao111 db2rom]# ./db2_install

WARNING:

DBT3534W  The db2prereqcheck utility determined that ASLR is set to ON and that this could cause issues with some tools.

WARNING: 

   The 32-bit library file libpam.so is not found on the system. 

 

Default directory for installation of products - /opt/ibm/db2/V9.7

 

***********************************************************

Do you want to choose a different directory to install [yes/no] ?

no

 [root@hao111 ~]# groupadd -g 2000 db2iadm1

 [root@hao111 ~]# groupadd -g 2001 db2fadm1

 [root@hao111 ~]# useradd -m -g db2iadm1 -d /home/db2inst1 db2inst1

 [root@hao111 ~]# useradd -m -g db2fadm1 -d /home/db2fenc1 db2fenc1

 [root@hao111 ~]# useradd -m -g db2iadm1 -d /home/cms cms

 [root@hao111 ~]# useradd -m -g db2iadm1 -d /home/scms scms

 [root@hao111 ~]# passwd db2inst1

 [root@hao111 ~]# passwd db2fenc1

 [root@hao111 ~]# passwd cms

 [root@hao111 ~]# passwd scms

创建实例

[root@hao111 ~]# cd /opt/ibm/db2/V9.7/instance/

[root@hao111 instance]# ./db2icrt -p 50000 -u db2fenc1 db2inst1

DBI1070I  Program db2icrt completed successfully. 

[root@hao111 instance]# ./db2icrt -p 50001 -u db2fenc1 cms

DBI1070I  Program db2icrt completed successfully. 

 [root@hao111 instance]# ./db2icrt -p 50002 -u db2fenc1 scms

DBI1070I  Program db2icrt completed successfully. 

安装许可证

[root@hao111 instance]# su - db2inst1

[db2inst1@hao111 ~]$ db2licm -l

[db2inst1@hao111 ~]$ exitlogout

[root@hao111 instance]# cd /opt/ibm/db2/V9.7/adm/

[root@hao111 adm]# ./db2licm -a /root/db2ese_c.lic  

LIC1402I  License added successfully.

 

建库

$ db2start

$ db2 create db cms automatic storage yes on /home/cms/db2fs using codeset GBK territory CN

 

操作系统内核参数配置

$ vi /etc/sysctl.conf

----以内存为16GB的配置例子

----如果大于16GBSEMMSLSEMMNSSEMOPMmsgmaxmsgmnb保持不变

----shmmnishmmaxshmallSEMMNImsgmni的设置成比例增大,见下面加黑内容

kernel.msgmnb = 65536

kernel.msgmax = 65536

kernel.msgmni=1638

kernel.shmmax = 68719476736

kernel.shmmni=4096

kernel.shmall = 4294967296

----kernel.sem= <SEMMSL>  <SEMMNS>  <SEMOPM>  <SEMMNI> 

kernel.sem=250 25600 32 4096

 

# sysctl -p     ----使设置生效

# ipcs -l      ----显示当前内核参数

 

 

 

修改limits.conf

# vi /etc/security/limits.conf   ----根据实际情况,酌情修改

修改/etc/hosts

# vi /etc/hosts

 

 

 

DB2参数配置

环境变量配置 (主、备)

$ db2set DB2_USE_IOCP=OFF

$ db2set DB2COMM=tcpip  

$ db2set DB2CODEPAGE=1386 

$ db2set DB2AUTOSTART=YES 

$ db2set DB2_HADR_ROS=ON

$ db2set DB2_STANDBY_ISO=UR

设置 DBM CFG (主、备)

$ db2 update dbm cfg using DIAGLEVEL 3                                                                       

$ db2 update dbm cfg using DIAGSIZE 1024                                                                    

$ db2 update dbm cfg using SHEAPTHRES 0   ----SHEAPTHRES的值为0时,使用共享排序

设置 DB CFG ()

预取和清页进程数目设定

connect to cms;

update db cfg using NUM_IOCLEANERS AUTOMATIC;

update db cfg using NUM_IOSERVERS AUTOMATIC;

锁参数设定

connect to cms;

update db cfg using MAXLOCKS 40;

update db cfg using LOCKLIST 20480;

update db cfg using LOCKTIMEOUT 30;

日志参数设定

connect to cms;

update db cfg using LOGBUFSZ 5120;

update db cfg using LOGFILSIZ 51200;

update db cfg using LOGPRIMARY 50;

update db cfg using LOGSECOND 80;

update db cfg using SOFTMAX 100;

update db cfg using TRACKMOD ON;

update db cfg using NEWLOGPATH /home/cms/db2log/trans;  ----事务日志的存储路径

update db cfg using LOGARCHMETH1 DISK:/home/cms/db2log/arch;

内存参数设定

connect to cms;

update db cfg using CATALOGCACHE_SZ AUTOMATIC;

update db cfg using PCKCACHESC AUTOMATIC;

update db cfg using STMTHEAP AUTOMATIC;

update db cfg using APPLHEAPSZ AUTOMATIC;

update db cfg using STAT_HEAP_SZ AUTOMATIC;

update db cfg using SHEAPTHRES_SHR AUTOMATIC;

update db cfg using SORTHEAP AUTOMATIC;

 

 

$ db2 disconnect all

$ db2stop

$ db2start

实施

复制数据库

备份()

$ db2 backup db cms online to /home/cms/111 compress

生成迁移脚本()

$ db2 list history backup all for cms

$ db2ckbkp -h CMS.0.cms.NODE0000.CATN0000.20140125044402.001

$ db2 "restore db cms from . taken at 20140125044402  into cms logtarget /home/cms/db2fs redirect generate script cms.clp"    

     ----logtarget /home/db2fs ”字段,表示rollforward生成的日志路径

                                                      

 

恢复数据库 ()

$ cd /home/cms

$ mkdir db2log

$ cd db2log

$ mkdir arch 

$ mkdir trans

$ scp CMS.0.cms.NODE0000.CATN0000.20140125044402.001 cms@192.168.56.103:~

$ scp cms.clp cms@192.168.56.103:~

$ db2 -tvf cms.clp  ---- cms.clp文件,需要根据实际情况,酌情修改。

 

配置通讯端口 (主、备)

# vi /etc/services 

键入“shift+G”到最后一行

加入:db2h_cmsinst1   70000/tcp  #db2 hadr service port

保存,退出!

 

数据库参数配置

主节点:

$ vi hadr1.sh 

db2 update db cfg for cms using hadr_local_host primary-node2;

db2 update db cfg for cms using hadr_local_svc db2h_cmsinst1;

db2 update db cfg for cms using hadr_remote_host standby-node2;

db2 update db cfg for cms using hadr_remote_svc db2h_cmsinst1;

db2 update db cfg for cms using hadr_remote_inst cms;

db2 update db cfg for cms using logindexbuild on;

db2 update db cfg for cms using indexrec restart;

 

$ chmod +x hadr1.sh 

$ ./hadr1.sh 

 

从节点:

$ vi hadr2.sh 

db2 update db cfg for cms using hadr_local_host standby-node2;

db2 update db cfg for cms using hadr_local_svc db2h_cmsinst1;

db2 update db cfg for cms using hadr_remote_host primary-node2;

db2 update db cfg for cms using hadr_remote_svc db2h_cmsinst1;

db2 update db cfg for cms using hadr_remote_inst cms;

db2 update db cfg for cms using logindexbuild on;

db2 update db cfg for cms using indexrec restart;

 

$ chmod +x hadr2.sh 

$ ./hadr2.sh

启动主从数据库

启动从数据库

$ db2start

$ db2 start hadr on db cms as standby

 

启动主数据库

$ db2start

$ db2 start hadr on db cms as primary

 

 

切换HADR

监控HADR状态

$ db2pd -d cms -hadr

 

手工切换

在从节点上执行“takeover hadr”命令:

$ db2 takeover hadr on database cms

 

0 0
原创粉丝点击