共同进步
作者共同进步·2013-12-06 13:05
数据库架构师·中国金融电子化公司

原创首发:使用DB2自带的HA功能配置HA

字数 10300阅读 5740评论 4赞 5
前提需求
1)两台主机或者虚机之间建立共享磁盘。
2)两台主机或者虚机上安装DB2 ESE版
测试环境说明
操作系统版本:SuseLinux10Sp4 X64位
DB2版本:DB2 V9.7FP8
虚机:virtual box4.3.4
host1:10.1.4.90,主机名:DB2HA1
host2:10.1.4.33,主机名:DB2HA2
详细步骤
在加入集群的两个节点上编辑/etc/profile文件,加入下面一行
   export  CT_MANAGEMENT_SCOPE=2
在加入集群的两个节点上编辑/etc/hosts文件,加入下面一行
   10.1.4.90       DB2HA1.site
   10.1.4.33       DB2HA2.site
在加入集群的两个节点上以root身份运行下面的命令,准备节点
   preprpnode DB2HA1 DB2HA2
在加入集群的两个节点上,修改/etc/services文件,加入DB2服务端口
   DB2c_db2inst1     50000/tcp
在DB2HA1上对识别出的共享磁盘上建立VG,名称为vgtest,并在该VG上建立一个lv,名称为lv_test,对应的mount点为/home/db2inst1,并修改fstab选项,选择mount方式为“Do Not Mount at System Start-up”



在DB2HA1上在root用户下执行如下命令创建如下用户,并修改/home/db2inst1文件系统的属组为db2inst1:db2iadm
   groupadd -g 1000 db2iadm
   groupadd -g 1001 db2fadm
   useradd -m -d /home/db2inst1 -g 1000 -u 10000 db2inst1
   useradd -m -d /home/db2fenc1 -g 1001 -u 10010 db2fenc1
   修改db2inst1用户的密码
   passwd db2inst1
   cd /home
   chown -R db2inst1:db2iadm db2inst1
   su - db2inst1
   创建空的.profile之后保存
在DB2HA1上在root用户下执行如下命令创建实例,并设置注册变量,更新实例服务端口
       /opt/ibm/db2/v9.7/instance/db2icrt -s ese -u db2fenc1 db2inst1
       实例创建成功之后
       su - db2inst1
       db2set DB2COMM=tcpip
       db2 update dbm cfg using svcename DB2c_db2inst1
       db2start
   实例启动成功之后,通过执行netstat -an|grep -i 50000检查是否已经在服务端口启动监听
   db2stop
在DB2HA1上在root用户下关闭卸载文件系统/home/db2inst1
   su - root
   umount /home/db2inst1
重启DB2HA2之后,使用root用户登录后按照如下方式修改/etc/fstab选项
   LABEL=lv_test        /home/db2inst1       reiserfs   noauto,acl,user_xattr        1 2
在DB2HA2上装载/home/db2inst1文件系统
   mount /home/db2inst1
在DB2HA2上创建实例相关用户
   groupadd -g 1000 db2iadm
   groupadd -g 1001 db2fadm
   useradd -m -d /home/db2inst1 -g 1000 -u 10000 db2inst1
   useradd -m -d /home/db2fenc1 -g 1001 -u 10010 db2fenc1
   修改db2inst1用户的密码
   passwd db2inst1
   cd /home
   chown -R db2inst1:db2iadm db2inst1
   su - db2inst1
   创建空的.profile之后保存
在DB2HA2上在root用户下执行如下命令创建实例,并设置注册变量,更新实例服务端口
   删除/home/db2inst1目录下的全部内容,执行
       /opt/ibm/db2/v9.7/instance/db2icrt -s ese -u db2fenc1 db2inst1
       实例创建成功之后
       su - db2inst1
       db2set DB2COMM=tcpip
       db2 update dbm cfg using svcename DB2c_db2inst1
       db2start
   实例启动成功之后,通过执行netstat -an|grep -i 50000检查是否已经在服务端口启动监听
   db2stop
   su - root
   umount /home/db2inst1
在DB2HA1上重新装载/home/db2inst1,并修改db2nodes.cfg:
   mount /home/db2inst1
   su - db2inst1
   并修改db2nodes.cfg中的内容如下:
   0 DB2HA1 0
启动实例
   db2start
通过执行db2haicu,完成整个集群配置
   db2haicu
   Welcome to the DB2 High Availability Instance Configuration Utility (db2haicu).

You can find detailed diagnostic information in the DB2 server diagnostic log file called db2diag.log. Also, you can use the utility called db2pd to query the status of the cluster domains you create.

For more information about configuring your clustered environment using db2haicu, see the topic called 'DB2 High Availability Instance Configuration Utility (db2haicu)' in the DB2 Information Center.

db2haicu determined the current DB2 database manager instance is db2inst1. The cluster configuration that follows will apply to this instance.

db2haicu is collecting information on your current setup. This step may take some time as db2haicu will need to activate all databases for the instance to discover all paths ...
When you use db2haicu to configure your clustered environment, you create cluster domains. For more information, see the topic 'Creating a cluster domain with db2haicu' in the DB2 Information Center. db2haicu is searching the current machine for an existing active cluster domain ...
db2haicu did not find a cluster domain on this machine. db2haicu will now query the system for information about cluster nodes to create a new cluster domain ...

db2haicu did not find a cluster domain on this machine. To continue configuring your clustered environment for high availability, you must create a cluster domain; otherwise, db2haicu will exit.

