Configuring DB2 Universal Database (UDB) 7.1 for use with WebSphere Application Server

This article describes how to do the following:

The procedures in this article assume that DB2 is installed in the default location /opt/IBMdb2/V7.1 and that any required FixPak is installed.

Creating a database instance and administration server

  1. Ensure that you are logged into the machine with superuser (root) privileges.
  2. Create home directories for the DB2 Instance, DB2 Fenced User, and DB2 Administration Server. These directory names must match the values for the Home Directory option that you designate when configuring the DB2 Instance, DB2 Fenced User, and DB2 Administration Server in the procedures listed under Steps 7, 8, and 14.
  3. Navigate to the directory containing the DB2 Setup Utility by entering the following command:
    # cd /opt/IBMdb2/V7.1/install
  4. Start the DB2 Setup Utility by entering the following command:
    # ./db2setup
  5. Highlight the Create button beside the option labeled To create a DB2 Instance, an Administration Server, or a Data Links Manager Administrator select Create and press Return.
  6. In the Create DB2 Services window, highlight the Create a DB2 Instance option and press Return.
  7. In the DB2 Instance window, perform the following steps, noting the values that you enter or accept for future reference:
    1. Enter a user name or accept the default value for the User Name option. You will specify this user name when you configure WebSphere Application Server.
    2. Enter a user ID or accept the default user ID by ensuring that the Use default UID option has an asterisk (*) beside it.
    3. Enter a group name or accept the default value for the Group Name option.
    4. Enter a group ID or accept the default group ID by ensuring that the Use default GID option has an asterisk (*) beside it.
    5. Enter a home directory or accept the default value for the Home Directory option. You will specify this directory when you configure WebSphere Application Server.
    6. Type a password for the user in the Password and Verify Password options. DB2 requires a password of eight or fewer characters. You will specify this password when you configure WebSphere Application Server.
    7. Highlight OK and press Return.
  8. In the Fenced User window, perform the following steps, noting the values that you enter or accept for future reference:
    1. Enter a user name or accept the default value for the User Name option.
    2. Enter a user ID or accept the default user ID by ensuring that the Use default UID option has an asterisk (*) beside it.
    3. Enter a group name or accept the default value for the Group Name option.
    4. Enter a group ID or accept the default group ID by ensuring that the Use default GID option has an asterisk (*) beside it.
    5. Enter a home directory or accept the default value for the Home Directory option.
    6. Type a password for the user in the Password and Verify Password options. DB2 requires a password of eight or fewer characters.
    7. Highlight OK and press Return.
  9. In the DB2 Warehouse Control Database window, highlight the option labeled Do not set up DB2 Warehouse Control Database and press Return.
  10. Highlight OK and press Return.
  11. In the DB2 Distributed Join for DB2 Data Sources window, highlight the option labeled Do not set up DB2 Distributed Join for DB2 Data Sources and press Return.
  12. Highlight OK and press Return.
  13. In the Create DB2 Services window, highlight the Create the Administration Server option and press Return.
  14. In the Administration Server window, perform the following steps, noting the values that you enter or accept for future reference:
    1. Enter a user name or accept the default value for the User Name option.
    2. Enter a user ID or accept the default user ID by ensuring that the Use default UID option has an asterisk (*) beside it.
    3. Enter a group name or accept the default value for the Group Name option.
    4. Enter a group ID or accept the default group ID by ensuring that the Use default GID option has an asterisk (*) beside it.
    5. Enter a home directory or accept the default value for the Home Directory option.
    6. Type a password for the user in the Password and Verify Password options. DB2 requires a password of eight or fewer characters.
    7. Highlight OK and press Return.
  15. A notice window informs you of the value being created for the DB2SYSTEM environment variable. Ensure that OK is highlighted and press Return.
  16. In the Create DB2 Services window, highlight OK and press Return.
  17. The Summary Report window summarizes the choices you have made so far. When you have determined that the information is correct, ensure that Continue is highlighted and press Return.
  18. A warning window opens, giving you the option of canceling the processes. Ensure that OK is highlighted and press Return.
  19. A notice window informs you when the processes are completed. Ensure that OK is highlighted and press Return.
  20. The Status Report window informs you of process successes and failures. View the Log File for information on how to correct particular failures. To exit from this window, ensure that OK is highlighted and press Return.
  21. In the DB2 Setup Utility window, highlight Close and press Return.
  22. In the notice window, ensure that OK is highlighted and press Return.
  23. Make the root user a member of the administrative group that you accepted or designated for the Group Name option during the creation of the Administrative Server in Step 14 by editing the /etc/group file.
  24. If you are developing or running applications and want to avoid specifying the full path to the product libraries and include files, consider creating symbolic links. Create symbolic links for the DB2 files to the /usr/lib directory and for the include files to the /usr/include directory by entering the following command:
    # /opt/IBMdb2/V7.1/cfg/db2ln
  25. Configure the instance owner (the value that you accepted or designated for the User Name option in Step 7, in this example, db2inst1) to run the db2profile script at login, by doing one of the following:
  26. Configure the root user to run the db2profile script at login. You can find this script in the directory /export/home/db2inst1/sqllib (assuming that /export/home/db2inst1 is the home directory of the example instance owner db2inst1). This action is required to install and run WebSphere Application Server.
  27. Log out and then log back in for your changes to take effect.

