Monday, November 7, 2011

Installing DB2 9 Express C on UBUNTU!

Posted by Shiva Gouraram | Monday, November 7, 2011 | Category: , , , |

Hi ,In this post i am going to explain how to install DB2 9 Express C on UBUNTU using command line interface.
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 sudoor 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 asDB2DIR
f) This article only shows configuring a single DB2 instance called db2inst1, bound to the instance owner (user) named db2inst1
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
  • cd expc
  • Optionally execute ./db2prereqcheck followed by (required)./db2_install. The db2prereqcheck simply will check your system requirements and quit, basically doing the same thing thatdb2_install does at startup, but db2_install will continue on to install if the pre requirements are met. (see next bullet).
  • 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 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
  • 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….
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 db2stopfollowed 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.
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
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 isdb2das1 and stop the db2 admin server by executing a db2admin stopcommand.
  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 auserdel USERNAME from the command line as root for each user as well as remembering to cleanup their home directories.
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.


Currently have 0 comments:

Leave a Reply