Summary:

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

测试环境:

OS:Red hat 6
Server: 192.168.122.17
Primary instance: hadr1pri
Primary service/port: 43099
Standby instance: hadr1std
Standby service/port: 44099
DB name: ORG
--注意,切勿使用与DBM SVCENAME 太接近的端口,因为实例会默认使用那端口之后的连续几个端口,所以应尝试更远一些的端口
vi /etc/services
DB2_hadrpri     60008/tcp
DB2_hadrpri_1 60009/tcp
DB2_hadrpri_2 60010/tcp
DB2_hadrpri_END 60011/tcp
DB2_hadrstd 60012/tcp
DB2_hadrstd_1 60013/tcp
DB2_hadrstd_2 60014/tcp
DB2_hadrstd_END 60015/tcp
43099 43099/tcp
44099 44099/tcp

搭建开始

step 1: 创建组和用户

create primary instance id
To create groups on Linux operating systems, enter the following commands:

groupadd -g  db2iadm2
groupadd -g db2fadm2
groupadd -g dasadm2 Create users for each group: useradd -u -g db2iadm2 -m -d /home/hadrpri hadrpri
useradd -u -g db2fadm2 -m -d /home/hadrfenc hadrfenc
useradd -u -g dasadm2 -m -d /home/hadrdas hadrdas

create standby instance id
To create groups on Linux operating systems, enter the following commands:

useradd -u 1020 -g db2iadm2 -m -d /home/hadr1std  hadr1std

useradd -u 1019 -g db2fadm2 -m -d /home/hadr1sfc  hadr1sfc

useradd -u 1018 -g dasadm2 -m -d /home/std1das std1das

step 2:创建实例

cd /opt/IBM/db2/V9.7/instance
./db2icrt -s ese -u hadr1fc hadr1pri
./db2icrt -s ese -u hadr1sfc hadr1std

step3: 主节点归档模式设置,备节点使用restore方式创建数据库,主备节点HADR设置

--在Primary:

--启用归档模式
--启用LOGINDEXBUILD,以便日志有关索引的操作 db2 update db cfg for org using LOGRETAIN on
db2 update db cfg for org using LOGINDEXBUILD on --Backup DB
db2 backup db org to /data

----在standby

--启动数据

--使用primary db 的备份文件进行数据库恢复

db2start 
db2 restore db org from   /home/hadrstd  taken at 20150120040252 on /home/hadrstd dbpath on /home/hadrstd

--这时候standby的数据库应该是roll-forward pedning的状态,切勿手动roll-forward 
   db2 connect to org

SQL1117N  A connection to or activation of database "SAMPLE" cannot be made  
   because of ROLL-FORWARD PENDING.  SQLSTATE=57019

--在Primary:

db2 update dbm cfg using svcename DB2_hadrpri

db2 update db cfg for org using hadr_local_svc  41099

db2 update db cfg for org using hadr_remote_host  192.168.122.17

db2 update db cfg for org using hadr_local_host  192.168.122.17

db2 update db cfg for org using hadr_remote_svc 42099

db2 update db cfg for org using hadr_remote_inst  hadrstd

db2 update db cfg for org using hadr_syncmode sync

db2 connect to org
db2 quiesce database immediate force connections
db2 unquiesce database
db2 connect reset

--在Standby:

db2 update dbm cfg using svcename DB2_hadrstd

db2 update db cfg for org using hadr_remote_host  192.168.122.17

db2 update db cfg for org using hadr_local_svc  42099

db2 update db cfg for org using hadr_local_host  192.168.122.17

db2 update db cfg for org using hadr_remote_svc  41099

db2 update db cfg for org using hadr_remote_inst  hadrpri

db2 update db cfg for org using hadr_syncmode sync

db2 update db cfg for org using HADR_TIMEOUT 3

db2 update db cfg for org using HADR_PEER_WINDOW 120

4.启动并测试

--先启动standby 
    --在Standby: 
    db2 start hadr on db sample as standby 
    DB20000I  The START HADR ON DATABASE command completed successfully. 
     
    --这时候应该是remote catchup pending的状态:

[hadrstd@oc0644314035 db2dump]$ db2pd -d org -hadr

Database Partition 0 -- Database ORG -- Standby -- Up 0 days 00:00:05 -- Date 2015-01-20-22.00.09.169952

HADR Information:

Role    State                SyncMode   HeartBeatsMissed   LogGapRunAvg (bytes)

