IBM DB2 high availability (HA) clusters on virtual machines using Heartbeat have (at minimum) two nodes — a primary and a standby (virtual). DB2 HA clusters on virtual machines are designed to reduce the loss of data or work when something happens to the primary node. It enables automatic and effortless switching over to the virtual machines. You can improve resource utilization, respond quickly to business needs, and stay flexible and free from vendor lock in. In other words, DB2 high availability clusters on virtual machines give you the ability to run your data center faster, easier, and better, for less money.
With this setup, you can also survive a failure on one of the two Xen hosts, schedule downtime for hardware maintenance, or move the machines with the users of the platforms. A failure of the service means that users have to reconnect, but they won't have to wait until the node has rebooted or until you have fixed the hardware problem.
Installation and configuration instructions
In this section, see how to install the software and configure DB2 with Heartbeat high availability system for clustering and failover.
Heartbeat monitoring refers to the ability of one node to detect that another node is down when it fails — to detect the missing node's "heartbeat."
Let's first take a look at the required components. You need:
- A system that supports Linux® or UNIX® Xen virtualization
- A storage volume where all nodes involved in the cluster can write to at the same time
- A file system that allows simultaneous writes
- The Heartbeat software for high availability clustering
- One or more Xen virtual machines
- DB2 8.1 for Linux, UNIX, and Window or later (see Resources for trial and free downloads of DB2)
- SAN storage or NFS shared disk
Figure 1. System overview
Install the Linux OS with Xen
This is the first step of configuration and can be achieved while installing the operating system, including the Xen Virtual Machine packages. (Or you can manually install it afterward.)
Figure 2. Choose Xen packages for installation
Install Xen Hypervisor
This is the second step of configuration. The hypervisor needs to be installed on the host using YAST or YUM.
Figure 3. Install the packages using YAST or other package manager
Create a virtual machine
Figure 4. Configure the virtual machine
Log in as root user on the virtual machine
Figure 5. Virtual machine — domU — running within host dom0
Cluster configuration details
Listing 1. Configuration details
Node1 (Primary) vmlinux.test.com 188.8.131.52 Node2 (Virtual Machine) db2xen.test.com 184.108.40.206
Test the serial connection
On a Linux platform, serial port devices are typically named ttyS0, ttyS1,
and. Use the
setserial command to display or
configure serial port information. For example, use the following commands
to display which ports are available:
Listing 2. Display which ports are available
setserial -bg /dev/ttyS* /dev/ttyS0 at 0x03f8 (irq = 4) is a 16550A /dev/ttyS1 at 0x02f8 (irq = 3) is a 16550A
Sharing disk between primary and virtual machines
You can either use SAN disk or NFS for sharing the disk between nodes. This article uses NFS.
- Create a /data directory on both nodes.
- On vmlinux.test.com node, modify the /etc/exports file for sharing
/data. For the setup in this article, we have added the following
- Start the NFS services. If NFS is already running, you can run the
/usr/sbin/exportfs -rato force nfsd to re-read the /etc/exports file.
- Modify the /etc/fstab file as follows, on both the HA nodes
vmlinux.test.com and db2xen.test.com:
vmlinux.test.com:/data /data nfs noauto,rw,hard 0 0
You now need to manually mount /data on both nodes since it configured as a noauto.
Download and install Heartbeat
Download heartbeat and install it on both the vmlinux and db2xen machines:
Listing 3. Install Heartbeat on both machines
rpm -ivh heartbeat-220.127.116.118011323-1.1.i586.rpm rpm -ivh heartbeat-pils-18.104.22.1688011323-1.1.i586.rpm rpm -ivh heartbeat-devel-22.214.171.1248011323-1.1.i586.rpm rpm -ivh heartbeat-stonith-126.96.36.1998011323-1.1.i586.rpm
Heartbeat increases business continuity and high availability by migrating disparate workloads onto virtual machines without interruption.
The following list summarizes the Heartbeat setup:
- Two nodes
- Active/passive configuration
- Use Heartbeat to determine health of the other node
- When failure on the primary node is detected, the other node takes over
Heartbeat detects a failure with the primary node and initiates failover by:
- Stopping DB2 on the primary node
- Releasing the shared disk
- Removing the service IP address on the primary node
- Adding the service IP address to the virtual machine
- Mounting the shared disk on the virtual machine
- Restarting DB2 on the virtual machine
You must configure the authkeys, ha.cf, and haresources to get Heartbeat working. For detailed information, refer to the Heartbeat Web site (see Resources).
The configuration files are identical on both nodes, so after configuring one node, copy the files to the other node. Don't forget to restart heartbeat after making changes to the configuration.
This file contains global configuration parameters for Heartbeat. It contains information about what nodes are in the HA cluster.
Listing 4. Configure /etc/ha.d/ha.cf
[root@vmlinux]# cd /etc/ha.d [root@vmlinux]# vi ha.cf ## /etc/ha.d/ha.cf on node1 ## This configuration is to be the same on both machines logfile /var/log/ha-log keepalive 2 deadtime 60 warntime 10 initdead 120 serial /dev/ttyS0 auto_failback yes node vmlinux node db2xen
The files contains the name of the node responsible for managing the resources. Listing 5 provides an example haresources file:
Listing 5. Example haresources file
vmlinux.test.com 188.8.131.52 Filesystem:: vmlinux.test.com:/data::/data::nfs::rw,hard db2::db2inst1
The above line in Listing 5 indicates that on startup of Heartbeat, vmlinux serves the cluster IP address, mounts the shared filesystem, and starts the database server. On shutdown, Heartbeat first stops the database server, then un-mounts the shared filesystem, and finally gives up the IP. Note that Heartbeat will look in /etc/rc.d/init.d and /etc/ha.d/resource.d for scripts.
The third file to configure determines your authentication keys. (For more
information on authentication keys, see
Resources.) There are three types of
authentication methods available: crc, md5, and sha1. For security
reasons, Heartbeat requires
/etc/ha.d/authkeys.. The format of
the file is as follows:
Listing 6. Format of authkeys file
auth <number> <number> <authmethod> [<authkey>]
Listing 7 shows an example authkeys file:
Listing 7. Example authkeys file
auth 3 3 md5 Hello!
Install DB2 and create an instance
Follow the steps below to install DB2 on both the primary node and the backup node (virtual machine):
- Log in as root user.
- Install DB2.
- Prepare the primary and standby nodes for DB2 instance creation.
- Create appropriate groups and users to manage the instance.
For group and user IDs, the values of the numerical group ID
(gid) and the user ID (uid) fields must match on both
Listing 8. Example values
groupadd -g 959 db2grp groupadd -g 958 db2fgrp groupadd -g 957 dasadm useradd -u 1007 -g db2grp -m -d /db2home/db2inst1 db2inst1 useradd -u 1008 -g db2fgrp -m -d /db2home/db2fenc1 db2fenc1 useradd -u 1009 -g dasadm -m -d /home/dasusr1 dasusr1
- Create appropriate groups and users to manage the instance. For group and user IDs, the values of the numerical group ID (gid) and the user ID (uid) fields must match on both machines.
- Create the instance.
Test the high availability
Follow the steps below to create a database xendb and test the high availability on both primary and virtual machines:
- Log on as user db2inst1 on primary node vmlinux:
su - db2inst1.
- Ensure that the DB2 instances are not started at boot time by using
db2inst1@vmlinux:~> cd sqllib/bin/ db2inst1@vmlinux:~/sqllib/bin> ./db2iauto -off db2inst1
- Make sure the DB2 Fault Monitor Coordinator is turned off:
db2inst1@vmlinux:~/sqllib/bin> tail -n 1 /etc/inittab #fmc:2345:respawn:/opt/IBM/db2/V8.FP15/bin/db2fmcd #DB2 Fault Monitor Coordinator
- Start DB2 on the primary node vmlinux:
db2inst1@vmlinux:~/sqllib/bin> db2start 06/19/2008 23:12:41 0 0 SQL1063N DB2START processing was successful
- Mount the file system /data on the primary node vmlinux:
mount /data (Execute as root user)
- Create a database xendb and test the connectivity:
Listing 9. Create a database xendb and test the connectivity
db2inst1@vmlinux:~> db2 create db xendb on /data DB20000I The CREATE DATABASE command completed successfully. db2inst1@vmlinux:~> db2inst1@vmlinux:~> db2 connect to xendb Database Connection Information Database server = DB2/LINUX 8.2.8 SQL authorization ID = DB2INST1 Local database alias = XENDB db2inst1@vmlinux:~> db2 connect reset DB20000I The SQL command completed successfully. db2inst1@vmlinux:~>
- Stop DB2 on node vmlinux:
Listing 10. Stop DB2 on node vmlinux
db2inst1@vmlinux:~> db2stop 06/19/2008 23:17:34 0 0 SQL1064N DB2STOP processing was successful. SQL1064N DB2STOP processing was successful.
- Mount the filesystem /data on the virtual machine node db2xen:
mount /data (Execute as user root user)
- Start DB2 on db2xen:
Listing 11. Start DB2 on db2xen
db2inst1@ db2xen:~> db2start 06/20/2008 00:07:39 0 0 SQL1063N DB2START processing was successful. SQL1063N DB2START processing was successful.
- Catalog the database xendb and check the connectivity:
Listing 12. Catalog the database xendb and check the connectivity
db2inst1@ db2xen:~> db2 catalog db xendb on /data DB20000I The CATALOG DATABASE command completed successfully. DB21056W Directory changes may not be effective until the directory cache is refreshed. db2inst1@ db2xen:~> db2 terminate DB20000I The TERMINATE command completed successfully. db2inst1@db2xen:~> db2 connect to xendb Database Connection Information Database server = DB2/LINUX 8.2.8 SQL authorization ID = DB2INST1 Local database alias = XENDB db2inst1@db2xen:~> db2 connect reset DB20000I The SQL command completed successfully. db2inst1@db2xen:~> db2stop 06/19/2008 23:17:34 0 0 SQL1064N DB2STOP processing was successful. SQL1064N DB2STOP processing was successful.
Testing DB2 failover using Heartbeat
In this section, learn how to test the high availability of the scheduling daemon.
- Start the Heartbeat service (execute as root user).
Note: This article recommends starting on the system primary vmlinux and then going to the virtual machine db2xen node.
- Check the database status by using the command in Listing 13:
Listing 13. Check the database status
db2inst1@vmlinux:~> db2 list active databases Active DatabasesDatabase name = XENDB Applications connected currently = 0 Database path = /data/db2inst1/NODE0000/SQL00001/
- To test the failover, stop heartbeat on the primary system as user
You should see all the services come up on the virtual machine in under a minute. You can verify that DB2 is running on the backup by checking the /var/log/ha-log file.
- Check the database status by using the following command:
Listing 14. Check the database status
db2inst1@db2xen:~> db2 list active databases Active DatabasesDatabase name = XENDB Applications connected currently = 0 Database path = /data/db2inst1/NODE0000/SQL00001/
Using DB2 high availability clusters on virtual machines increases server utilization by consolidating physical servers and applications, thus lowering hardware, maintenance, and electrical costs. This increases business continuity and system uptime by migrating disparate workloads onto virtual machines without interruption.
- Linux Heartbeat: Learn more about Heartbeat.
- Linux Heartbeat authorization keys: Learn more about Heartbeat authorization keys.
- Xen Hypervisor: Learn more about the powerful Xen Hypervisor.
- "IBM DB2 Express-C for Linux HOWTO" (Free Software Foundation, Inc., 2002): Follow this comprehensive guide for installing and using the IBM DB2 Express-C 9 database on a Linux operating system.
- developerWorks resource page for DB2 for Linux, UNIX, and Windows: Find articles and tutorials, and connect to other resources to expand your skills on DB2 for Linux, UNIX, and Windows.
- developerWorks Information Management zone: Learn more about Information Management. Find technical documentation, how-to articles, education, downloads, product information, and more.
- Stay current with developerWorks technical events and webcasts.
- Technology bookstore: Browse for books on these and other technical topics.
Get products and technologies
- DB2 Express-C: Download IBM DB2 Express-C, a free version of DB2 Express database server.
- DB2 for Linux, UNIX, and Windows: Download a trial version of DB2 for Linux, UNIX, and Windows. This trial includes DB2 Enterprise, DB2 Workgroup, DB2 Express, and DB2 Personal Edition, as well as the latest Visual Studio add-ins for DB2.
- Build your next development project with IBM trial software, available for download directly from developerWorks.
- Participate in the discussion forum.
- Participate in developerWorks blogs and get involved in the developerWorks community.