解压 tar -zxvf db2软件包(放在opt目录下)
注:安装切换到root用户下
[root@localhost DB2]# pwd
/mnt/hgfs/Sunrier/DB2
[root@localhost DB2]# ls
db2exc_971_LNX_x86.tar.gz
[root@localhost DB2]# cd /opt
[root@localhost opt]# ls
[root@localhost opt]# tar -zxvf /mnt/hgfs/Sunrier/DB2/db2exc_971_LNX_x86.tar.gz
..............................................................................
..............................................................................
..............................................................................
..............................................................................
..............................................................................
..............................................................................
expc/db2_deinstall
expc/readmefirst.htm
expc/db2setup
expc/db2ls
expc/db2ckupgrade
expc/db2_install
expc/readmefirst.txt
expc/installFixPack
[root@localhost opt]# ls
expc
[root@localhost opt]#
3.开始安装软件包
[root@localhost opt]# ls
expc
[root@localhost opt]# cd expc
[root@localhost expc]# ls
db2 db2_deinstall db2ls db2setup installFixPack readmefirst.htm
db2ckupgrade db2_install db2prereqcheck doc readmefirst readmefirst.txt
[root@localhost expc]# ./db2_install
用于安装产品的缺省目录 - /opt/ibm/db2/V9.7
***********************************************************
要选择另一个目录用于安装吗?[是/否]
否
正在初始化 DB2 安装。
要执行的任务总数为:35
要执行的所有任务的总估计时间为: 1149
任务 #1 启动
描述: 正在检查许可协议的接受情况
估计时间 1 秒
任务 #1 结束
任务 #2 启动
描述: 具备 root 用户特权的情况下进行安装时的基本客户机支持
估计时间 3 秒
任务 #2 结束
********************
********************
********************
********************
********************
********************
********************
********************
********************
********************
********************
********************
********************
********************
********************
********************
任务 #34 启动
描述: 正在注册 DB2 更新服务
估计时间 30 秒
任务 #34 结束
任务 #35 启动
描述: 正在更新全局概要文件注册表
估计时间 3 秒
任务 #35 结束
已成功完成执行。
有关更多信息, 请参阅 "/tmp/db2_install.log.24239" 上的 DB2安装日志 。
[root@localhost opt]# ls
expc ibm
[root@localhost opt]#
4.注册license
[root@localhost opt]# cd ibm/db2/V9.7/adm
[root@localhost adm]# pwd
/opt/ibm/db2/V9.7/adm
[root@localhost adm]# ls
cieadmsv cieprcnt db2audit db2chparm db2fmp db2genp db2govlg db2inidb db2path db2rfpen db2set db2stop db2sysc
ciecsdem cieprisc db2cacpy db2dart db2fmpr db2gov db2havend db2licd db2pd db2rstar db2star2 db2stop2 db2syscr
cielock cieprupx db2cap db2dasstml db2fmpterm db2govd db2iclean db2licm db2pdcfg db2rstop db2start db2stst db2trc
[root@localhost adm]# /opt/ibm/db2/V9.7/adm/db2licm -a /opt/expc/db2/license/db2expc_uw.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/V9.7/license/zh_CN.utf8"
[root@localhost adm]#
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
例子:
[root@localhost ~]# groupadd -g 888 testgroup
[root@localhost ~]# useradd -g testgroup -u 555 -d /home/testuser1 -m testuser1
或[root@localhost ~]# useradd -g testgroup -u 555 -d /home/testuser1 -m -s /bin/sh testuser1
[root@localhost ~]# userdel testuser1
[root@localhost ~]# groupdel testgroup
当加上-s /bin/sh时,在root用户下切换到testuser1时变成sh-3.1$
查看echo $PS1变成了\s-\v\$
所以想更改成以前的那种登陆提示符,修改PS1环境变量的值
sh-3.1$ export PS1="[\u@\h \W]\$ "
\h 显示主机名
\u 显示当前用户的用户名
\W 显示当前工作目录的名字
\w 显示当前工作目录的路径
\s 显示当前运行的shell的名字
\v 显示shell的版本
\t 显示当前时间
\d 显示当前日期
\\ 显示反斜杠
\$ 显示$符作为提示符,如果用户是root的话,则显示#号
\# 显示当前命令的命令编号
\! 显示该命令的历史记录编号
\n 打印新行
\nnn 显示nnn的八进制值
7.添加三个用户的密码
添加实例的用户密码
[root@localhost adm]# passwd db2inst1
Changing password for user db2inst1.
New UNIX password: 输入新密码(如Sunrier)
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password: 再输入新密码(如Sunrier,跟第一次输入相同)
passwd: all authentication tokens updated successfully.
[root@localhost adm]#
添加受防护的用户密码
[root@localhost adm]# passwd db2fenc1
Changing password for user db2fenc1.
New UNIX password: 输入新密码
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password: 再输入新密码(两次需相同,否则需要重新输入)
passwd: all authentication tokens updated successfully.
[root@localhost adm]#
添加DAS用户密码
[root@localhost adm]# passwd db2dasusr1
Changing password for user db2dasusr1.
New UNIX password: 输入新密码
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password: 再输入新密码(两次需相同,否则需要重新输入)
passwd: all authentication tokens updated successfully.
[root@localhost adm]#
8.检查用户组和用户是否创建成功
用户组: more /etc/group | grep db2
用户: more /etc/passwd | grep db2
[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/sh
db2fenc1:x:102:902::/home/db2fenc1:/bin/sh
db2dasusr1:x:103:903::/home/db2dasusr1:/bin/sh
[root@localhost adm]#
9.创建实例
进入/opt/ibm/db2/V9.7/instance目录
[root@localhost adm]# cd /opt/ibm/db2/V9.7/instance
[root@localhost instance]# pwd
/opt/ibm/db2/V9.7/instance
[root@localhost instance]# ./dascrt -u db2dasusr1 (注:创建DB2管理服务器)
[root@localhost instance]# ./db2icrt -u db2fenc1 db2inst1 (注:创建DB2实例)
或者[root@localhost instance]# ./db2icrt -a server -u db2fenc1 db2inst1 (注:创建DB2实例)
这里dascrt创建的是DB2 adminstration server,每台服务器只有一个这种server,为进行DB2管理(比如运行控制中心)所必须,同时指定其管理用户是db2dasusr1 ,db2icrt创建的是实例,其名字一般和管理用户名一样,这里db2fenc1指定db2inst1为它的防护用户,而db2inst1为一实例用户
10.配置DB2
1)设置DB2自启动(注:依然在root用户下)
[root@localhost instance]# pwd
/opt/ibm/db2/V9.7/instance
[root@localhost instance]# ./db2iauto -on db2inst1
db2set MsgRC=1306, P1='', P2=''
[root@localhost instance]#
设置对db2inst1在Linux启动时自动启动。
2)修改网络服务端口(注:在db2inst1用户下)
修改DB2的服务端口为50658,默认情况下端口是50000
[root@localhost instance]# su - db2inst1
[db2inst1@localhost ~]$ db2 update dbm cfg using SVCENAME 50658
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
[db2inst1@localhost ~]$
3)修改DB2连接方式为TCP/IP
[db2inst1@localhost ~]$ db2set DB2COMM=TCPIP
[db2inst1@localhost ~]$
修改DB2连接方式为TCPIP,然后可通过JDBC、ODBC等访问本DB2服务器上的数据库,安装了DB2客户端的其它机器也可访问数据库。
11.查看DB2许可证情况
[root@localhost ~]$ su - db2inst1
[db2inst1@localhost ~]$ db2licm -l
Product name: "DB2 Express-C"
License type: "Unwarranted"
Expiry date: "Permanent"
Product identifier: "db2expc"
Version information: "9.7"
Max number of CPUs: "2"
Max amount of memory (GB): "2"
[db2inst1@localhost DB2]$
注:上面为官网下载的免费DB2版本
[root@localhost ~]$ su - db2inst1
[db2inst1@localhost ~]$ db2licm -l
Product Name = "DB2 Universal Database Express Edition"
Product Identifier = "DB2EXP"
Version Information = "8.2"
Expiry Date = "Permanent"
Registered User Policy = "Disabled"
Enforcement Policy = "Soft Stop"
Number of processors = "1"
Number of licensed processors = "2"
Annotation = ""
Other information = ""
[db2inst1@localhost ~]$ db2licm -l
注:上面为商业使用中的付费DB2版本
12.查看DB2版本
[root@localhost ~]$ su - db2inst1
[db2inst1@localhost ~]$ db2level
DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL09071"
with level identifier "08020107".
Informational tokens are "DB2 v9.7.0.1", "s091114", "IP23033", and Fix Pack
"1".
Product is installed at "/opt/ibm/db2/V9.7".
[db2inst1@localhost ~]$
注:上面为官网下载的免费DB2版本
[db2inst1@localhost ~]$ db2level
DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL08023"
with level identifier "03040106".
Informational tokens are "DB2 v8.1.2.97", "special_15462", "MI00142_15462", and
FixPak "10".
Product is installed at "/opt/IBM/db2/V8.1".
[db2inst1@localhost ~]$
注:上面为商业使用中的付费DB2版本