IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  Information Management  >

使用 db2haicu 工具为 DB2 配置高可用性

DB2 版本 9.5 中 db2haicu 工具配合 TSA 的使用示例

developerWorks
文档选项

未显示需要 JavaScript 的文档选项


级别: 中级

孔斌 (binkong@cn.ibm.com), 软件工程师, IBM

2009 年 7 月 30 日

从 DB2 版本 9.5 开始,内置了一个文本工具 DB2 High Availability Instance Configuration Utility(db2haicu)。使用这个工具,用户可以利用 TSA(Tivoli System Automation)的特性,只需对原有系统做最小改动,即可为 DB2 进行高可用性配置。

简介

目前,很多中小企业都依赖单台服务器运行数据库。但一方面随着越来越多的重要应用移植到数据库上,另一方面,如硬件老化、系统运行错误等原因造成的停机维护时间增加,使得这种硬件环境已经不能满足业务需要,高可用性的引入已是大势所趋。然而,复杂的高可用配置以及由此造成的众多问题使得企业对此望而却步。而 DB2 9.5 中内嵌的 db2haicu(DB2 High Availability Instance Configuration Utility)工具通过配合 HA 集群管理软件 TSA(Tivoli System Automation)的自动化功能,可以使客户配置高可用环境既保证方便快捷,又保证了运行时的稳定可靠。本文以 AIX 5.3 和 DB2 版本 9.5 为例,介绍如何为现有 DB2 环境配置高可用性。





回页首


现有运行环境及改造方案

现有环境

图 1 显示了一个常见的 DB2 运行环境,用户通过光纤与存储设备 DS4200 连接,用于存放数据库文件,而主机使用单网卡与外界相连。客户端可以通过 IP 9.123.112.199 进行数据库操作。


图 1. 初始 DB2 配置示例
图 1. 初始 DB2 配置示例

DS4200 的具体使用情况参见表 1:


表 1. DS4200 使用情况
DS4200 VG对应挂载点
LUN0DB2HOME/DB2HOME

同时,db2inst1 用户的主目录位于 /DB2HOME/db2inst1,数据文件位于默认位置,这样可以利用存储提供的安全性对数据进行保障。

改造方案

根据对原有系统影响最小的原则,本方案不对原有系统做任何硬件改变,软件也只需要做细微改动(详细步骤参见后文)。

备用机器配置步骤:

  1. 安装 AIX 系统光盘中的 rsct.* 文件集
  2. 确保 DB2 版本 9.5 正常安装,并添加了 SA MP 组件
  3. 创建与原有系统相同 ID 的用户群和用户
  4. 将存储设备上的相同的 LUN 以相同的 VG 和 major number 进行挂接

原有运行环境配置步骤:

  1. 安装 AIX 系统光盘中的 rsct.* 文件集
  2. 确保 DS4200 上的 LUN 对应的 VG 不会被自动激活,相应挂载点也不会自动挂载
  3. 确保 DB2 版本 9.5 正常安装并运行,并添加了 SA MP 组件
  4. 添加客户机自动重路由配置参数
  5. 运行 db2haicu 完成配置

客户端:

  1. 对于 JDBC Type 2 方式进行的连接,利用 DB2 提供的客户机自动重路由功能,客户端可以不进行任何改动,直接读取服务器端设置的 Alternate server 即可在故障后,自动与虚拟 IP 进行连接。
  2. 对于 JDBC Type 4 方式进行的连接,重新更改配置文件中的目的地址即可。

图 2. 改造完成后的高可用环境配置
图 2. 改造完成后的高可用环境配置

配置完成后,外部程序可以通过原有 IP 9.123.112.199,也可以通过虚拟 IP 9.123.112.254 进行访问。当主节点出现故障,备用节点可以自动接管数据库系统,并以相同的虚拟 IP 对外提供服务。客户端则可以自动将连接从原有 IP 转为虚拟 IP,或者直接透明使用虚拟 IP 进行工作。





回页首


TSA 和 db2haicu 简介

DB2 与 TSA

在 AIX 和 Linux 操作系统上,SA MP Base Component 与 DB2 企业服务器版、 DB2 工作组服务器版、DB2 Connect 企业版和 DB2 Connect 应用程序服务器版集成。在Linux操作系统上,它还与 DB2 Express-C 固定期限许可证(FTL)和 DB2 高可用性功能部件易捷版集成。在 Windows 操作系统上,SA MP Base Component随所有这些DB2数据库产品和功能捆绑提供,但它未与DB2安装程序集成。

Tivoli System Automation(TSA)是一个高可用性集群管理软件,它为很多常用程序提供了自动化的管理模块。通过这些模块,用户告别了在其他 HA 集群管理软件上复杂的监控脚本与异常处理脚本,而转为只需定义需要监控的资源即可。

