DEV Community

Cover image for Setting up IBM Db2 Community Edition on Amazon EC2 (Ubuntu)
Unni P
Unni P

Posted on • Originally published at iamunnip.hashnode.dev

Setting up IBM Db2 Community Edition on Amazon EC2 (Ubuntu)

In this article we will look how we can install IBM Db2 community edition on Amazon EC2 Ubuntu instance

Introduction

  • Db2 is a cloud-native database

  • Low latency transactions and highly resilient

  • Supports structured and unstructured data

  • Entry-level edition of the Db2 data server for the developer and partner community

  • Available for Linux, Windows, and AIX and also available as a Docker image

  • Supports all core Db2 features

  • Up to 4 cores and 16 GB RAM

  • Always-on security

  • Db2 Community support

Prerequisites

  • Setup an EC2 instance of type t2.medium

  • Ubuntu 20.04 LTS as AMI

  • 30 GB of hard disk space

  • Open port 22 for SSH and 25000 for Db2

  • Create an IBM account for downloading the Db2 community edition

Installation

  • Login to your EC2 instance and verify the distribution version
$ ssh -i ibm-db2.pem ubuntu@54.234.180.34 
Enter fullscreen mode Exit fullscreen mode
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.6 LTS Release: 20.04 Codename: focalDownload and extract Db2 community edition tarball on EC2 instance You can download the community edition from this URL 
Enter fullscreen mode Exit fullscreen mode
  • Download the latest IBM Db2 Linux (x64) version on your local machine

  • Once the download is completed, copy the downloaded file to your EC2 instance

$ scp -i ibm-db2.pem v11.5.8_linuxx64_server_dec.tar.gz ubuntu@54.234.180.34:/home/ubuntu $ pwd /home/ubuntu $ ls v11.5.8_linuxx64_server_dec.tar.gz 
Enter fullscreen mode Exit fullscreen mode
  • Extract the tarball in your home directory
$ tar -xzvf v11.5.8_linuxx64_server_dec.tar.gz $ ls server_dec v11.5.8_linuxx64_server_dec.tar.gz 
Enter fullscreen mode Exit fullscreen mode
  • Move to the extracted directory and execute db2prereqcheck command This will check the prerequisite requirements for installing Db2
$ cd server_dec $ ls db2 db2_deinstall db2_install db2checkCOL.tar.gz db2checkCOL_readme.txt db2ckupgrade db2ls db2prereqcheck db2setup installFixPack 
Enter fullscreen mode Exit fullscreen mode
$ sudo ./db2prereqcheck ========================================================================== Sun Apr 30 04:51:27 2023 Checking prerequisites for DB2 installation. Version "11.5.8.0". Operating system "Linux" Validating "kernel level " ... Required minimum operating system kernel level: "3.10.0". Actual operating system kernel level: "5.15.0". Requirement matched. Validating "Linux distribution " ... Required minimum "UBUNTU" version: "16.04" Actual version: "20.04" Requirement matched. Validating "ksh symbolic link" ... WARNING : Requirement not matched. ERROR: The 'strings' utility that is used to detect prerequisite libraries is not present on this system. Please use your package or software manager to install the GNU Binary Utilities. Validating "C++ Library version " ... Required minimum C++ library: "libstdc++.so.6" Standard C++ library is located in the following directory: "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28". DBT3512W The db2prereqcheck utility failed to determine the currently-installed version of the C++ standard library, libstdc++. Requirement matched. Validating "libaio.so version " ... DBT3553I The db2prereqcheck utility successfully loaded the libaio.so.1 file. Requirement matched. Validating "libnuma.so version " ... DBT3610I The db2prereqcheck utility successfully loaded the libnuma.so.1 file. Requirement matched. Validating "/lib/i386-linux-gnu/libpam.so*" ... DBT3514W The db2prereqcheck utility failed to find the following 32-bit library file: "/lib/i386-linux-gnu/libpam.so*". WARNING : Requirement not matched. Requirement not matched for DB2 database "Server" . Version: "11.5.8.0". Summary of prerequisites that are not met on the current system: DBT3514W The db2prereqcheck utility failed to find the following 32-bit library file: "/lib/i386-linux-gnu/libpam.so*". DBT3619W The db2prereqcheck utility detected that ksh is not linked to ksh or ksh93. This is required for Db2 High Availability Feature with Tivoli SA MP. 
Enter fullscreen mode Exit fullscreen mode
  • From the above output, we can see the requirement checks are failed and we need to fix them

  • Enable 32-bit architecture on your instance and install the required packages