Standby RemoteCatchupPending Sync     0                  0

ConnectStatus ConnectTime                           Timeout  
Disconnected  Tue Jan 20 22:00:05 2015 (1421809205) 120

LocalHost                                LocalService     
192.168.122.17                           42099

RemoteHost                               RemoteService      RemoteInstance   
192.168.122.17                           41099              hadrstd

PrimaryFile  PrimaryPg  PrimaryLSN       
S0000000.LOG 0          0x0000000002728010

StandByFile  StandByPg  StandByLSN         StandByRcvBufUsed

--再启动Primary 
    --在Primary: 
[hadr1pri@oc0644314035 data]$ db2 start hadr on database org as primary

DB20000I  The START HADR ON DATABASE command completed successfully.

[hadrstd@oc0644314035 ~]$ db2pd -d org -hadr

Database Partition 0 -- Database ORG -- Standby -- Up 0 days 00:11:53 -- Date 2015-01-21-00.59.58.732725

HADR Information:

Role    State                SyncMode   HeartBeatsMissed   LogGapRunAvg (bytes)

Standby Peer                 Sync     0                  0

ConnectStatus ConnectTime                           Timeout  
Connected     Wed Jan 21 00:48:39 2015 (1421819319) 3

PeerWindowEnd                         PeerWindow

Wed Jan 21 01:01:57 2015 (1421820117) 120

LocalHost                                LocalService     
192.168.122.17                           42099

RemoteHost                               RemoteService      RemoteInstance   
192.168.122.17                           41099              hadrpri

PrimaryFile  PrimaryPg  PrimaryLSN       
S0000001.LOG 0          0x0000000002728010

StandByFile  StandByPg  StandByLSN         StandByRcvBufUsed

S0000001.LOG 0          0x0000000002728010 0%

--可以看到一旦Primary也起来了,hadr的状态就会变成peer

--这时候尝试手动归档,看日志是否能够顺利传递到standby 
[hadr1pri@oc0644314035 data]$  db2 archive log for DB sample

DB20000I  The ARCHIVE LOG command completed successfully.

--在Standby进行role 切换

[hadrstd@oc0644314035 ~]$ db2 takeover hadr on database org

DB20000I  The TAKEOVER HADR ON DATABASE command completed successfully.

[hadrstd@oc0644314035 ~]$ db2pd -d org -hadr

Database Partition 0 -- Database ORG -- Active -- Up 0 days 00:12:16 -- Date 2015-01-21-01.00.21.098460

HADR Information:

Role    State                SyncMode   HeartBeatsMissed   LogGapRunAvg (bytes)

Primary Peer                 Sync     0                  0

ConnectStatus ConnectTime                           Timeout  
Connected     Wed Jan 21 00:48:39 2015 (1421819319) 3

PeerWindowEnd                         PeerWindow

Wed Jan 21 01:02:20 2015 (1421820140) 120

LocalHost                                LocalService     
192.168.122.17                           42099

RemoteHost                               RemoteService      RemoteInstance   
192.168.122.17                           41099              hadrpri

PrimaryFile  PrimaryPg  PrimaryLSN       
S0000001.LOG 0          0x0000000002728010

StandByFile  StandByPg  StandByLSN       
S0000001.LOG 0          0x0000000002728010

References

搭建案例:

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

http://blog.csdn.net/dream19881003/article/details/7417285

自己总结的ISSUES

http://www.cnblogs.com/DBA-Ivan/p/4260264.html

Issues:

https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014850278

http://bytes.com/topic/db2/answers/496482-unable-start-hadr-reason-code-7-a

http://www.dbforums.com/showthread.php?1665366-DB2-9-7-HADR-setup