Verifying the installation of DB2 UDB 7.1

To demonstrate that DB2 is functioning correctly, create a sample database and then compile and execute a Java application that accesses this database. To create a sample database and compile and run the Java application, perform the following steps:

  1. Log in as the DB2 instance owner (the value that you accepted or designated for the User Name option in Step 7 in the procedure in the section "Creating a database instance and administration server"). Logging in as the instance owner places you automatically in the home directory of the instance owner. The command prompt changes in appearance to indicate the change in your login identity.
  2. Ensure that your DISPLAY and TERM environment variables are set properly.
  3. To ensure that the DB2 environment has been set up correctly, search the environment for the value of the DB2INSTANCE environment variable by entering the following command. The value returned must be the instance owner name (the value that you accepted or designated for the User Name option in Step 7 in the procedure in the section "Creating a database instance and administration server"):
    $ env | grep DB2INSTANCE
  4. Create the sample database by executing the db2sampl script, as follows. This process can take several minutes to complete.
    $ db2sampl
  5. Ensure that you are in the home directory of the instance owner (in this example, /export/home/db2inst1) and compile an example Java application by using the javac command, as follows:
    $ javac -d . sqllib/samples/java/DB2Appl.java

    The resulting class file is created in the local directory.

  6. Ensure that DB2 is running or start it by entering the following command:
    $ db2start
  7. Execute the sample by using the java command, as follows:
    $ java DB2Appl

    Your output appears like the following:

    Retrieve some data from the database... 
    Received results: 
     empno= 000010 firstname= CHRISTINE 
     empno= 000020 firstname= MICHAEL 
     empno= 000030 firstname= SALLY 
     . . .
    Update the database... 
    Changed 1 row.
  8. If you want to stop DB2, enter the following command:
    $ db2stop
  9. To log out as the DB2 instance owner, enter the following command:
    $ exit

    The DB2 server remains active unless you stop it as detailed in Step 8.

Creating and configuring a database for WebSphere Application Server

In order for WebSphere Application Server to store the administrative configuration, you must create a database on the database server node. The database name will be the same one (or alias) used for the JDBC URL entry name during the WebSphere Application Server installation. Perform the following steps to create a database named was and set the DB2 application heap size:

  1. Log in as the DB2 instance owner (the value that you accepted or designated for the User Name option in Step 7 in the procedure in the section "Creating a database instance and administration server"). Logging in as the instance owner places you automatically in the home directory of the instance owner. The command prompt changes in appearance to indicate the change in your login identity.
  2. Ensure that your DISPLAY and TERM environment variables are set properly.
  3. To ensure that the DB2 environment has been set up correctly, search the environment for the value of the DB2INSTANCE environment variable by entering the following command. The value returned must be the instance owner name (the value that you accepted or designated for the User Name option in Step 7 in the procedure in the section "Creating a database instance and administration server"):
    $ env | grep DB2INSTANCE
  4. Ensure that DB2 is running or start it by entering the following command:
    $ db2start
  5. Enter the following command to create a database named was. This process can take several minutes to complete.
    $ db2 create database was
  6. Enter the following command to set the application heap size:
    $ db2 update db config for WAS using applheapsz 256
  7. If you want to stop DB2, enter the following command:
    $ db2stop
  8. To log out as the DB2 instance owner, enter the following command:
    $ exit

    The DB2 server remains active unless you stop it as detailed in Step 7.

  9. Restart your machine for your changes to take effect. If an application heap size of 256 does not work for your system, increase the size to 512.