$ sudo dpkg --add-architecture i386 $ sudo apt update $ sudo apt install -y ksh ksh93 lib32stdc++6 libpam0g:i386 binutils 
Enter fullscreen mode Exit fullscreen mode
  • Once the required packages are installed, rerun the db2prereqcheck command again and verify all the requirements are matched
$ sudo ./db2prereqcheck ========================================================================== Sun Apr 30 04:55:30 2023 Checking prerequisites for DB2 installation. Version "11.5.8.0". Operating system "Linux" Validating "kernel level " ... Required minimum operating system kernel level: "3.10.0". Actual operating system kernel level: "5.15.0". Requirement matched. Validating "Linux distribution " ... Required minimum "UBUNTU" version: "16.04" Actual version: "20.04" Requirement matched. Validating "ksh symbolic link" ... Requirement matched. Validating "C++ Library version " ... Required minimum C++ library: "libstdc++.so.6" Standard C++ library is located in the following directory: "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28". Actual C++ library: "CXXABI_1.3.1" Requirement matched. Validating "32 bit version of "libstdc++.so.6" " ... Found the 64 bit "/lib/x86_64-linux-gnu/libstdc++.so.6" in the following directory "/lib/x86_64-linux-gnu". Found the 32 bit "/lib32/libstdc++.so.6" in the following directory "/lib32". Requirement matched. Validating "libaio.so version " ... DBT3553I The db2prereqcheck utility successfully loaded the libaio.so.1 file. Requirement matched. Validating "libnuma.so version " ... DBT3610I The db2prereqcheck utility successfully loaded the libnuma.so.1 file. Requirement matched. Validating "/lib/i386-linux-gnu/libpam.so*" ... Requirement matched. DBT3533I The db2prereqcheck utility has confirmed that all installation prerequisites were met. 
Enter fullscreen mode Exit fullscreen mode
  • Multiple installation methods available for Db2 for specific use cases

  • We are going to install Db2 using db2_install command as root user and wait for the installation to complete

$ sudo ./db2_install Read the license agreement file in the db2/license directory. *********************************************************** To accept those terms, enter "yes". Otherwise, enter "no" to cancel the install process. [yes/no] yes Default directory for installation of products - /opt/ibm/db2/V11.5 *********************************************************** Install into default directory (/opt/ibm/db2/V11.5) ? [yes/no] yes Specify one of the following keywords to install DB2 products. SERVER CONSV CLIENT RTCL Enter "help" to redisplay product names. Enter "quit" to exit. *********************************************************** SERVER *********************************************************** Do you want to install the DB2 pureScale Feature? [yes/no] no DB2 installation is being initialized. 
Enter fullscreen mode Exit fullscreen mode
  • Once the installation is completed, you will see the below message and we can check the installation log file for post-installation steps
The execution completed successfully. For more information see the DB2 installation log at "/tmp/db2_install.log.5295". 
Enter fullscreen mode Exit fullscreen mode
$ cat /tmp/db2_install.log.5295 Post-installation instructions ------------------------------- Required steps: Set up a DB2 instance to work with DB2. Optional steps: Notification SMTP server has not been specified. Notifications cannot be sent to contacts in your contact list until this is specified. For more information see the DB2 administration documentation. To validate your installation files, instance, and database functionality, run the Validation Tool, /opt/ibm/db2/V11.5/bin/db2val. For more information, see "db2val" in the DB2 Information Center. 
Enter fullscreen mode Exit fullscreen mode
  • Let’s validate our installation by executing the db2val command and verify the log file We can see that everything is OK
$ sudo /opt/ibm/db2/V11.5/bin/db2val DBI1379I The db2val command is running. This can take several minutes. DBI1335I Installation file validation for the DB2 copy installed at /opt/ibm/db2/V11.5 was successful. DBI1343I The db2val command completed successfully. For details, see the log file /tmp/db2val-230430_051357.log. 
Enter fullscreen mode Exit fullscreen mode
$ cat /tmp/db2val-230430_051357.log Installation file validation for the DB2 copy installed at "/opt/ibm/db2/V11.5" starts. Task 1: Validating Installation file sets. Status 1 : Success Task 2: Validating embedded runtime path for DB2 executables and libraries. Status 2 : Success Task 3: Validating the accessibility to the installation path. Status 3 : Success Task 4: Validating the accessibility to the /etc/services file. Status 4 : Success DBI1335I Installation file validation for the DB2 copy installed at /opt/ibm/db2/V11.5 was successful. Installation file validation for the DB2 copy installed at "/opt/ibm/db2/V11.5" ends. DBI1343I The db2val command completed successfully. For details, see the log file /tmp/db2val-230430_051357.log. 
Enter fullscreen mode Exit fullscreen mode