【HADR】搭建实战的更多相关文章

  1. 小D课堂 - 新版本微服务springcloud+Docker教程_3-05 服务注册和发现Eureka Server搭建实战

    笔记 5.服务注册和发现Eureka Server搭建实战     简介:使用IDEA搭建Eureka服务中心Server端并启动,项目基本骨架介绍          官方文档:http://clou ...

  2. Elasticsearch数据库 | Elasticsearch-7.5.0应用搭建实战

    Elasticsearch 是一个可用于分布式以及符合RESTful 风格的搜索和数据分析引擎.-- Elastic Stack 官网 搭建Elasticsearch的"那些事儿" ...

  3. Linux-Rsync服务器/客户端搭建实战

    一.需求 每晚汇总各机器的操作日志,同步到主服务器进行日志分析. 二.基础知识 rsync 分为服务器端.客户端,服务器端搭建比客户端辛苦一些(也是很简单). rsync 服务器是指以 deamon ...

  4. Struct2、Hibernate3、Spring3框架搭建实战(转)

    采用目前最新的struts-2.3.1.2.hibernate3.6.10.Final.spring-framework-3.1.1.RELEASE开发包,以及eclipse-jee-indigo-S ...

  5. Nuget私有服务搭建实战

    最近更新了Nuget私有服务器的版本,之前是2.8.5,现在是2.11.3. Nuget服务器的搭建,这里有篇很详细的文章,跟着弄就好了: https://docs.microsoft.com/en- ...

  6. ASP.NET MVC项目框架快速搭建实战

    MVC项目搭建笔记---- 项目框架采用ASP.NET MVC+Entity Framwork+Spring.Net等技术搭建,采用”Domain Model as View Model“的MVC开发 ...

  7. 超详细解说Hadoop伪分布式搭建--实战验证【转】

    超详细解说Hadoop伪分布式搭建 原文http://www.tuicool.com/articles/NBvMv2原原文 http://wojiaobaoshanyinong.iteye.com/b ...

  8. Docker竟然还能这么玩?商业级4G代理搭建实战!

    时间过得真快,距离这个系列的上一篇文章<商业级4G代理搭建指南[准备篇]>发布的时间已经过了两个星期了,上个星期由于各种琐事缠身,周二开始就没空写文章了,所以就咕咕咕了. 那么在准备篇中, ...

  9. Hexo+Github个人博客搭建 | 实战经验分享

    概述 第一次尝试搭建属于自己的博客,并且成功了,非常开心. 很久之前就想搭建一个博客,可是也一直没有行动,最近在逛B站的时候发现一个up主(CodeSheep)的一个视频 <手把手教你从0开始搭 ...

随机推荐

  1. MySQL性能调优与架构设计——第11章 常用存储引擎优化

    第11章 常用存储引擎优化 前言: MySQL 提供的非常丰富的存储引擎种类供大家选择,有多种选择固然是好事,但是需要我们理解掌握的知识也会增加很多.每一种存储引擎都有各自的特长,也都存在一定的短处. ...

  2. Python WebDriver + Firefox 文件下载

    firefox可以通过 在地址栏输入:about:config 或about:aupport 来查看或修改配置信息. 这里有两种解决方式, 1.设置自动保存下载 如下图勾选:以后自动采用相同的动作处理 ...

  3. Vivado安装教程

    Vivado的各个版本的安流程其实都差不多,本教程用Vivado2016.4为例进行安装,同样适用于之前和之后的各个版本. 下载好安装包后打开,双击xsetup.exe运行安装程序 弹出的窗口,提示现 ...

  4. C的打印输出格式

    #include<stdio.h> int main() { float test1=12.3224356546565461-0.1; int test2=13; char test3[] ...

  5. 深海划水队项目--七天冲刺之day7

    站立式会议: 昨天已完成的工作:设置游戏按键,检查重合.检查是否超出边界.检查是否可以下落,方块的硬下落和软下落方法. 今日已完成的工作:添加方法:方块的着陆和消除. 工作中遇到的困难:在消除方块的时 ...

  6. FDMemTable三层提交数据总是不成功的原因

    提交数据的代码如下: procedure TForm1.btnSaveClick(Sender: TObject);var LDeltas: TFDJSONDeltas;begin if FDMemT ...

  7. akka 练手 原来第一次是原封不动的返回传出去的参数

    今天,有介绍akka的文章,就下了个源码的demo练手! 在TimeServer 这个实例中主要就2个文件 server端 static void Main(string[] args) { usin ...

  8. Pi 在Windows下面使用远程桌面登录

    1.删除系统自带的xrdp 输入命令sudo apt-get purge xrdp pi@raspberrypi:~ $ sudo apt-get purge xrdp 正在读取软件包列表... 完成 ...

  9. 1-初步了解C#-语言基础

    本篇博客对应视频讲解 前言 终于开始讲语言了,我选择讲C#.为什么呢?因为C#是很好的入门语言,简洁.全面,面向对象类型安全,开发体验好,上手容易.而其他的语言也已经有人讲了很多了,C#相对来说要少一 ...

  10. java public class和class的区别