DB2 installation

From OpenVZ Virtuozzo Containers Wiki
Revision as of 05:57, 20 September 2010 by MaxZinal (talk | contribs) (Set VE resource limits appropriately)
Jump to: navigation, search

DB2 has been certified by IBM for use inside Virtuozzo. It works in OpenVZ too!

IBM provides a free download of DB2 Express-C which is what I installed.

Here is a rough guide to installing DB2 into a freshly-created VE.

Create a new VE

I created a new VE for the Debian distribution using debootstrap, as described in Debian template creation.

Set VE resource limits appropriately

DB2 installation can fail and it will not be possible to operate the database if your resource limits are too low. I used these limits for a small database:

  • kmemsize to 10,000,000
  • privvmpages to 300,000
  • shmpages to 80,000
  • numproc to 150
  • tcpsndbuf to 700,000
  • tcprcvbuf to 700,000
  • diskspace to 6,000,000
Warning.svg Warning: The above UBC values might not be consistent; see UBC consistency check.

These are tested resource limits for x86-64 system running Debian/GNU Linux 5.0.6 (the settings above did not work very well):

  • kmemsize to 26214400:29491200
  • privvmpages to 2097152:unlimited
  • shmpages to 1572864
  • numproc to 400
  • tcpsndbuf to 1720320:2703360
  • tcprcvbuf to 1720320:2703360
  • vmguardpages to 2097152:unlimited
  • oomguardpages to 26112:unlimited

And according to DB2 9 documentation, the following minimal guest kernel options must be set in /etc/sysctl.conf:

kernel.shmmax = 1073741824
kernel.sem = 250 256000  32 1024
kernel.msgmax = 65535
kernel.msgmnb = 65535

Install additional packages

  • libstdc++5 (required for installation)
  • pdksh (required for operation?)
  • ssh (may be required for operation)
  • xbase-clients (for xauth)
  • firefox (for post-installation)
  • strace and telnet (for debugging)
  • libdbi-perl gcc libc6-dev make (for building CPAN DBD::DB2 package)

Download the DB2 Express-C package

DB2 Express-C version 9 is available from this page: [[1]]

You will need to register with IBM before you can download.

  • Untar the received file as root
  • Run exp/disk1/db2setup
  • Follow the prompts:
    • Setup user 'dasusr1'
    • Setup user 'db2inst1' and database instance 'db2inst1'

Post-install actions

This is where it gets yukky. DB2 wants to run a browser inside the VE. It wants to run Java applets inside the browser. I installed Iceweasel, but the post-install script does not recognise it. I was eventually able to hack the script to recognise and use the browser but it crashed on one of the Java applets. I think you can get by without running the post-install.

Here's what to do instead:

First, su to the instance owner:

  • su - db2inst1

Try starting and stopping the database:

  • db2start
  • db2stop

If these don't work it means your environment variables are not set properly. IBM set these for me:

CLASSPATH=/home/db2inst1/sqllib/java/db2java.zip:/home/db2inst1/sqllib/java/db2jcc.jar:/home/db2inst1/sqllib/java/sqlj.zip:/home/db2inst1/sqllib/function:/home/db2inst1/sqllib/java/db2jcc_license_cu.jar:.
DB2INSTANCE=db2inst1
PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/home/db2inst1/sqllib/bin:/home/db2inst1/sqllib/adm:/home/db2inst1/sqllib/misc

Try creating IBM's sample database:

  • db2sampl

Setup a development environment

I develop in perl so I was most interested in access to the database though the DBI library. I did this:

  • Use CPAN to download and install DBD::DB2

If you don't use CPAN you can also do this (as root):

Setup DB2 for autostart

It seems that DB2 can be auto-started at VE boot time, but not auto-stopped. I used this script:

#!/bin/sh
#
# Script to start DB2 instances on bootup.
#

set -e

. /lib/lsb/init-functions

case "$1" in
start)
        echo Starting DB2
        /opt/ibm/db2/V9.1/instance/db2istrt
        ;;
stop)
        ;;
restart|reload)
        ;;
esac

exit 0

And I used this command to create the symlink to make it start at VE "boot" time:

update-rc.d db2 start 95 2 .

Testing your installation

From the db2inst1 user, do:

  • db2

Inside the db2 client, try:

connect to sample
grant dbadm on database to user fred
connect reset

Enjoy!

Please provide feedback in the discussion (Talk) page about improvements to this HOWTO.