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.
- Via the process described below in detail, with the manual
db2_installmethod (and uninstall). - 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;
- db2 instance owner =
db2inst1 - db2 fence user =
db2fenc1 - 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:
- Login as root
- Go to IBM and download DB2 Express-C
- Save the tarball file in
/tmp/db2expc9 cd /tmp/db2expc9and extract the tarball withtar -xvzf the_db29_tarball_filename.tar.gzcd expc- Optionally execute
./db2prereqcheckfollowed by (required)./db2_install. Thedb2prereqchecksimply will check your system requirements and quit, basically doing the same thing thatdb2_installdoes at startup, butdb2_installwill 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 libaio.so.1 is not found on the systemOR you might get a warning statingCan'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 successfullyand 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...
- 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....)
- login as root
- Lets create the our single DB2 instance owner user by executing:
useradd -m db2inst1 - set a good password for this user with:
passwd db2inst1 - Create the db2 fenced user:
useradd -m db2fenc1 - Set a good password for this user with:
passwd db2fenc1 - Create the db2 admin server user:
useradd -m db2das1 - Set a good password for this user with:
passwd db2das1 - 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. - Ok, now we can create the actual usable db2 instance with the following command:
DB2DIR/instance/db2icrt -a server -u db2fenc1 db2inst1. - Now that the instance if created lets create some links with:
DB2DIR/cfg/db2ln - 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.
- As root, open up
/etc/servicesand add the following line at the end of the filedb2c_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) - Now lets logout
- Login as
db2inst1using the password you set earlier - execute a
db2stopfollowed by adb2start - 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/servicesabove. - The output should be "The update database manager command completed successfully". Execute a
db2stopfollowed by adb2start - 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/servicesfile. - Exit the db2 CLP prompt by typing
quit - Now lets fire up the actual TCP/IP communication by entering the following command:
db2set DB2COMM=tcpip, followed by adb2stopfollowed by adb2start - Verify that DB2 is listening on your port by typing
netstat -naand look for your port listed in the output. - 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.
- Login as db2inst1, the db2 instance owner
- execute a
db2 create database bitsoi - Connect with
db2 connect to bitsoi user db2inst1 - Enter the password
- You are now connected if you seee the "database connection information" output
- Fire up the CLP with
db2 - At the prompt type
create table myTest (name varchar(10)) - If successful, insert a record with
insert into myTest (name) values ('bitsofinfo') - Select it with
select * from myTest - Yeah, it works, exit with a
quitand when back at the command line typedb2 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.
- The steps below are a summary of the official document located here.
- Optionally backup, then DROP all of your databases, this is your call.. and at your own risk....
- Login as the db2 admin server owner, in our example case this is
db2das1and stop the db2 admin server by executing adb2admin stopcommand. - when completed logout
- login as root
- execute
DB2DIR/instance/dasdropto drop the das server instance - logout and login as the db2 instance owner
db2inst1 - execute a
db2stop force - execute a
db2 terminate - logout and login as root
- execute
DB2DIR/instance/db2idrop db2inst1to drop the our db2 instance - 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.
[...] if you are looking for a single document that is slightly more concise in nature, you can read this excellent step by step guide that was published today on the blog bits.of.info. Bookmark and [...]
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
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.
Thanks for the comments Philip, as I am getting feedback I’ll try to update the article to include some of these pointers.
[...] Via the db2_install manual method (command line) which is described in detail in my other article. [...]
cool blog
Its really a very helpful post.
It worked. That makes this the best I’ve read on the topic so far
Thank you.
Nice article … thanks =)
really good article, I managed to setup db2 express in no time
Thanks.
this document let’s me done.
[...] this is the time to remove DB2. I’m using DB2 Express-c and I have good direction on this link and another help [...]
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.
Thanks a lot, helped me out of the Redbook hell
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….
Great tutorial. Worked just fine on Ubuntu 11.04. Thanks!
Worked on Ubuntu 8.04 like a charm.
Thanks a lot!
Excellent tutorial. Worked on SUSE Linux Enterprise Server 11 SP 2. Thanks!
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….
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
Thanks 1,000,000 for this article. Much appreciated!