Configuring the database manager to use TCP/IP

It is recommended that you configure the database manager to use TCP/IP to connect to WebSphere Application Server remotely. Because you are using a local DB2 database with WebSphere Application Server (both DB2 and WebSphere Application Server are installed on the same machine), you will perform all of the steps in the following procedure on the same machine.

Perform the following steps to configure the database manager to use TCP/IP to connect to WebSphere Application Server remotely:

  1. Ensure that you are logged into the machine with superuser (root) privileges.
  2. Ensure that your DISPLAY and TERM environment variables are set properly.
  3. Use a text editor to open the /etc/services file. If it does not specify DB2 connection and interrupt service ports, add the following text to specify the ports:
    server1     50000/tcp  # DB2 connection service port
    server1i    50001/tcp  # DB2 interrupt connection service port
  4. Log in as the DB2 instance owner (the value that you accepted or designated for the User Name option in Step 7 in the procedure in the section "Creating a database instance and administration server"). In this example, the DB2 instance owner name is db2inst1.
    # su - db2inst1

    Logging in as the instance owner places you automatically in the home directory of the instance owner. The command prompt changes in appearance to indicate the change in your login identity.

  5. Ensure that your DISPLAY and TERM environment variables are set properly.
  6. Set DB2COMM to TCP/IP by using the db2set command, as follows:
    $ db2set DB2COMM=tcpip
  7. Update the database manager configuration by using the db2 update command, as follows:
    $ db2 update dbm cfg using svcename DB2_connection_service_port

    In this command, DB2_connection_service_port represents the name of the DB2 connection service port you specified in the /etc/services file (for example, server1).

  8. Catalog the TCP/IP node by using the db2 catalog command, as follows:
    $ db2 catalog tcpip node WASNODE remote host_name \
    server DB2_connection_service_port

    In this command, host_name represents the client machine name or IP address and DB2_connection_service_port represents the DB2 connection service port server name or port number you specified in the /etc/services file (for example, server1 or 50000).

  9. Catalog the database by using the db2 catalog command, as follows:
    $ db2 catalog database was as wasAlias at node WASNODE
  10. Stop and start DB2 for your changes to take effect by using the db2stop and db2start commands, as follows:
    $ db2stop
    $ db2start
  11. To log out as the DB2 instance owner, enter the following command:
    $ exit

    The DB2 server remains active unless you stop it by using the db2stop command.

Verifying connection to the was database

Perform the following steps to verify connection to the was database:

  1. Log in as the DB2 instance owner (the value that you accepted or designated for the User Name option in Step 7 in the procedure in the section "Creating a database instance and administration server"). Logging in as the instance owner places you automatically in the home directory of the instance owner. The command prompt changes in appearance to indicate the change in your login identity.
  2. Ensure that your DISPLAY and TERM environment variables are set properly.
  3. To ensure that the DB2 environment has been set up correctly, search the environment for the value of the DB2INSTANCE environment variable by entering the following command. The value returned must be the instance owner name (the value that you accepted or designated for the User Name option in Step 7 in the procedure in the section "Creating a database instance and administration server"):
    $ env | grep DB2INSTANCE
  4. Ensure that DB2 is running or start it by entering the following command:
    $ db2start
  5. Connect to the was database by entering the following command:
    $ db2 connect to was

    Your output appears like the following (assuming an instance name of db2inst1):

    Database Connection Information
    
         Database server        = DB2/SUN 7.1.0  
         SQL authorization ID   = DB2INST1
         Local database alias   = WAS
  6. If you want to stop DB2, enter the following command:
    $ db2stop
  7. To log out as the DB2 instance owner, enter the following command:
    $ exit

    The DB2 server remains active unless you stop it as detailed in Step 6.