Installing and uninstalling DB2 9 express c on a headless Ubuntu/Redhat (RHEL) box (i.e. from the command line)

I’ve used DB2 for years and it has proved to be a rock solid database, that is stable, performs well, has awesome features like HADR for high availability and with the Express-C edition you can use it for your own projects free of charge…..however …one of the frustrating things I have always found is that something which in reality can be done fairly simply (headless install), is presented in such a complex fashion when you are reading the online DB2 documentation. As a user you have to waste all this time wading through DB2’s extensive online documentation which is presented in a format which seems to be catered towards full time DBAs who have the time to wade through link after link after reference after reference and on and on. They simply don’t have quick one page summaries that cover it all in simple straightforward HOWTOs . Secondly, if you want to install/uninstall DB2 on a headless machine via the command line (that being one without an X windows server), DB2 does not seem to provide any easy way to do that. (db2_install just installs files under /opt/ibm/…) The default automated tool that will install DB2, configure users and setup services etc, is the db2setup program which is a wizard app that requires as GUI by default, so if you are on a headless machine…. good luck and get ready to search online for help.

That said, there are two ways you can install DB2 via the command line without any sort of x-server.

  1. Via the process described below in detail, with the manual db2_install method (and uninstall).
  2. Via the db2setup -r [responsefile] method which is described in detail in my other article.

That said, this article is to present you with what is lacking: a simple straight forward HOWTO on how to install/uninstall DB2 (express-c 9 in particular) on a headless Ubuntu or Red Hat (RHEL) (server) box via the db2_install method from the command line only. I’ve included links to all the relevant DB2 docs so you don’t have to search around for them and secondly try to provide quick summaries of each step along the way.

Assumptions for this article:

a) The steps below were done with db2 Express-C 9.7 and on Ubuntu 9.04 Server edition, but the procedure should apply to other versions within the major versions quite well.

b) The steps below have also been executed on a headless Red Hat Enterprise 5.X (RHEL) server with no problem, so the procedures below will likely work for many other Linux distros as well.

c) This assumes you have root access to the machine, OR where root is referred to below, assumes a literally the user root OR a user with root authority through such means as sudo or other applicable permissions.

d) This assumes you have no previous DB2 installation, or if so, you have already properly removed it

d) This assumes the following usernames for the following DB2 users;

  1. db2 instance owner = db2inst1
  2. db2 fence user = db2fenc1
  3. db2 admin owner (das user) = db2das1

e) This assumes that DB2 will be installed in /opt/ibm/db2/V9.7 (or whatever the version is you are installing. This path will be referred to throughout the rest of this document as DB2DIR

f) This article only shows configuring a single DB2 instance called db2inst1, bound to the instance owner (user) named db2inst1

INSTALLATION

This section is a summary of the steps laid out at this official DB2 install document:

  1. Login as root
  2. Go to IBM and download DB2 Express-C
  3. Save the tarball file in /tmp/db2expc9
  4. cd /tmp/db2expc9 and extract the tarball with tar -xvzf the_db29_tarball_filename.tar.gz
  5. cd expc
  6. Optionally execute ./db2prereqcheck followed by (required) ./db2_install. The db2prereqcheck simply will check your system requirements and quit, basically doing the same thing that db2_install does at startup, but db2_install will continue on to install if the pre requirements are met. (see next bullet).
  7. Now at this point you may get one or more of the following errors or warnings saying something to the effect of The required library file libaio.so.1 is not found on the system OR you might get a warning stating Can't use the string to find the version of libstdc++. The solution to either of these errors/warnings, is to run the following commands:
    • apt-get install libaio1 (ubuntu)
    • apt-get install libstdc++5 (ubuntu)
    • yum install libstdc++ (rhel)
    • yum install libaio (rhel)

    After installing these 2 packages you may STILL get the warning about libstdc++ however just ignore than and run the following forced install with the command ./db2_install -f sysreq. If you still continue to get some sort of error please read the system requirements

  8. Assuming the install command completed successfully (check the output, at the end of the install process you should see The Execution completed successfully and review the install log located at /tmp/db2_install.log.XXXX). You now have the core db2 express c files installed under your DB2DIR which is /opt/ibm/db2/V9.7... however conveniently DB2 IS NOT READY to run, we still need to do more configuring....

