Introduction

Recently my company acquired DB2 for our SQL database. We chose DB2 over the other SQL databases even though DB2 is not widely know in the internet space. My boss sums up our decision to use DB2 like so: "Some SQL databases are like high performance cars -- you need great expensive mechanics to tweak them out. DB2 is like a Chevy v8 -- you can do it yourself and really make it haul".

While we have had great success with the DB2 on AIX. There is, as of yet, no known native port of DB2 to FreeBSD. This poses a considerable problem. I prefer FreeBSD over Linux for web serving. (I will not discuss why here.) So when we needed to roll out our application we were left with a decision to make: use Linux or wait. Since we had a deadline to meet, we decided to roll out our initial production database dependent servers on Linux. This way I could explore other possibilities at a more comfortable pace.

As FreeBSD has progressed over the years, the FreeBSD team decided to add support for Linux binaries. This happened early in the 2.x tree, and over the years this has progressed into a simple and almost transparent interface to run the Linux binaries. This cannot really be called emulation because it is a little more complex and much more elegant then that. If you are really interested and want to know more, please read the FreeBSD Handbook.

How to install the Linux compat

When you install FreeBSD you can enable the Linux compat right away. However if you already have a running system then you can either choose the port (build from source) or the package (already built). I decided to use the port, since I regularly cvsup the ports tree, so it might be more up-to-date than the package. If you need more information on cvsup, then please refer to the FreeBSD Handbook (look for "keeping up with FreeBSD"). Basically if you are familiar with the ports system then this should be very easy. Otherwise then do the following:
cd /usr/ports/emulators/linux_base
make && make install

This should install the base linux system into the /compat/linux directory. After that you need to decide whether or not you need support for development tools at this stage if you are developing complex programs that need to be compiled. You should still develop them on a running Linux system. This will be much easier to debug. Otherwise there is a port for Linux development tools in /usr/ports/devel/linux_devtools.

After you have installed the base Linux system. You still need to let the kernel know that you want to run Linux applications. Here again you have a choice. There is a kernel module that you enable by simply typing linux as root. Or you can compile in support. Since I know that I need this support all the time I chose to compile in support. Here are the kernel options:

      options         COMPAT_LINUX
      options         DEBUG_LINUX

I decided not to use the DEBUG_LINUX option since this was a production web server. Now if you chose to use the module then you can activate it on start up by adding the following line to /etc/rc.conf

 linux_enable="YES"

The last thing that you need to do is decide if your programs will need the Linux /proc file system. This can be activated either by an entry in /etc/fstab or by manually mounting it. The following entry in /etc/fstab should be fine.

      /proc                   /compat/linux/proc      linprocfs  rw   0       0

Installing DB2

The DB2 client is pretty sophisticated and uses a lot of commands on the installation that are not as of yet part of the linux_base system. So I would not try to install it onto a FreeBSD system using the Linux compat alone. I would instead install it onto a running Linux box then transfer over the files as needed. You can do all of this on the FreeBSD port of VMware (which I did) if you don't have a spare Linux box. What I did was the following:

This all sounds simple, but it is not that easy. DB2 has several directories that we found very important. First was the /usr/IBMdb2/ directory. This will hold the bulk of the installation. There is also a /usr/local/db2/ directory -- that for us -- housed the users' home directories. You need to pay close attention to the permissions on all of the files that you will find inside the /usr/local/db2//sqllib directory. Most of this is actually linked into the /usr/IBMdb2/ directory anyway.

When you install these directories onto the FreeBSD system you don't have to worry about putting them inside the /compat/linux directory. We were able to install them all into directories that mirrored the Linux installation exactly.

Once you have all the DB2 files installed onto the FreeBSD system and you have the support enabled for Linux you are ready to start the db2 client. The one thing that really took me a while to figure out was that /dev/null had to have permissions of 0666 otherwise the db2 client would not start. What it would do was hang around and finally time out. Why IBM decided to use /dev/null in a compiled binary is strange at best. So be careful and make sure that you adjust the permissions on /dev/null.

Also make sure that you set up the DB2 client to work and catalog the proper databases before you install onto FreeBSD. What DB2 does to store you database connection information is make the following directories inside the DB2 user's home.

 
/sqllib/sqlnodir/
/sqllib/sqldbdir/

Inside these two directories, there are some binary files that contain the proper node information as well as the database catalog information. I was unable to change these files from the db2 command prompt under the FreeBSD compat. So what I did instead is alter them when needed on Linux then tar them up and transfer them over. I imagine that this can be solved and eventually the ability to change these files from FreeBSD will happen in the near future.

Apache, PHP and Perl

I kept the Linux box that I used to install the DB2 on. This made it very easy to create our Apache server with the proper modules compiled in. For PHP we decided to compile in PHP and link against the DB2 libs (pretty much the default). We also follow the mod_perl default install. After we had all of our Perl modules and our Apache binary, I then just tar'd up the /usr/local/lib/perl and Apache directories. Granted their is a lot more to do for Apache and Perl. You should read their respective README's and installation instructions.

Performance and notes

At this point I could not wait to give it a run. After some initial setup we were off and running. I ran some simple tests on our application and everything ran perfectly. What amazed me was both that it worked and that I did not notice a loss of performance. After playing around for a while, I noticed that on Linux we could only run around 80 to 100 Apache processes before the box was max'ed out. This is due to our application and by no means Apache. Our application is extremely resource intensive and in many ways this is very good performance (all things considered). However on FreeBSD, I was able to run over 150 processes before the box was max'ed out. Both boxes had the exact same hardware and setup (besides the OS).

However, I cannot say with 100% certainty and it would be very difficult to make formal benchmarks. I can say that from a system admin standpoint. I cannot notice a loss of performance running the Linux Apache on FreeBSD. To be honest it almost seems to be faster running on FreeBSD.

Nathan Boeger is a senior system admin / systems developer for GetRelevant, a promotional Internet marketing company.