Create a domain and continue? [1]
1. Yes
2. No
Create a unique name for the new domain:
hotstdby
Nodes must now be added to the new domain.
How many cluster nodes will the domain hotstdby contain?
2
Enter the host name of a machine to add to the domain:
DB2HA1
Enter the host name of a machine to add to the domain:
DB2HA2
db2haicu can now create a new domain containing the 2 machines that you specified. If you choose not to create a domain now, db2haicu will exit.

Create the domain now? [1]
1. Yes
2. No

Creating domain hotstdby in the cluster ...
Creating domain hotstdby in the cluster was successful.
You can now configure a quorum device for the domain. For more information, see the
topic "Quorum devices" in the DB2 Information Center. If you do not configure a
quorum device for the domain, then a human operator will have to manually intervene
if subsets of machines in the cluster lose connectivity.
Configure a quorum device for the domain called hotstdby? [1]
1. Yes
2. No
The following is a list of supported quorum device types:
1. Network Quorum
Enter the number corresponding to the quorum device type to be used: [1]
Specify the network address of the quorum device:
10.1.4.89
Configuring quorum device for domain hotstdby ...
Configuring quorum device for domain hotstdby was successful.
Create networks for these network interface cards? [1]
1. Yes
2. No

Enter the name of the network for the network interface card: eth0 on cluster node: DB2HA1.site
1. Create a new public network for this network interface card.
2. Create a new private network for this network interface card.
Enter selection:
1
Are you sure you want to add the network interface card eth0 on cluster node DB2HA1.site to the network db2_public_network_0? [1]
1. Yes
2. No

Adding network interface card eth0 on cluster node DB2HA1.site to the network db2_public_network_0 ...
Adding network interface card eth0 on cluster node DB2HA1.site to the network db2_public_network_0 was successful.
Enter the name of the network for the network interface card: eth0 on cluster node: DB2HA2.site
1. db2_public_network_0
2. Create a new public network for this network interface card.
3. Create a new private network for this network interface card.
Enter selection:
1
Are you sure you want to add the network interface card eth0 on cluster node DB2HA2.site to the network db2_public_network_0? [1]
1. Yes
2. No

Adding network interface card eth0 on cluster node DB2HA2.site to the network db2_public_network_0 ...
Adding network interface card eth0 on cluster node DB2HA2.site to the network db2_public_network_0 was successful.
The following are valid settings for the high availability configuration parameter:
  1.TSA
  2.Vendor
Enter a value for the high availability configuration parameter: [1]

Setting a high availability configuration parameter for instance db2inst1 to TSA.
Now you need to configure the failover policy for the instance db2inst1. The failover policy determines the machines on which the cluster manager will restart the database manager if the database manager is brought offline unexpectedly.
The following are the available failover policies:
  1. Local Restart -- during failover, the database manager will restart in place on the local machine
  2. Round Robin -- during failover, the database manager will restart on any machine in the cluster domain
  3. Active/Passive -- during failover, the database manager will restart on a specific machine
  4. M+N -- during failover, the database partitions on one machine will failover to any other machine in the cluster domain (used with DPF instances)
  5. Custom -- during failover, the database manager will restart on a machine from a user-specified list
Enter your selection:
3
You can identify mount points that are noncritical for failover. For more information, see the topic 'Identifying mount points that are noncritical for failover' in the DB2 Information Center.  Are there any mount points that you want to designate as noncritical? [2]
1. Yes
2. No
1
Enter the full path of the mount to be made non-critical:
/
Adding path / to the non-critical path list ...
Adding path / to the non-critical path list was successful.
Do you want to add more paths to the non-critical path list? [1]
1. Yes
2. No
2
Active/Passive failover policy was chosen. You need to specify the host names of an active/passive pair.
Enter the host name for the active cluster node:
DB2HA1
Enter the host name for the passive cluster node:
DB2HA2
Adding DB2 database partition 0 to the cluster ...
Adding DB2 database partition 0 to the cluster was successful.
Do you want to configure a virtual IP address for the DB2 partition: 0? [2]
1. Yes
2. No
1
Enter the virtual IP address:
10.1.4.91
Enter the subnet mask for the virtual IP address 10.1.4.91: [255.255.255.0]
255.255.255.0
Select the network for the virtual IP 10.1.4.91:
1. db2_public_network_0
Enter selection:
1
Adding virtual IP address 10.1.4.91 to the domain ...
Adding virtual IP address 10.1.4.91 to the domain was successful.
All cluster configurations have been completed successfully. db2haicu exiting ...
   备注:如果执行过程中因某种原因导致中途退出,如果希望删除原有的集群域配置进行重建,可以执行db2haicu -delete,也可在root用户下通过执行rmrpdomain domainname完成
在共享磁盘上建立数据库
   db2 "create db testdb using codeset gbk territory cn pagesize 32 K"
     至此,整个HA配置已经完成。如果希望验证HA的效果,可以在其他客户端配置服务IP的DB2连接之后进行测试。
     可以采用如下方式进行测试:
     1)reboot DB2HA1
     2)db2实例失败
     3)在节点间手动移动资源(rgreq -o move <resource group>)

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

5

添加新评论4 条评论

atpeace331atpeace331数据库管理员银行
2014-08-04 20:25
借鉴一下
uc804uc804数据库运维工程师企业
2013-12-13 15:45
好贴
daoguo525daoguo525系统工程师世纪五岳(北京)科技有限公司
2013-12-12 16:12
飘叶飘叶数据库管理员volkswagen
2013-12-06 13:51
呵呵,我刚做完hadr的配置cluster,准备搞share disk呢,正好参考你的文章
Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广