1创建安装目录
mkdir -p /opt/db2v11.1/
cd /opt/db2v11.1/
2解压软件包
[root@localhost db2v11.1]# tar xf v11.1_linuxx64_expc.tar.gz
3开始安装软件包
[root@localhost ~]# yum install -y compat-libstdc++-33 libaio.so.1
[root@localhost expc]# cd /opt/db2v11.1/expc
[root@localhost expc]# ./db2_install
Default directory for installation of products - /opt/ibm/db2/V10.5
***********************************************************
Install into default directory (/opt/ibm/db2/V10.5) ? [yes/no]
是否选择默认目录安装,选择yes
*************************************************
The execution completed successfully.
安装命令执行完成
4注册license
[root@localhost expc]# cd /opt/ibm/db2/V11.1/adm/
[root@localhost adm]# chmod 775 *
[root@localhost adm]# ./db2licm -a /opt/db2v11.1/expc/db2/license/db2expc_uw.lic
5创建用户组
[root@localhost adm]# groupadd -g 901 db2iadm1
[root@localhost adm]# groupadd -g 902 db2fadm1
[root@localhost adm]# groupadd -g 903 db2dadm1
6创建用户
(分别是拥有实例的用户,受防护的用户,DAS用户)且指定对应的用户组
[root@localhost adm]# useradd -g db2iadm1 -u 101 -d /home/db2inst1 -m db2inst1
[root@localhost adm]# useradd -g db2fadm1 -u 102 -d /home/db2fenc1 -m db2fenc1
[root@localhost adm]# useradd -g db2dadm1 -u 103 -d /home/db2dasusr1 -m db2dasusr1
参数说明:
-u uid 使用者的ID值,必须为唯一的ID值,除非用-o选项可以不唯一,数字不可为负值,0~999传统上是保留给系统帐号使用。
-d path 使用者目录
-m 使用者目录如不存在则自动建立
-s shell 使用者登入后使用shell名称作为提示符,如果不写系统会帮你指定预设的登入shell
7添加用户的密码
[root@localhost adm]# passwd db2inst1
[root@localhost adm]# passwd db2fenc1
[root@localhost adm]# passwd db2dasusr1
8检查用户组和用户
[root@localhost adm]# more /etc/group | grep db2
db2iadm1:x:901:
db2fadm1:x:902:
db2dadm1:x:903:
[root@localhost adm]# more /etc/passwd | grep db2
db2inst1:x:101:901::/home/db2inst1:/bin/bash
db2fenc1:x:102:902::/home/db2fenc1:/bin/bash
db2dasusr1:x:103:903::/home/db2dasusr1:/bin/bash
9创建实例
绑定端口号
[root@localhost instance]# cd /opt/ibm/db2/V11.1/instance
[root@localhost instance]# ./db2icrt -p 50000 -u db2fenc1 db2inst1
创建样本数据库
[root@localhost instance]# su - db2inst1
[db2inst1@localhost ~]$ db2sampl
[db2inst1@localhost ~]$ db2start
[db2inst1@localhost ~]$ db2 “select * from staff”
[root@localhost instance]# ./dascrt -u db2dasusr1 (创建DB2管理服务器)
[root@localhost instance]# ./db2icrt -u db2fenc1 db2inst1 (创建DB2实例)
10配置DB2
(1)设置DB2自启动
[root@localhost instance]# su -
[root@localhost instance]# cd /opt/ibm/db2/V10.5/instance
[root@localhost instance]# ./db2iauto -on db2inst1
(2)修改网络服务端口(注:在db2inst1用户下)
修改DB2的服务端口为50658,默认情况下端口是50000(单实例的话可以不修改)
[root@localhost expc]# su - db2inst1
[db2inst1@localhost ~]$ db2 update dbm cfg using SVCENAME 50658
(3)修改DB2连接方式为TCP/IP
[root@localhost expc]# su - db2inst1
[db2inst1@localhost ~]$ db2set DB2COMM=TCPIP
(4)修改字符集
[db2inst1@localhost ~]$ db2set db2codepage=1208(也就是utf-8)
数据库db2 系统centos xhell 三个字符集要一致
11查看DB2许可证
[db2inst1@localhost ~]$ db2licm -l
Product name: "DB2 Express-C"
License type: "Unwarranted"
Expiry date: "Permanent"
Product identifier: "db2expc"
Version information: "11.1"
Max number of CPUs: "2"
Max amount of memory (GB): "16"
Max number of cores: "2"
Enforcement policy: "Soft Stop"
12创建数据库并设置字符集
[root@localhost expcD]# su - db2inst1
[root@localhost expc]# db2 create database arapmdb2 using codeset UTF-8 territory CN pagesize 32768
可能会等的时间长一点
13连接数据库
[db2inst1@localhost ~]$ db2 connect to arapmdb2 user db2inst1 using db2inst1
14创建BUFFERPOOL
[db2inst1@localhost ~]$ db2 create BUFFERPOOL testBUFFER SIZE 1000 PAGESIZE 32K
15创建TestTB表
[db2inst1@localhost ~]$ db2 "create table TestTB(id integer not null generated always as identity(start with 1,increment by 1),name varchar(10))"
插入数据
[db2inst1@localhost ~]$ db2 "INSERT INTO TestTB(name) VALUES('test')"