DB2 高可用性实例配置实用程序(db2haicu)是从 DB2 9.5 版本开始的一个基于文本的实用程序,您可以使用它在集群环境(本示例中,集群管理软件为 TSA)中配置与管理高可用性数据库。 db2haicu 通过查询系统来收集有关数据库实例、集群环境和集群管理器的信息。您可通过参数向 db2haicu 调用、输入文件提供更多信息,或在运行时通过在 db2haicu 提示符处提供信息来实现上述目的。





回页首


准备工作

时间同步(可选)

时间的同步并不是必须步骤,这样做只是为了保证定位问题时,不需要由于不同机器在日志中添加的时间不一致而不得不进行做相应的转换。为了准确同步,建议使用 AIX 中的 xntpd 子系统。

安装 RSCT 文件集

RSCT (Reliable Scalable Cluster Technology) 文件集是 AIX 实现 HA 的基础组件,包括 HACMP 和 TSA 在内的 HA 集群管理软件都需要 RSCT 支持。 RSCT 安装文件位于 AIX 安装介质中,通过 smitty 安装 rsct.* 即可。

添加 RSCT 之后,就可以为集群环境进行初步的准备工作了。在两个节点上执行相同的命令:

# preprpnode cmaix25 cmaix26

确保 DB2 版本 9.5 添加了 SA MP 组件

在 DB2 版 本 9.5 中,TSA 已经被完全整合。用户可以在安装 DB2 时通过选择“ Install the SAMP Base Component ”进行安装(如图 3 所示),也可以通过 DB2 ESE 安装介质中 db2/< 操作系统名称 >/tsamp 下的 installSAM 进行补充安装(如清单 1 所示)。


图 3. 安装 DB2 时选择 TSA


清单 1. 补充安装 TSA
cd ./db2/aix/tsamp 
 root@cmaix25 # ./installSAM 
 prereqSAM: All prerequisites for the ITSAMP installation are met on operating system AIX 
 5300-09 
 installSAM: Packages will be installed from directory ./AIX 
 installSAM: The following package is not installed yet and needs to be 
 installed ./AIX/sam.core 

 installSAM: A general License Agreement and License Information specifically for System 
 Automation will be shown. Scroll down using the Enter key (line by line) or Space bar 
 (page by page). At the end you will be asked to accept the terms to be allowed to 
 install the product. Select Enter to continue 
 ... ... 
 installSAM: To accept all terms of the preceding License Agreement and License 
 Information type 'y', anything else to decline
 
 

创建与原有系统相同 ID 的用户群和用户

检查主机 cmaix25 上的用户群组和用户 ID,如:

root@cmaix25 # su - db2inst1 
 $ id 
 uid=203(db2inst1) gid=102(db2iadm1) groups=1(staff),101(dasadm1),103(db2fadm1)

这样,在备用机 cmaix26 上面建立组和用户的时候,也为它们指定相同的 ID 信息。

检查主机 VG 及挂载点状态

检查主机环境,将挂载点设置为非自动加载,同时将 VG 设置为非自动激活。否则,当故障转换发生后,故障机器重新启动会试图抢占共享磁盘而报错。

root@cmaix25 # chvg -a n DB2HOME

检查 /etc/filesystems,确保 /DB2HOME 对应的 mount 选项为 false 。

将 LUN 以相同的 信息在客户机进行挂接

检查主机的 VG 名称:

root@cmaix25 # lspv 
 hdisk0 000925926d77bb8e rootvg active 
 hdisk2 000a5d72aa712308 DB2HOME active

并检查此 VG 对应的 major number

root@cmaix25 # ls -al /dev/DB2HOME 
 crw-rw---- 1 root system 45, 0 Jun 04 04:31 /dev/DB2HOME

根据此信息,在备用机上添加 VG 时,设置相同的 major number,并通向确保不会被自动激活。

root@cmaix26 # importvg -y DB2HOME -V 45 hdisk2

同时,根据主机 /nfs/filesystems 内容,在客户机生建立 /DB2HOME 目录并设置相同的挂载信息。

为数据库添加客户机自动重路由

实际上,虽然配置完成后可以通过虚拟 IP 进行访问,但对于没有更改原数据库连接信息的客户机,它并不会在接管完成之后自动连接到新的主数据库,而是仍然尝试连接到原来的主数据库,由于原来的主服务器已经变成备用服务器(数据库角色切换),或者原来的主服务器已经被禁用(故障转移),这样的连接尝试将遭到失败。

这就是为什么需要 DB2 自动客户机重路由特性。当 DB2 启用了自动客户机重路由特性时,在接管完成之后,所有当前的和新的客户机连接都自动被路由到虚拟 IP,应用程序在很短的中断之后又可以继续它们的工作。

在主机上执行以下命令:

db2 update alternate server for database <DB Name> using <Virtual IP> port <PORT>





回页首


