环境

  • 操作系统: Ubuntu 20.04
  • Db2 image: v11.5.0_linuxx64_server.tar.gz

安装和配置

解压文件 tar -zxvf v11.5.0_linuxx64_server.tar.gz ,生成 server 目录。

进入 server 目录,如下:

➜  server ls
db2  db2checkCOL_readme.txt  db2checkCOL.tar.gz  db2ckupgrade  db2_deinstall  db2_install  db2ls  db2prereqcheck  db2setup  installFixPack

在安装之前,可以先运行 db2prereqcheck 检查一下:

➜  server ./db2prereqcheck 

==========================================================================

Wed Mar 30 14:47:48 2022
Checking prerequisites for DB2 installation. Version "11.5.0.0". Operating system "Linux" 
   
Validating "Linux distribution " ... 
   Required minimum "UBUNTU" version: "16.04" 
   Actual version: "20.04" 
   Requirement matched. 
   
Validating "kernel level " ... 
   Required minimum operating system kernel level: "3.10.0". 
   Actual operating system kernel level: "5.13.0". 
   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". 
DBT3514W  The db2prereqcheck utility failed to find the following 32-bit library file: "libstdc++.so.6". 

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.0.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*". 

DBT3514W  The db2prereqcheck utility failed to find the following 32-bit library file: "libstdc++.so.6". 

............

DBT3555E  The db2prereqcheck utility determined that the current platform is not supported by the following version: "9.8.0.4". 
DBT3555E  The db2prereqcheck utility determined that the current platform is not supported by the following version: "9.8.0.3". 
DBT3555E  The db2prereqcheck utility determined that the current platform is not supported by the following version: "9.8.0.2". 

中间省略的部分是对其它Db2版本的检查,从 11.1.9.010.1.0.0 ,检查结果和 11.5.0.0 基本一样。

  • DBT3514W :以 W 结尾,表示warning,此处是说 libstdc++.so.6libpam.so* 有点问题;
  • DBT3555E :以 E 结尾,表示error,此处应该是指不支持Db2版本 9.8.0.4 (以及更低的版本);

对于 libstdc++.so.6libpam.so* ,可以去处理一下,消除warning,但也可以不予理会,暂时没发现对安装和使用Db2有什么影响……

注:如果遇到如下错误:

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.

解决方法是安装 build-essential 。运行如下命令:

apt install build-essential

安装好以后,再次运行 db2prereqcheck 检查一下。

接下来,切换到 root 。如果不切换:

  • Db2会安装在当前用户的home目录,无法设置;
  • 安装之后,也会遇到问题,我没具体研究,可能也有办法解决,不过为了避免不必要的麻烦,还是切换到root来安装吧;

运行 db2_install

➜  server ./db2_install 
Requirement not matched for DB2 database "Server" . Version: "11.5.0.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*". 


DBT3514W  The db2prereqcheck utility failed to find the following 32-bit library file: "libstdc++.so.6". 


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]

首先提示了 DBT3514W 的warning,然后让你接受license,此时输入 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 ,并回车。

选择是否安装purescale:

Do you want to install the DB2 pureScale Feature? [yes/no] 

输入 no ,并回车。

最后是总结,并安装Db2:

Requirement not matched for DB2 database "Server" . Version: "11.5.0.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*". 


DBT3514W  The db2prereqcheck utility failed to find the following 32-bit library file: "libstdc++.so.6". 

DB2 installation is being initialized.

............

The execution completed with warnings.

For more information see the DB2 installation log at
"/tmp/db2_install.log.53975".

无需交互,看着安装程序刷屏,一小会儿就好了。

接下来配置Db2用户:

➜  ~ groupadd -g 2000 db2iadm1
➜  ~ groupadd -g 2001 db2fadm1
➜  ~ useradd -m -g db2iadm1 -d /home/db2inst1 db2inst1
➜  ~ useradd -m -g db2fadm1 -d /home/db2fenc1 db2fenc1
➜  ~ passwd db2inst1
New password: 
Retype new password: 
passwd: password updated successfully
➜  ~ passwd db2fenc1
New password: 
Retype new password: 
passwd: password updated successfully

来到安装目录 /opt/ibm/db2/V11.5/instance ,运行:

chmod -R 755 *

接下来运行:

./db2icrt -p 50000 -u db2fenc1 db2inst1

接下来切到 db2inst1 用户,并创建 SAMPLE 数据库:

$ db2sampl

  Starting the DB2 instance...
  Creating database "SAMPLE"...
  Connecting to database "SAMPLE"...
  Creating tables and data in schema "DB2INST1"...
  Creating tables with XML columns and XML data in schema "DB2INST1"...
  Stopping the DB2 instance...

  'db2sampl' processing complete.

查看DB:

$ db2 list db directory

 System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = SAMPLE
 Database name                        = SAMPLE
 Local database directory             = /home/db2inst1
 Database release level               = 15.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =

查看Db2版本:

$ db2level
DB21085I  This instance or install (instance name, where applicable: 
"db2inst1") uses "64" bits and DB2 code release "SQL11050" with level 
identifier "0601010F".
Informational tokens are "DB2 v11.5.0.0", "s1906101300", "DYN1906101300AMD64", 
and Fix Pack "0".
Product is installed at "/opt/ibm/db2/V11.5".

启动Db2:

$ db2start
03/30/2022 14:39:21     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.

连接到 SAMPLE 数据库:

$ db2 connect to sample

   Database Connection Information

 Database server        = DB2/LINUXX8664 11.5.0.0
 SQL authorization ID   = DB2INST1
 Local database alias   = SAMPLE

运行SQL:

$ db2 "select * from sysibm.sysdummy1"

IBMREQD
-------
Y      

  1 record(s) selected.

大功告成!

Logo

更多推荐