在本文中,我们将在Amazon EC2 Ubuntu实例上安装IBM DB2社区版
介绍
-
db2是一个云本地数据库
-
低潜伏期交易和高弹性
-
支持结构化和非结构化数据
-
开发人员和合作伙伴社区的DB2数据服务器的入门级版
-
可用于Linux,Windows和AIX,也可作为Docker Image
提供
-
支持所有核心DB2功能
-
最多4个内核和16 GB RAM
-
始终在安全性
-
DB2社区支持
先决条件
-
设置T2.Medium类型的EC2实例
-
ubuntu 20.04 lts as ami
-
硬盘空间的30 GB
-
SSH打开端口22,DB2
为25000
-
创建一个IBM帐户,用于下载Db2 community edition
安装
- 登录到您的EC2实例并验证发行版本
$ ssh -i ibm-db2.pem ubuntu@54.234.180.34
$ 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
-
在您的本地计算机上下载最新的IBM DB2 Linux(X64)版本
-
下载完成后,将下载的文件复制到您的EC2实例
$ 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
- 在您的主目录中提取TARBALL
$ tar -xzvf v11.5.8_linuxx64_server_dec.tar.gz
$ ls
server_dec v11.5.8_linuxx64_server_dec.tar.gz
- 移至提取的目录并执行
db2prereqcheck
命令 这将检查安装DB2的先决条件要求
$ cd server_dec
$ ls
db2 db2_deinstall db2_install db2checkCOL.tar.gz db2checkCOL_readme.txt db2ckupgrade db2ls db2prereqcheck db2setup installFixPack
$ 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.
-
从上面的输出中,我们可以看到要求检查失败,我们需要修复它们
-
在您的实例上启用32位体系结构并安装所需的软件包
$ sudo dpkg --add-architecture i386
$ sudo apt update
$ sudo apt install -y ksh ksh93 lib32stdc++6 libpam0g:i386 binutils
- 安装了所需的软件包后,再次重新运行
db2prereqcheck
命令,并验证所有要求匹配
$ 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.
-
DB2可用于特定用例的多个安装方法
-
我们将使用
db2_install
命令作为root用户安装DB2,并等待安装完成
$ 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.
- 安装完成后,您将看到以下消息,我们可以检查安装日志文件的安装步骤
The execution completed successfully.
For more information see the DB2 installation log at
"/tmp/db2_install.log.5295".
$ 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.
- 让我们通过执行
db2val
命令来验证我们的安装并验证日志文件 我们可以看到一切都还好
$ 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.
$ 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.
后安装
- 为DB2创建所需的组
$ sudo groupadd -g 998 db2iadm1
$ sudo groupadd -g 997 db2fsdm1
$ sudo groupadd -g 996 dasadm1
- 为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
- 为用户设置密码
$ 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
- 使用
db2icrt
命令为DB2创建一个实例,并验证日志文件以获取有关连接到数据库的信息
$ 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.
$ 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.
- 让我们使用以下命令启动数据库实例
$ 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
$ . sqllib/userprofile
$ db2ilist
db2inst1
$ db2start
04/30/2023 05:36:30 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
- 现在启动了数据库实例,我们可以连接到实例
$ 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 =>
- 创建一个测试数据库,然后使用以下命令连接到数据库
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
- 重新启动后,启用数据库实例的自动启动
执行以下命令为
db2inst1
用户
$ 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
- 重新启动EC2实例并验证DB2进程
$ 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
$ 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>
- 连接到我们的测试数据库,我们可以看到一切都很好
$ 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
参考
https://www.dbi-services.com/blog/setting-up-ibm-db2-on-linux-root-installation/