交互模式进行 db2haicu 配置(主机)

只需要在 Active 节点 cmaix25 中运行此命令即可,Standby 节点会自动完成相应的设置。

 $db2start06/10/2009 03:17:44 0 0 SQL1063N DB2START processing was successful. 
 
 SQL1063N DB2START processing was successful. 
 $ 
 $db2haicuWelcome 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.
 
 

第一步就是要创建集群,并填入该集群的相应信息。在本示例中,我们将集群命名为 cmaix2526,并且添加入两个节点:cmaix25 和 cmaix26 。请注意,这节点的名字和数量需要与 preprpnode 中的设置相一致。

Create a domain and continue? [1] 
 1. Yes 
 2. No 
 1 
 Create a unique name for the new domain: 
 cmaix2526 
 Nodes must now be added to the new domain. 
 How many cluster nodes will the domain cmaix2526 contain? 
 2 
 Enter the host name of a machine to add to the domain: 
 cmaix25 
 Enter the host name of a machine to add to the domain: 
 cmaix26 
 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 
 1 
 Creating domain cmaix2526 in the cluster ... 
 Creating domain cmaix2526 in the cluster was successful.

集群配置完毕后,开始设置 QUORUM 设备。通过设置一个能够 ping 到的 IP 地址,来决定集群中两台机器是否正常工作。请注意,QUORUM 设备必须保证能够始终被 ping 到,以保证整个集群环境中机器状态的正确。在本示例中,我们使用网关地址 9.123.112.1 作为网络 QUORUM 设备。

为简单起见,本文中使用了公共网络作为 QUORUM 设备。但在实际使用中,如果数据交换与心跳检测使用了同一个网络,那么当网络拥挤时会产生心跳检测不准确的情况。一个极端的例子是,网络堵塞会造成检测工具错误的认为 Active 节点出现了故障,这时 Standby 机器会启动接管操作。由于 Active 节点实际上仍然是活跃的,这种结果会造成两个节点使用了相同的 IP 地址,并且同时拥有和访问共享磁盘,并造成一系列故障。因此,建议用户使用第二块网卡进行私有网络心跳仲裁。

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 cmaix2526? [1] 
 1. Yes 
 2. No 
 1 
 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] 
 1 
 Specify the network address of the quorum device: 
 9.123.112.1 
 Configuring quorum device for domain cmaix2526 ... 
 Configuring quorum device for domain cmaix2526 was successful.

这一步设置公共网络,db2haicu 会自动探测所有连接的网络,并且通过用户的选择,将重要的网络添加进集群。 db2haicu 会检测集群中的网络,并且当此网络故障时,将相应节点设置为不可用。

The cluster manager found 2 network interface cards on the machines in the domain. 
You can use db2haicu to create networks for these network interface cards. 
For more information, see the topic 'Creating networks with db2haicu' 
in the DB2 Information Center. 

 Create networks for these network interface cards? [1] 
 1. Yes 
 2. No 
 1 
 Enter the name of the network for the network interface card: en0 
on cluster node: cmaix25.cn.ibm.com 
 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 en0 on cluster 
 node cmaix25.cn.ibm.com to the network db2_public_network_0? [1] 
 1. Yes 
 2. No 
 1 
 Adding network interface card en0 on cluster node cmaix25.cn.ibm.com to the 
network db2_public_network_0 ... 
 Adding network interface card en0 on cluster node cmaix25.cn.ibm.com to the 
network db2_public_network_0 was successful. 
 Enter the name of the network for the network interface card: en0 on cluster 
node: cmaix26.cn.ibm.com 
 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 en0 on cluster node 
cmaix26.cn.ibm.com to the network db2_public_network_0? [1] 
 1. Yes 
 2. No 
 1 
 Adding network interface card en0 on cluster node cmaix26.cn.ibm.com to the 
network db2_public_network_0 ... 
 Adding network interface card en0 on cluster node cmaix26.cn.ibm.com to the 
network db2_public_network_0 was successful.
 
 

现在,db2haicu 提示当前的 HA 环境使用何种集群管理软件,在本示例中只讨论 TSA 环境。而故障转换策略则决定了当数据库出现故障之后的处理方式。在多节点多分区环境下,这需要复杂的设计。但在本示例中,由于只有两个节点,我们可以简单的选择 Active/Passive 方式,即一个活动节点,一个备用节点。

Retrieving high availability configuration parameter for instance db2inst1 ... 
 The cluster manager name configuration parameter 
(high availability configuration parameter) 
 is not set. For more information, see the topic "cluster_mgr - Cluster manager 
 name configuration parameter" in the DB2 Information Center. 
 Do you want to set the high availability configuration parameter? 
 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] 
 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 
 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: 
 cmaix25 
 Enter the host name for the passive cluster node: 
 cmaix26 
 Adding DB2 database partition 0 to the cluster ... 
 Adding DB2 database partition 0 to the cluster was successful.

