4.4. Setting Up a DB2 Service

This section provides an example of setting up a cluster service that fails over IBM DB2 Enterprise/Workgroup Edition on a cluster. This example assumes that NIS is not running on the cluster systems. To install the software and database on the cluster systems, follow these steps:

  1. On both cluster systems, log in as root and add the IP address and host name to be used to access the DB2 service to /etc/hosts file. For example:

    10.1.16.182     ibmdb2.class.example.com        ibmdb2
  2. Choose an unused partition on a shared disk to use for hosting DB2 administration and instance data, and create a file system on it. For example:

    mke2fs -j /dev/sda3
  3. Create a mount point on both cluster systems for the file system created in Step 2. For example:

    mkdir /db2home
  4. On the first cluster system, devel0, mount the file system created in Step 2 on the mount point created in Step 3. For example:

    mount -t ext3 /dev/sda3 /db2home
  5. On the first cluster system, devel0, mount the DB2 cdrom and copy the setup response file included in the distribution to /root. For example:

    mount -t iso9660 /dev/cdrom /mnt/cdrom
    cp /mnt/cdrom/IBM/DB2/db2server.rsp /root
  6. Modify the setup response file, db2server.rsp, to reflect local configuration settings. Make sure that the UIDs and GIDs are reserved on both cluster systems. For example:

    -----------Instance Creation Settings------------
    -------------------------------------------------
    DB2.UID = 2001
    DB2.GID = 2001
    DB2.HOME_DIRECTORY = /db2home/db2inst1
    
    -----------Fenced User Creation Settings----------
    --------------------------------------------------
    UDF.UID = 2000
    UDF.GID = 2000
    UDF.HOME_DIRECTORY = /db2home/db2fenc1
    
    -----------Instance Profile Registry Settings------
    ---------------------------------------------------
    DB2.DB2COMM = TCPIP
    
    ----------Administration Server Creation Settings---
    ----------------------------------------------------
    ADMIN.UID = 2002
    ADMIN.GID = 2002
    ADMIN.HOME_DIRECTORY = /db2home/db2as
    
    ---------Administration Server Profile Registry Settings-
    ---------------------------------------------------------
    ADMIN.DB2COMM = TCPIP
    
    ---------Global Profile Registry Settings-------------
    ------------------------------------------------------
    DB2SYSTEM = ibmdb2
  7. Start the installation. For example:

    cd /mnt/cdrom/IBM/DB2
    ./db2setup -d -r /root/db2server.rsp 1>/dev/null \
    	    2>/dev/null &
  8. Check for errors during the installation by examining the installation log file, /tmp/db2setup.log. Every step in the installation must be marked as SUCCESS at the end of the log file.

  9. Stop the DB2 instance and administration server on the first cluster system. For example:

    su - db2inst1
    db2stop
    exit
    su - db2as
    db2admin stop
    exit
  10. Unmount the DB2 instance and administration data partition on the first cluster system. For example:

    umount /db2home
  11. Mount the DB2 instance and administration data partition on the second cluster system, devel1. For example:

    mount -t ext3 /dev/sda3 /db2home
  12. Mount the DB2 CDROM on the second cluster system and remotely copy the db2server.rsp file to /root. For example:

    mount -t iso9660 /dev/cdrom /mnt/cdrom
    rcp devel0:/root/db2server.rsp /root
  13. Start the installation on the second cluster system, devel1. For example:

    cd /mnt/cdrom/IBM/DB2
    ./db2setup -d -r /root/db2server.rsp 1>/dev/null \
    	    2>/dev/null &
  14. Check for errors during the installation by examining the installation log file. Every step in the installation must be marked as SUCCESS except for the following:

    DB2 Instance Creation                              FAILURE
    Update DBM configuration file for TCP/IP           CANCEL
    Update parameter DB2COMM                           CANCEL
    Auto start DB2 Instance                            CANCEL
    DB2 Sample Database                                CANCEL
    Start DB2 Instance
    Administration Server Creation                     FAILURE
    Update parameter DB2COMM                           CANCEL
    Start Administration Serve                         CANCEL
  15. Test the database installation by invoking the following commands, first on one cluster system, and then on the other cluster system:

    mount -t ext2 /dev/sda3 /db2home
    su - db2inst1
    db2start
    db2 connect to sample
    db2 select tabname from syscat.tables
    db2 connect reset
    db2stop
    exit
    umount /db2home
  16. Create the DB2 cluster start/stop script on the DB2 administration and instance data partition. For example:

    #!/bin/sh
    #
    # IBM DB2 Database Cluster Start/Stop Script
    #
          
    DB2DIR=/usr/IBMdb2/V6.1
          
    case $1 in
    "start")
       $DB2DIR/instance/db2istrt
       ;;
    "stop")
       $DB2DIR/instance/db2ishut
       ;;
    esac

    Make sure the permissions of the file include being executable.

  17. Modify the /usr/IBMdb2/V6.1/instance/db2ishut file on both cluster systems to forcefully disconnect active applications before stopping the database. An example script to do this is as follows:

    for DB2INST in ${DB2INSTLIST?}; do
        echo "Stopping DB2 Instance "${DB2INST?}"..." >> ${LOGFILE?}
        find_homedir ${DB2INST?}
        INSTHOME="${USERHOME?}"
        su ${DB2INST?} -c " \
            source ${INSTHOME?}/sqllib/db2cshrc   1> /dev/null 2> /dev/null; \
                   ${INSTHOME?}/sqllib/db2profile 1> /dev/null 2> /dev/null; \
    >>>>>>> db2 force application all; \
            db2stop                              "  1>> ${LOGFILE?} 2>> ${LOGFILE?}
        if [ $? -ne 0 ]; then
            ERRORFOUND=${TRUE?}
        fi
    done
  18. Edit the inittab file and comment out the DB2 line to enable the cluster service to handle starting and stopping the DB2 service. This is usually the last line in the file. For example:

    db:234:once:/etc/rc.db2 > /dev/console 2>&1 # Autostart DB2 Services

Use the cluadmin utility to create the DB2 service. Add the IP address from Step 1, the shared partition created in Step 2, and the start/stop script created in Step 16.

To install the DB2 client on a third system, invoke these commands:

mount -t iso9660 /dev/cdrom /mnt/cdrom
cd /mnt/cdrom/IBM/DB2
./db2setup -d -r /root/db2client.rsp

To configure a DB2 client, add the service's IP address to the /etc/hosts file on the client system:

10.1.16.182   ibmdb2.class.example.com   ibmdb2

Then, add the following entry to the /etc/services file on the client system:

db2cdb2inst1      50000/tcp

Invoke the following commands on the client system:

su - db2inst1
db2 catalog tcpip node ibmdb2 remote ibmdb2 server db2cdb2inst1
db2 catalog database sample as db2 at node ibmdb2
db2 list node directory
db2 list database directory

To test the database from the DB2 client system, invoke the following commands:

db2 connect to db2 user db2inst1 using ibmdb2
db2 select tabname from syscat.tables
db2 connect reset