环境:
OS:Centos 7
DB:v11.5.6
1.解压
[root@host135 db2]# tar -xvf v11.5.6_linuxx64_server_dec.tar.gz
[root@host135 db2]# mv server_dec /opt/db2
2.检查安装环境
[root@host135 db2]# ./db2prereqcheck
3.安装依赖包
yum install libstdc++*
yum install pam*
yum groupinstall 'Infiniband Support'
yum install gcc
yum install cpp
yum install gcc-c++
yum install kernel-devel
yum install ksh
yum install ntp
yum install sg3_utils
yum install pam32*
yum install libcxgb*
yum install m4
yum install binutils-devel
yum install patch
yum install -y pam*
yum install libnuma*
yum install libstdc++.so.6
yum install pam.i686
4.关闭selinux
#vi /etc/selinux/config
修改如下:
SELINUX=disabled#
5.修改系统内核参数
# vi /etc/sysctl.conf
kernel.shmmax = 8589934592 --设置为物理内存的一半或稍大
kernel.shmall = 67108864
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=262144
net.core.rmem_max=262144
net.core.wmem_default=262144
net.core.wmem_max=262144
6.安装
[root@host135 db2]# cd /opt/db2 ./db2_install [root@host135 db2]# ./db2_install Requirement not matched for DB2 database "Server" . Version: "11.5.6.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/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] yes Default directory for installation of products - /opt/ibm/db2/V11.5 *********************************************************** Install into default directory (/opt/ibm/db2/V11.5) ? [yes/no] 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 Requirement not matched for DB2 database "Server" . Version: "11.5.6.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/libpam.so*". DBT3514W The db2prereqcheck utility failed to find the following 32-bit library file: "libstdc++.so.6". DB2 installation is being initialized. Total number of tasks to be performed: 55 Total estimated time for all tasks to be performed: 2315 second(s) Task #1 start Description: Checking license agreement acceptance Estimated time 1 second(s) Task #1 end Task #2 start Description: Base Client Support for installation with root privileges Estimated time 3 second(s) Task #2 end Task #3 start Description: Product Messages - English Estimated time 14 second(s) Task #3 end Task #4 start Description: Base client support Estimated time 355 second(s) Task #5 start Description: Java Runtime Support Estimated time 217 second(s) Task #5 end Task #6 start Description: Java Help (HTML) - English Estimated time 7 second(s) Task #6 end Task #7 start Description: Base server support for installation with root privileges Estimated time 6 second(s) Task #7 end Task #8 start Description: Global Secure ToolKit Estimated time 76 second(s) Task #8 end Task #9 start Description: Java support Estimated time 11 second(s) Task #9 end Task #10 start Description: SQL procedures Estimated time 3 second(s) Task #10 end Task #11 start Description: ICU Utilities Estimated time 59 second(s) Task #11 end Task #12 start Description: Java Common files Estimated time 18 second(s) Task #12 end Task #13 start Description: Base server support Estimated time 582 second(s)
安装选项说明:
SERVER : Install DB2 server product
CONSV : Install DB2 Connect
CLIENT : Install DB2 client
RTCL : Install DB2 runtime client
6.创建实例说明
a.要在Linux服务器上创建 DB2 实例,您需要2个操作系统用户(实例 id 和受保护的 id),该用户未与任何其他 DB2 实例映射;
b.DB2实例用户名的长度不应超过8个字符。如果您想对 DB2 实例使用超过 8 个字符长的用户名,请确保您的操作系统支持长ID;
c.DB2 实例用户名不能是 GUESTS、LOCAL、PUBLIC、USERS、ADMINS。不能以 IBM、SQL、SYS 开头创建操作系统用户;
[root@host135 instance]#groupadd gdb2iadm1 [root@host135 instance]#groupadd gdb2fadm1 [root@host135 instance]#useradd db2inst1 -G gdb2iadm1 [root@host135 instance]#useradd db2fenc1 -G gdb2fadm1 [root@host135 instance]#cd /opt/ibm/db2/V11.5/instance [root@host135 instance]# ./db2icrt -a server -p 50000 -u db2fenc1 db2inst1 DBI1446I The db2icrt command is running. DB2 installation is being initialized.
7.激活license
以下操作全部以 db2inst1 用户执行查看license信息
[root@host135 instance]# su - db2inst1 [db2inst1@host135 ~]$ db2licm -l Product name: "DB2 Community Edition" License type: "Community" Expiry date: "Permanent" Product identifier: "db2dec" Version information: "11.5" Max amount of memory (GB): "16" Max number of cores: "4" Features: IBM DB2 Performance Management Offering: "Not licensed" license激活 [root@host135 ~]# find / -name db2ese_c.lic [root@host135 ~]# find / -name *.lic /opt/db2/db2/linuxamd64/tsamp/license/sam41.lic /opt/db2/db2/license/db2dec.lic /opt/db2/db2/license/db2consv_t.lic /opt/db2/db2/license/db2ese_t.lic /opt/db2/db2/license/db2trial.lic /opt/ibm/db2/V11.5/.licbkup/lic00000001.lic db2ese_t.lic DB2 Enterprise Server Edition(试用) db2dec.lic Db2 Community Edition (非生产) db2consv_t.lic Db2 Connect Server Edition (试用) db2trial.lic: Db2 Advanced Edition 90 天試用軟體授權 执行激活 [db2inst1@host135 ~]$ db2licm -a /opt/db2/db2/license/db2ese_t.lic LIC1402I License added successfully. LIC1426I This product is now licensed for use as outlined in your License Agreement. USE OF THE PRODUCT CONSTITUTES ACCEPTANCE OF THE TERMS OF THE IBM LICENSE AGREEMENT, LOCATED IN THE FOLLOWING DIRECTORY: "/opt/ibm/db2/V11.5/license/en_US.iso88591" 再次查看授权信息 [db2inst1@host135 ~]$ db2licm -l Product name: "DB2 Enterprise Server Edition" License type: "Trial" Expiry date: "04/22/2024" Product identifier: "db2ese" Version information: "11.5" Product name: "DB2 Community Edition" License type: "Community" Expiry date: "Permanent" Product identifier: "db2dec" Version information: "11.5" Max amount of memory (GB): "16" Max number of cores: "4" Features: IBM DB2 Performance Management Offering: "Not licensed"
8.启动
su - db2inst1 [db2inst1@host135 sqllib]$ which db2start ~/sqllib/adm/db2start [db2inst1@host135 sqllib]$ db2start 01/24/2024 09:58:29 0 0 SQL1063N DB2START processing was successful. SQL1063N DB2START processing was successful.
9.查看端口
[db2inst1@host135 sqllib]$ ss -nlp|grep 50000 tcp LISTEN 0 128 *:50000 *:* users:(("db2sysc",pid=20530,fd=6))
10.创建数据库
[root@host135 instance]# su - db2inst1 [db2inst1@host135 ~]$ db2 create db db_hxl using codeset utf-8 territory CN SQL1043C Database Services could not initialize the system catalogs. Error "-902" was returned. 再次执行就可以成功 [db2inst1@host135 ~]$ db2 create db db_hxl using codeset utf-8 territory CN DB20000I The CREATE DATABASE command completed successfully.
11.链接数据库并创建表
[db2inst1@host135 ~]$ db2 connect to db_hxl db2 " create table tb_test( id bigint not null generated by default as identity (start with 1,increment by 1), name varchar(20), user_ages int ) " DB20000I The SQL command completed successfully. 查看库中的表 [db2inst1@host135 ~]$ db2 list tables Table/View Schema Type Creation time ------------------------------- --------------- ----- -------------------------- TB_TEST DB2INST1 T 2024-01-24-10.58.45.374637 1 record(s) selected. 查看表结构 [db2inst1@host135 ~]$ db2 describe table tb_test Data type Column Column name schema Data type name Length Scale Nulls ------------------------------- --------- ------------------- ---------- ----- ------ ID SYSIBM BIGINT 8 0 No NAME SYSIBM VARCHAR 20 0 Yes USER_AGES SYSIBM INTEGER 4 0 Yes 3 record(s) selected. 写入数据 db2 " insert into tb_test(name,user_ages) values('test01',10); " 查询数据 db2 " select * from tb_test; " ID NAME USER_AGES -------------------- -------------------- ----------- 2 test01 10 1 record(s) selected.
12.创建账号并赋予权限
DB2没有数据库级别的用户,只能使用操作系统级别的用户;所以要新建DB2用户,要先在数据库服务器上新建操作系统用户. 例如要给数据库新建一个testuser用户 su - root useradd testuser passwd testuser 登录原来创建实例账户登录进行授权 [root@host135 tmp]# su - db2inst1 [db2inst1@host135 ~]$ db2 connect to db_hxl 授权 [db2inst1@host135 ~]$ db2 grant connect,DBADM on database to user testuser DB20000I The SQL command completed successfully. 使用testuser进行登录 [db2inst1@host135 ~]$ db2 connect to db_hxl user testuser using testuser Database Connection Information Database server = DB2/LINUXX8664 11.5.6.0 SQL authorization ID = TESTUSER Local database alias = DB_HXL 查询数据 db2 " select * from db2inst1.tb_test; " [db2inst1@host135 ~]$ db2 " > select * from db2inst1.tb_test; > " ID NAME USER_AGES -------------------- -------------------- ----------- 2 test01 10 1 record(s) selected. 这里查询需要带上用户
标签:DB2,db2inst1,Task,部署,host135,install,db2,安装 From: https://www.cnblogs.com/hxlasky/p/17984526