DB2 is one of the few industrial strength, fully featured database
systems that has a community edition available for free use. It
supports stored-procedures, and all the standard MySQL-esque features,
in addition to triggers and all sorts of data partitioning. And it even
ships with a full set of administrative GUI tools. Unfortunately,
nobody has taken the time to document the process of getting DB2
installed on Ubuntu Dapper (6.06 LTS). This is my attempt to do so and
save others some of the confusion that I went though getting it to work.
If you’re feeling adventurous, you can read the official DB2 9.1 documentation and the many, many DB2 Manuals available on IBMs site.
Getting DB2
There are a number of verions of DB2 available from IBM. Unless you
have usage requirements that demand advanced data replication,
partitioning, and clusteriing, the freely distributed Express-C
community version of DB2 should suffice. The only notable limitation
imposed by this version is a 2CPU/4GB Ram hardware constraint on the
physical host on which the software is installed. More information on
the varying DB2 versions, their features, and their constraints can be
found on the official IBM DB2 page. You can get DB2 Express-C at the IBM downloads page.
Installing DB2
The DB2 installation package is rpm-based, so we’ll need to install an
rpm-compatible installer for Ubuntu. For this, we apt-get alien, an rpm
package installer:
$ sudo apt-get install alien
Now we may db2_install installation script that is bundled with DB2. This needs to be done as root:
$ tar xzvf db2exc_91_LNX_x86.tar.gz
$ sudo exp/disk1/db2_install
This should take a few minutes to install. At the time of this
writing, the installation procedure had approximately ten steps and
lasted about three to five minutes. Note that depending on the version
of gcc that you have installed (if at all), you may need to install libstdc++5, as it is required for successful installation. This is easily obtained:
$ sudo apt-get install libstdc++5
Setting Up Groups/Users
Now that we have DB2 installed, we need to configure it for use. We
start by creating the standard DB2 user groups: instance owners, fenced
users, and administrators. (Note that these commands need to be run as
root — the sudo is dropped here for notational simplicity and a # is added in its place for clarity).
# groupadd -g 999 db2iadm1
# groupadd -g 998 db2fadm1
# groupadd -g 997 dasadm1
Now we’ll create a default user for each group:
# useradd -u 1002 -g dasadm1 -m -d /home/dasusr1 dasusr1 -p password2
# useradd -u 1003 -g db2fadm1 -m -d /home/db2fenc1 db2fenc1 -p password3
# useradd -u 1004 -g db2iadm1 -m -d /home/db2inst1 db2inst1 -p password4
Creating the Adminstrative Database
Now we need to create a DB2 Administration Server to administer all instances of DB2 under the purview of this installation:
# /opt/ibm/db2/V9.1/instance/dascrt -u dasusr1
Note here that dasusr1 may be any user that is a member of the dasadm1 group we set up earlier.
DB2 Instance Semantics. Creating an Instance.
A DB2 instance is an environment that acts as a logical container for a
collection of databases. It’s an abstraction that allows the creation
and usage of multiple independent DB2 environments using the same
physical resources.
We need an instance to hold all of our databases. We’l create a default instance using the db2inst1 user we just created as its owner:
# /opt/ibm/db2/V9.1/instance/db2icrt -u db2fenc1 db2inst1
As we noted, db2inst1 is the instance owner, while db2fenc1 credentials are used to execute fenced stored procedures and executables.
Starting and Stopping an Instance
A DB2 instance is an environment that acts as a logical container for a
collection of In order to start and stop the DB2 instance (remember, we
may have multiple instances for a given installation on a physical
host), we log in as the owner and call db2start after inializing the
DB2 environment:
$ su db2inst1
$. ~/sqllib/db2profile
$db2start
Stopping the environment is just as simple: we’d call db2stop instead of db2start.
You may enable (or disable) automatic DB2 instance start/stop on system start-up/shut-down by calling:
$ db2iauto -on db2inst1
where db2inst1 is the login name of the instance. Replacing the -on flag with -off disables this feature.
The Sample Database
If you wish to build the sample database bundled with DB2 in
order to play around, call db2sampl while logged into a DB2 instance
owner account:
$ su db2inst1
$ . ~/sqllib/db2profile
$ db2sampl
That’s It.
This concludes the bare-minimum needed to set up a working
DB2 environment on Ubuntu. Note that this configuration does not allow
for external connections over TCP/IP. We’d need to start a separate
service
References
[1] Official DB2 9.1 documentation
[2] DB2 Manuals
No comments:
Post a Comment
您的评论将使我blog更有动力~