CONFIGURING

Ok, now that you have the core db2 express C files installed under your DB2DIR /opt/ibm/db2/V9.7 it is time to manually do what a DB2 install program should be doing for you, you now get to act like a bash script and do all the things below manually, have fun...

  1. The steps below are a summary of this DB2 install document. In short we are going to create the required DB2 users, create the DB2 admin server instance, create our single usable DB2 instance, then configure DB2 to talk over TCP/IP (I feel like this is 1995....)
  2. login as root
  3. Lets create the our single DB2 instance owner user by executing: useradd -m db2inst1
  4. set a good password for this user with: passwd db2inst1
  5. Create the db2 fenced user: useradd -m db2fenc1
  6. Set a good password for this user with: passwd db2fenc1
  7. Create the db2 admin server user: useradd -m db2das1
  8. Set a good password for this user with: passwd db2das1
  9. Now we have our base users and we now need to create the db2 administration server instance with the command: DB2DIR/instance/dascrt -u db2das1.
  10. Ok, now we can create the actual usable db2 instance with the following command: DB2DIR/instance/db2icrt -a server -u db2fenc1 db2inst1.
  11. Now that the instance if created lets create some links with: DB2DIR/cfg/db2ln
  12. Awesome! We are almost there, but FIRST we must jump into our time machine and go back to the early 1990's when software was not really pre-configured to use TCP/IP for communications....as is DB2 by default... so lets configure it to talk via TCP/IP on a particular port.
  13. As root, open up /etc/services and add the following line at the end of the file db2c_db2inst1 3700/tcp # DB2 connection service port, (NOTE you can change the port to something other than the default if you want, i.e. security reasons)
  14. Now lets logout
  15. Login as db2inst1 using the password you set earlier
  16. execute a db2stop followed by a db2start
  17. Execute the following command to configure db2 to use the TCP/IP settings as follows: Bring up the db2 CLP with db2. Next type the following command in the CLP prompt: update database manager configuration using svcename db2c_db2inst1. REMEMBER to adjust the service name and port number accordingly if you used something different in your /etc/services above.
  18. The output should be "The update database manager command completed successfully". Execute a db2stop followed by a db2start
  19. Next you can verify that the TCP/IP comm settings took effect by typing (while still in the db2 clp prompt): get database manager config, in the resulting output you should see the "TCP/IP Service name" which matches the service name in your /etc/services file.
  20. Exit the db2 CLP prompt by typing quit
  21. Now lets fire up the actual TCP/IP communication by entering the following command: db2set DB2COMM=tcpip, followed by a db2stop followed by a db2start
  22. Verify that DB2 is listening on your port by typing netstat -na and look for your port listed in the output.
  23. Yeah! DB2 is now running on this box and you are good to go to begin creating databases etc. Remember to adjust your iptables firewall rules accordingly per your requirements to restrict access to only the hosts you want to permit.

VERIFY

Hey, lets create a basic database and verify we can use it to see that DB2 works.

  1. Login as db2inst1, the db2 instance owner
  2. execute a db2 create database bitsoi
  3. Connect with db2 connect to bitsoi user db2inst1
  4. Enter the password
  5. You are now connected if you seee the "database connection information" output
  6. Fire up the CLP with db2
  7. At the prompt type create table myTest (name varchar(10))
  8. If successful, insert a record with insert into myTest (name) values ('bitsofinfo')
  9. Select it with select * from myTest
  10. Yeah, it works, exit with a quit and when back at the command line type db2 terminate

UNINSTALLING

So you are probably thinking, "hey, how about we just run that db2_deinstall command?" Wrongo buddy, that would be way too obvious and easy. Instead we need to follow the steps below.

  1. The steps below are a summary of the official document located here.
  2. Optionally backup, then DROP all of your databases, this is your call.. and at your own risk....
  3. Login as the db2 admin server owner, in our example case this is db2das1 and stop the db2 admin server by executing a db2admin stop command.
  4. when completed logout
  5. login as root
  6. execute DB2DIR/instance/dasdrop to drop the das server instance
  7. logout and login as the db2 instance owner db2inst1
  8. execute a db2stop force
  9. execute a db2 terminate
  10. logout and login as root
  11. execute DB2DIR/instance/db2idrop db2inst1 to drop the our db2 instance
  12. Finally... now we get to actually run the deinstaller, as root execute DB2DIR/install/db2_deinstall -a

