Configure high availability DB2 for Linux, UNIX, and Windows clusters on virtual machines using Xen and Heartbeat

Implement DB2 HA Clusters on virtual machines

IBM® DB2® clusters on virtual machines (Xen) enable you to reap the benefits of utility computing and high availability. Virtual machines have become a key requirement for many enterprises. They help reduce the total cost of ownership and can be leveraged for development, testing, dynamic provisioning, high availability, no-downtime maintenance, and load balancing. In this article, learn all about how to configure and deploy DB2 high availability on Xen with Heartbeat.

Share:

Abhinay Nagpal (abhinaynagpal@in.ibm.com), DB2 Advanced Technical Support Analyst, IBM, Software Group

Abhinay NagpalAbhinay Nagpal is a DB2 advanced technical support analyst at IBM India Software Lab, Pune, where his main focus is assisting IBM DB2 customers worldwide.



Eldho Mathew (mathew.eldho@gmail.com), DB2 Advanced Technical Support Analyst, IBM, Software Group

Eldho MathewEldho Mathew is a DB2 advanced technical support analyst at IBM India Software Lab, Pune, where his main focus is assisting IBM DB2 customers worldwide. His areas of interest and expertise include down systems and performance tuning.



Gaurav Mehrotra (gaurav.mehrotra@in.ibm.com), DB2 Advanced Technical Support Analyst, IBM, Software Group

Gaurav MehrotraGaurav Mehrotra is working as a DB2 technical support analyst at IBM India Software Lab, Pune, where his main focus is assisting IBM DB2 customers worldwide.



11 December 2008

Introduction

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
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
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
Install the packages using YAST or other package manager

Create a virtual machine

Figure 4. Configure the virtual machine
Configure the virtual machine

Log in as root user on the virtual machine

Figure 5. Virtual machine — domU — running within host dom0
Virtual machine -- domU -- running within host dom0

Cluster configuration details

Listing 1. Configuration details
Node1 (Primary)		 vmlinux.test.com	9.182.205.90
Node2 (Virtual Machine)	 db2xen.test.com	9.182.205.91

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.

  1. Create a /data directory on both nodes.
  2. On vmlinux.test.com node, modify the /etc/exports file for sharing /data. For the setup in this article, we have added the following line: ./data 9.182.205.91(rw,sync,no_root_squash)
  3. Start the NFS services. If NFS is already running, you can run the command /usr/sbin/exportfs -ra to force nfsd to re-read the /etc/exports file.
  4. 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-2.1.3.2008011323-1.1.i586.rpm
rpm -ivh heartbeat-pils-2.1.3.2008011323-1.1.i586.rpm
rpm -ivh heartbeat-devel-2.1.3.2008011323-1.1.i586.rpm
rpm -ivh heartbeat-stonith-2.1.3.2008011323-1.1.i586.rpm

Configure Heartbeat

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.

Configure /etc/ha.d/ha.cf

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

Configure /etc/ha.d/haresources

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 9.182.205.100
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.

Configure /etc/ha.d/authkeys

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 chmod 600 /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):

  1. Log in as root user.
  2. Install DB2.
  3. Prepare the primary and standby nodes for DB2 instance creation.
    1. 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.
      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
  4. 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:

  1. Log on as user db2inst1 on primary node vmlinux:
    su - db2inst1.
  2. Ensure that the DB2 instances are not started at boot time by using the db2iauto utility :
    db2inst1@vmlinux:~> cd sqllib/bin/
    db2inst1@vmlinux:~/sqllib/bin> ./db2iauto -off db2inst1
  3. 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
  4. 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
  5. Mount the file system /data on the primary node vmlinux:
    mount /data  (Execute as root user)
  6. 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:~>
  7. 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.
  8. Mount the filesystem /data on the virtual machine node db2xen:
    mount /data  (Execute as user root user)
  9. 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.
  10. 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.

  1. 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.

    /etc/init.d/heartbeat start
  2. 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/
  3. To test the failover, stop heartbeat on the primary system as user root:

    /etc/rc.d/init.d/heartbeat stop

    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.
  4. 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/

Conclusion

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.

Resources

Learn

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.

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Information management on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management
ArticleID=358211
ArticleTitle=Configure high availability DB2 for Linux, UNIX, and Windows clusters on virtual machines using Xen and Heartbeat
publish-date=12112008