最后一步是虚拟 IP 的设置。设置完成后,集群就具有了一个浮动 IP 地址,当主节点活动时,此 IP 地址附属在主节点上,一旦主节点不可用,IP 地址会浮动到备用节点上。备用节点也就可以自动开始工作。请注意,必须要确保虚拟 IP 地址的可用性能,建议先试用此 IP,以保证此 IP 地址可以正确工作在网络中。

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: 
 9.123.112.254 
 Enter the subnet mask for the virtual IP address 9.123.112.254: [255.255.255.0] 
 255.255.255.0 
 Select the network for the virtual IP 9.123.112.254: 
 1. db2_public_network_0 
 Enter selection: 
 1 
 Adding virtual IP address 9.123.112.254 to the domain ... 
 Adding virtual IP address 9.123.112.254 to the domain was successful. 
 All cluster configurations have been completed successfully. db2haicu exiting ...

至此,一个高可用 DB2 配置环境完成了。此外,db2haicu 还支持以 XML 方式进行集群环境配置,此处不进行讨论。





回页首


运行与维护

配置完成后,很多操作对用户来说都是透明的。用户可以在 Active 机器上使用 lssam 或者 db2pd – ha 指令来查看当前系统的状态。此外,当执行下列数据库管理器实例配置和管理操作时,用户不需要考虑其对于集群环境的影响,数据库管理器会自动执行相关的集群管理器配置:

  • 使用 START DATABASE 或 db2start 来启动数据库
  • 使用 STOP DATABASE 或 db2stop 来停止数据库
  • 使用 CREATE DATABASE 来创建数据库
  • 使用 CREATE TABLESPACE 来添加存储器
  • 使用 ALTER TABLESPACE DROP 或 DROP TABLESPACE 来除去存储器
  • 使用 DROP TABLESPACE 来删除数据库
  • 使用 RESTORE DATABASE 或 db2Restore 来复原数据库
  • 使用 SET TABLESPACE CONTAINERS 为重定向复原指定表空间容器
  • 使用 ROLLFORWARD DATABASE 或 db2Rollforward 前滚数据库
  • 使用 RECOVER DATABASE 或 db2Recover 来恢复数据库
  • 使用 CREATE EVENT MONITOR 来创建事件监视器
  • 使用 DROP EVENT MONITOR 来删除事件监视器
  • 使用以下各项来创建和改变外部例程:
    • CREATE PROCEDURE
    • CREATE FUNCTION
    • CREATE FUNCTION
    • CREATE METHOD
    • ALTER PROCEDURE
    • ALTER FUNCTION
    • ALTER METHOD
  • 使用以下各项来删除外部例程:
    • DROP PROCEDURE
    • DROP FUNCTION
    • DROP METHOD
  • 使用 START HADR 来为数据库启动 DB2 高可用性灾难恢复(HADR)操作
  • 使用 STOP HADR 来为数据库停止 HADR 操作
  • 使用 TAKEOVER HADR 来促使 HADR 备用数据库作为 HADR 主数据库来接管工作
  • 设置数据库管理器配置参数 DIAGPATH 或 SPM_LOG_PATH
  • 设置数据库配置参数 NEWLOGPATH、OVERFLOWLOGPATH、MIRRORLOGPATH 或 FAILARCHPATH
  • 使用 db2idrop 来删除数据库管理器实例

例如,当用户 CREATE TABLESPACE 时指定了另一块共享磁盘上的挂载点,则该资源将被自动添加入 TSA 集群环境并具有了相同的高可用特性。同样,在设置了高可用性的实例 db2inst1 中 CREATE DATABSE 也会使该数据库被自动添加入集群。在这种配置下,用户的运行成本比传统高可用环境低很多,资源监控与切换的风险也大大降低。





回页首


参考资源 (resources)



参考资料

学习

获得产品和技术
  • 现在可以免费使用 DB2 。下载 DB2 Express-C,这是为社区提供的 DB2 Express Edition 的免费版本,它提供了与 DB2 Express Edition 相同的核心数据特性,为构建和部署应用程序奠定了坚实的基础。

  • 下载 DB2 Enterprise V9.5 试用版 ,试用本文中描述的特性。

  • 下载 信息管理软件试用版 ,体验它们强大的功能。


讨论


关于作者

孔斌的照片

孔斌, IBM 软件工程师,国家认证系统分析师。从事企业内容管理(Enterprise Content Manager) 的系统测试工作,目前主要工作方向是高可用性测试。




对本文的评价








IBM 公司保留在 developerWorks 网站上发表的内容的著作权。未经IBM公司或原始作者的书面明确许可,请勿转载。如果您希望转载,请通过 提交转载请求表单 联系我们的编辑团队。
    关于 IBM 隐私条约 联系 IBM 使用条款