Post Installation

  • Create required groups for Db2
$ sudo groupadd -g 998 db2iadm1 $ sudo groupadd -g 997 db2fsdm1 $ sudo groupadd -g 996 dasadm1 
Enter fullscreen mode Exit fullscreen mode
  • Create required users for Db2
$ sudo useradd -u 1004 -g db2iadm1 -m -d /home/db2inst1 db2inst1 $ sudo useradd -u 1003 -g db2fsdm1 -m -d /home/db2fenc1 db2fenc1 $ sudo useradd -u 1002 -g dasadm1 -m -d /home/dasusr1 dasusr1 
Enter fullscreen mode Exit fullscreen mode
  • Set passwords for users
$ sudo passwd db2inst1 New password: Retype new password: passwd: password updated successfully $ sudo passwd db2fenc1 New password: Retype new password: passwd: password updated successfully $ sudo passwd dasusr1 New password: Retype new password: passwd: password updated successfully 
Enter fullscreen mode Exit fullscreen mode
  • Create an instance for Db2 using db2icrt command and verify the log file for information about connecting to the database
$ sudo /opt/ibm/db2/V11.5/instance/db2icrt -a server -u db2fenc1 db2inst1 DBI1446I The db2icrt command is running. DB2 installation is being initialized. Total number of tasks to be performed: 4 Total estimated time for all tasks to be performed: 309 second(s) Task #1 start Description: Setting default global profile registry variables Estimated time 1 second(s) Task #1 end Task #2 start Description: Initializing instance list Estimated time 5 second(s) Task #2 end Task #3 start Description: Configuring DB2 instances Estimated time 300 second(s) Task #3 end Task #4 start Description: Updating global profile registry Estimated time 3 second(s) Task #4 end The execution completed successfully. For more information see the DB2 installation log at "/tmp/db2icrt.log.85927". DBI1070I Program db2icrt completed successfully. 
Enter fullscreen mode Exit fullscreen mode
$ cat /tmp/db2icrt.log.85927 Required steps: You can connect to the DB2 instance "db2inst1" using the port number "25000". Record it for future reference. 
Enter fullscreen mode Exit fullscreen mode
  • Let’s start the database instance using the below commands
$ sudo su - db2inst1 $ db2ls Install Path Level Fix Pack Special Install Number Install Date Installer UID --------------------------------------------------------------------------------------------------------------------- /opt/ibm/db2/V11.5 11.5.8.0 0 Sun Apr 30 05:08:04 2023 UTC 0 
Enter fullscreen mode Exit fullscreen mode
$ . sqllib/userprofile $ db2ilist db2inst1 $ db2start 04/30/2023 05:36:30 0 0 SQL1063N DB2START processing was successful. SQL1063N DB2START processing was successful. 
Enter fullscreen mode Exit fullscreen mode
  • Now the database instance is started and we can connect to the instance
$ db2 (c) Copyright IBM Corporation 1993,2007 Command Line Processor for DB2 Client 11.5.8.0 You can issue database manager commands and SQL statements from the command prompt. For example: db2 => connect to sample db2 => bind sample.bnd For general help, type: ?. For command help, type: ? command, where command can be the first few keywords of a database manager command. For example: ? CATALOG DATABASE for help on the CATALOG DATABASE command ? CATALOG for help on all of the CATALOG commands. To exit db2 interactive mode, type QUIT at the command prompt. Outside interactive mode, all commands must be prefixed with 'db2'. To list the current command option settings, type LIST COMMAND OPTIONS. For more detailed help, refer to the Online Reference Manual. db2 => 
Enter fullscreen mode Exit fullscreen mode
  • Create a test database and connect to the database using the below commands
db2 => create database ibm DB20000I The CREATE DATABASE command completed successfully. db2 => connect to ibm Database Connection Information Database server = DB2/LINUXX8664 11.5.8.0 SQL authorization ID = DB2INST1 Local database alias = IBM 
Enter fullscreen mode Exit fullscreen mode
  • Enable automatic start of database instance after reboot Execute the below commands as db2inst1 user