DB2 should now be completely removed, except for your users db2inst1, db2fence1 and db2dasusr1. You can optionally remove those by doing a userdel USERNAME from the command line as root for each user as well as remembering to cleanup their home directories.

SUMMARY

I hope this document helped you out. DB2 is a great product and don't let lack of thousands of user blog posts/articles/howtos etc. on the web scare you away from it. Please send any comments to improve this HOW TO my way.

Advertisements

27 comments

  1. Pingback: Installing and configuring DB2 Express-C 9.7 on Ubuntu 9.04 Server | Zen and the Art of Programming
    • venkat

      I have problem in running this command
      DB2DIR/instance/dascrt -u db2das1.
      Getting error ” dascrt not found”
      I am trying create db2 admin server and
      also trying create second instance of db2 using
      DB2DIR/instance/db2icrt -u db2inst2.
      getting error “db2icrt is not found”

      I installed V9.7 on UBUNTU 9.4 with DB2_install method from CD.

      Any help is greatly appreciated.

      thanks

      venkat

  2. Philip Nelson

    Thanks for the document. However there are a few issues with this approach (as I’ve discovered over the years since I wrote a similar article for IDUG Solutions Journal).

    Firstly, you will find that you only get a subset of the features installed. To get the rest you need to manually untar the appropriate packages into the install directory.

    You don’t get your admin server or tools database properly configured.

    It is fairly easy to still run ./db2setup via X forwarding (this becomes a real necessity when you get to installing hybrid products like Infosphere Warehouse which have DB2 and lots more).

    But assuming you don’t want to set up X, then I would always now recommend setting up a response file on another box using ./db2setup and then using that to do the install on the headless box. You use the “-r” option to achieve this. It doesn’t require X to be present at all.

    A couple of other comments –

    To determine what you are missing before install use ./db2prereqcheck rather than just running the install program and waiting for it to fail.

    One Ubuntu-specific issue you should address is how to get DB2 to autostart at system boot. DB2 puts a record into /etc/inittab, which works for almost every other Linux system. However Ubuntu doesn’t use inittab : they switched to use something else a few releases ago. I don’t have the details of how to set this up to hand at the moment but it would be good if you would include this in your doc, so that folks don’t wonder why they can’t access DB2 after a reboot.

    • bitsofinfo

      Thanks for the comments Philip, as I am getting feedback I’ll try to update the article to include some of these pointers.

  3. Pingback: Installing db2 9 express-c on a headless Ubuntu box with db2setup and a response file « bits.of.info
  4. Pingback: [ubuntu 11.04 on my asus f2je - uninstalling DB2] « capricornday’s Blog
  5. walter

    Hey dude, i have some pics of my virtual machine (it’s a ubuntu server)
    if you wanna some pics, send me an email and i send the pics url or pics.

  6. Arpit Gaur

    best article i ever read on installing db2 on ubuntu… i installed db2 9.7 expc on ubuntu 11.04 and the process went so smooth… thanks a lot for the article…. πŸ™‚ πŸ™‚

  7. devzee

    I installed db2 express-c 10.1 for my university project in ubuntu 11.10 by using graphical installation wizard. I was able to use db2 from command line but was failed to use it from ibm data studio. It was giving some connection refused error. I followed the tcp/ip connection setup of your article and it solved my problem. thanks, thanks a lot πŸ™‚ very helpful article….

  8. Aman Singh

    I installed ubuntu with “install inside windows” option….now i want to install ibm db2 inside this ubuntu (which is already installed inside windows)……how and what am i supposed to do? The las time i tried…..it turned out that some error came up i couldn’t move ahead with the installation. Please help…….waiting for reply urgrently. Thnx in advance πŸ™‚

  9. Pingback: Building a LAMP Test Bed Part 4d – DB2 | Supreme Ruler of Earth
  10. Tobias Lang

    Very helpful, thanks you. I just verified this with a current Ubuntu 12.04 (on an Intel 64bit architecture, MacPro VMWare).

  11. Pingback: Creating LAMP Test Bed – Other Databases | Supreme Ruler of Earth

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s