$ db2greg -getinstrec instancename='db2inst1' Retrieved record: Service = |DB2| Version = |11.5.8.0| InstanceName = |db2inst1| InstancePath = |/home/db2inst1/sqllib| Usage = |N/A| StartAtBoot = 1 Maintenance = 0 InstallPath = |/opt/ibm/db2/V11.5| RemoteProf = |N/A| Comment = |N/A| $ db2iauto -on db2inst1 
Enter fullscreen mode Exit fullscreen mode
  • Reboot the EC2 instance and verify the Db2 process
$ sudo su - db2inst1 $ ps -ef | grep -i db2 root 469 1 0 05:48 ? 00:00:00 /opt/ibm/db2/V11.5/bin/db2fmcd root 1127 1096 0 05:48 pts/0 00:00:00 sudo su - db2inst1 root 1128 1127 0 05:48 pts/0 00:00:00 su - db2inst1 db2inst1 1129 1128 0 05:48 pts/0 00:00:00 -sh root 1626 1 0 05:49 ? 00:00:00 db2wdog 0 [db2inst1] db2inst1 1628 1626 1 05:49 ? 00:00:00 db2sysc 0 root 1635 1626 0 05:49 ? 00:00:00 db2ckpwd 0 root 1636 1626 0 05:49 ? 00:00:00 db2ckpwd 0 root 1637 1626 0 05:49 ? 00:00:00 db2ckpwd 0 db2inst1 1639 1626 0 05:49 ? 00:00:00 db2vend (PD Vendor Process - 1) 0 db2inst1 1647 1626 1 05:49 ? 00:00:00 db2acd 0 ,0,0,0,1,0,0,00000000,0,0,0000000000000000,0000000000000000,00000000,00000000,00000000,00000000,00000000,00000000,0000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000c3834000,0000000000000000,0000000000000000,1,0,0,,,,,a89f30,14,1e014,2,0,1,0000000000041fc0,0x240000000,0x240000000,1600000,2,2,13 db2inst1 1673 1129 0 05:49 pts/0 00:00:00 ps -ef db2inst1 1674 1129 0 05:49 pts/0 00:00:00 grep -i db2 
Enter fullscreen mode Exit fullscreen mode
$ systemctl status db2fmcd ● db2fmcd.service - DB2 v11.5.8.0 Loaded: loaded (/etc/systemd/system/db2fmcd.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2023-04-30 05:48:42 UTC; 11min ago Main PID: 469 (db2fmcd) Tasks: 58 (limit: 4686) Memory: 1.0G CGroup: /system.slice/db2fmcd.service ├─ 469 /opt/ibm/db2/V11.5/bin/db2fmcd ├─1626 db2wdog 0 [db2inst1] ├─1628 db2sysc 0 ├─1635 db2ckpwd 0 ├─1636 db2ckpwd 0 ├─1637 db2ckpwd 0 ├─1639 db2vend (PD Vendor Process - 1) 0 ├─1647 db2acd 0 ,0,0,0,1,0,0,00000000,0,0,0000000000000000,0000000000000000,00000000,00000000,00000000,00000000,00000000,00000000,0000,00000000,00000000,00000000,00000000,00000000> └─2450 db2fmp ( ,1,0,0,0,0,0,00000000,0,0,0000000000000000,0000000000000000,00000000,00000000,00000000,00000000,00000000,00000000,0000,00000000,00000000,00000000,00000000,00000000> 
Enter fullscreen mode Exit fullscreen mode
  • Connect to our test database and we can see everything is OK
$ db2 (c) Copyright IBM Corporation 1993,2007 Command Line Processor for DB2 Client 11.5.8.0 You can issue database manager commands and SQL statements from the command prompt. For example: db2 => connect to sample db2 => bind sample.bnd For general help, type: ?. For command help, type: ? command, where command can be the first few keywords of a database manager command. For example: ? CATALOG DATABASE for help on the CATALOG DATABASE command ? CATALOG for help on all of the CATALOG commands. To exit db2 interactive mode, type QUIT at the command prompt. Outside interactive mode, all commands must be prefixed with 'db2'. To list the current command option settings, type LIST COMMAND OPTIONS. For more detailed help, refer to the Online Reference Manual. db2 => connect to ibm Database Connection Information Database server = DB2/LINUXX8664 11.5.8.0 SQL authorization ID = DB2INST1 Local database alias = IBM 
Enter fullscreen mode Exit fullscreen mode

Reference

https://www.dbi-services.com/blog/setting-up-ibm-db2-on-linux-root-installation/

https://www.ibm.com/docs/en/db2/11.5

Top comments (0)