DB2 install安装及创建实例的过程--自实践
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
[root@ibmdb2 server]# ls
db2 db2_deinstall db2_install db2prereqcheck db2setup doc installFixPack
[root@ibmdb2 server]# ./db2_install
WARNING:
DBT3534W The db2prereqcheck utility determined that ASLR is set to ON and that this could cause issues with some tools.
用于安装产品的缺省目录是 /opt/ibm/db2/V9.5
***********************************************************
想要选择另一个目录来进行安装吗 [是/否]?
否
指定下面的一个或多个关键字
(用空格分隔)以安装 DB2 产品。
ESE
CONSV
WSE
EXP
PE
CLIENT
RTCL
输入 "help" 以重新显示产品名。
输入 "quit" 以退出。
***********************************************************
ese
WARNING:
DBT3534W The db2prereqcheck utility determined that ASLR is set to ON and that this could cause issues with some tools.
正在初始化 DB2 安装。
要执行的任务总数为:44
要执行的所有任务的总估计时间为:1989
任务 #1 启动
描述:正在检查许可协议的接受情况
估计时间 1 秒
任务 #1 结束
任务 #2 启动
描述:具备 root 用户特权的情况下进行安装时的基本客户机支持
估计时间 3 秒
任务 #2 结束
............................
任务 #42 启动
描述:正在注册 DB2 许可证
估计时间 5 秒
任务 #42 结束
任务 #43 启动
描述:正在设置缺省全局概要文件注册表变量
估计时间 1 秒
任务 #43 结束
任务 #44 启动
描述:正在初始化实例列表
估计时间 5 秒
任务 #44 结束
任务 #45 启动
描述:正在更新全局概要文件注册表
估计时间 3 秒
任务 #45 结束
已成功完成执行。
有关更多信息,请参阅 "/tmp/db2_install.log.24059" 上的 DB2
安装日志。
4、DB2安装准备
(1)用户、组群
[root@ibmdb2 server]# groupadd -g 1101 db2iadm1
[root@ibmdb2 server]# groupadd -g 1102 db2fadm1
[root@ibmdb2 server]# groupadd -g 1103 dbsadm1
[root@ibmdb2 server]# useradd -u 10001 -g 1101 db2inst1
[root@ibmdb2 server]# useradd -u 10002 -g 1102 db2fenc1
[root@ibmdb2 server]# useradd -u 10003 -g 1103 dasusr1
[root@ibmdb2 server]# passwd db2inst1
Changing password for user db2inst1.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
创建实例
[root@ibmdb2]# cd /opt/ibm/db2/V9.5/instance
[root@ibmdb2 instance]# ./dascrt -u dasusr1
SQL4409W The DB2 Administration Server is already active.
DBI1070I Program dascrt completed successfully.
[root@ibmdb2 instance]# ./db2icrt -u db2fenc1 db2inst1
DBI1070I Program db2icrt completed successfully.
更新实例
[root@ibmdb2 instance]# ./dasupdt dasusr1
SQL4407W The DB2 Administration Server was stopped successfully.
SQL4406W The DB2 Administration Server was started successfully.
DBI1070I Program dasupdt completed successfully.
安
装许可文件
[root@ibmdb2 instance]# /opt/ibm/db2/V9.5/adm/db2licm -a /root/db2ese_u.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.5/license/zh_CN.utf8"
[root@ibmdb2 instance]#
增加db2的环境变量
在/home/db2inst1/.bash_profile中加入
. /home/db2inst1/sqllib/db2profile
增加端口号
su - root
vi /etc/services
db2cdb2inst1 50000/tcp # Connection port for DB2 instance db2inst1
db2idb2inst1 50001/tcp # Interrupt port for DB2 instance db2inst1
# su - db2inst1
export DB2INSTANCE=db2inst1
$ db2level //查看DB2版本
[db2inst1@ibmdb2 ~]$ db2level
DB21085I Instance "db2inst1" uses "64" bits and DB2 code release "SQL0905A"
with level identifier "060B0107".
Informational tokens are "DB2 v9.5.0.10", "s120809", "IP23364", and Fix Pack
"10".
Product is installed at "/opt/ibm/db2/V9.5".
[db2inst1@ibmdb2 ~]$
启动数据库
[db2inst1@ibmdb2 ~]$ db2start
10/25/2012 13:51:09 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
[db2inst1@ibmdb2 ~]$
[db2inst1@ibmdb2 ~]$ db2 update dbm cfg using svcename db2cdb2inst1
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed
successfully.
[db2inst1@ibmdb2 ~]$ db2set DB2COMM=TCPIP
[db2inst1@ibmdb2 ~]$ db2 terminate
DB20000I The TERMINATE command completed successfully.
重启数据库
[db2inst1@ibmdb2 ~]$ db2stop
2012-10-25 13:52:06 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
[db2inst1@ibmdb2 ~]$ db2start
10/25/2012 13:52:26 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
[db2inst1@ibmdb2 ~]$
--==============================================================
-- 建库操作
--==============================================================
su - db2inst1
1、创建数据库,同时设置字符集,中文的语言环境是utf-8
[db2inst1@ibmdb2 ~]$ db2 "create db dbtest1 using codeset UTF-8 territory CN"
DB20000I The CREATE DATABASE command completed successfully.
[db2inst1@ibmdb2 ~]$ db2 terminate
DB20000I The TERMINATE command completed successfully.
<第二种> GBK
db2 "create db dbtest using codeset GBK territory CN"
2、修改codepage
db2set db2codepage=1386 --db2 get db cfg for dbtest,查看是否需要修改。默认就是1386
db2 terminate
断开当前数据库连接:db2 connect reset
或者:db2 disconnect current
断开所有数据库的连接:db2 disconnect all
connect reset 应该是终止数据库连接,包含一个commit的动作
terminate应该是能终止这个client发起的进程,释放资源
terminate是命令,除了断开连接以外,它还终止clp(命令行处
理器)的后台进程,也就是常见的db2bp:back-end process。
connect reset是sql语句。
3、为了提高效率,表空间尽量使用裸设备
4、数据库设为归档日志,并做脱机备份
5、[db2inst1@ibmdb2 ~]$ db2 connect to dbtest
Database Connection Information
Database server = DB2/LINUXX8664 9.5.10
SQL authorization ID = DB2INST1
Local database alias = DBTEST
若:instance所在目录为/home/db2inst1
[db2inst1@ibmdb2 ~]$ db2 bind /home/db2inst1/sqllib/bnd/db2schema.bnd blocking all grant public sqlerror continue
LINE MESSAGES FOR db2schema.bnd
------ --------------------------------------------------------------------
SQL0061W The binder is in progress.
SQL0091N Binding was ended with "0" errors and "0" warnings.
[db2inst1@ibmdb2 ~]$
[db2inst1@ibmdb2 ~]$ db2 connect reset
DB20000I The SQL command completed successfully.
停启试验
db2 force application all --前提是断开所有连接
[db2inst1@ibmdb2 ~]$ db2stop
2012-10-25 14:08:42 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
[db2inst1@ibmdb2 ~]$ db2start
10/25/2012 14:08:47 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
[db2inst1@ibmdb2 ~]$
查看50000端口是否启动
[db2inst1@ibmdb2 ~]$ netstat -anp |grep 50000
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:50000 0.0.0.0:* LISTEN 20131/db2sysc 0
*****************************************************************************
--==============================================================
-- Linux下卸载DB2
--==============================================================
1、db2卸载
(1)停止所有的数据库应用程序;
$ su db2inst1
$ db2 force application all
*****************************************************************************
[db2inst1@localhost home]$ db2 force application all
DB20000I The FORCE APPLICATION command completed successfully.
DB21024I This command is asynchronous and may not be effective immediately.
*****************************************************************************
(2)卸下所有的数据库;
$ su db2inst1
$ db2 list db directory //查看数据库列表
$ db2 drop database
*****************************************************************************
[db2inst1@localhost home]$ db2 list db directory
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = TEST
Database name = TEST
Local database directory = /home/db2inst1
Database release level = a
.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
[db2inst1@localhost home]$ db2 drop db test
DB20000I The DROP DATABASE command completed successfully.
*****************************************************************************
(3)停止DB2数据库管理器;
$ su db2inst1
$ db2stop
*****************************************************************************
[db2inst1@localhost home]$ db2stop
07/31/2007 15:19:57 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
*****************************************************************************
(4)通过DB2管理服务器所有者(dasusr1)登录并发出db2admin stop命令来停止DB2管理服务器;
$ su dasusr1
$ db2admin stop
*****************************************************************************
[dasusr1@localhost root]$ db2admin stop
SQL4407W The DB2 Administration Server was stopped successfully.
*****************************************************************************
(5)用root用户查看活动的db2进程并杀掉db2进程;
$ su root
# ps -ef |grep db2 //查看进程
# kill -9 <端口>
*****************************************************************************
*****************************************************************************
(6)删除DB2实例
$ su root
# cd /opt/ibm/db2/V9.5/instance/
# ./daslist //列出系统中的DAS
# ./dasdrop dasusr1
# ./db2ilist //获取系统上的所有DB2实例的名称
# ./db2idrop db2inst1
*****************************************************************************
[root@localhost instance]# ./dasdrop dasusr1
SQL4410W The DB2 Administration Server is not active.
DBI1070I Program dasdrop completed successfully.
[root@localhost instance]# ./db2idrop db2inst1
DBI1070I Program db2idrop completed successfully.
*****************************************************************************
(7)卸载db2
$ su root
# cd /root/db2v8 //安装盘位置
# ./db2_deinstall
*****************************************************************************
[root@localhost db2v8]# ./db2_deinstall
Removing package(s) now.....
IBM_db2essg81....
IBM_db2icms81....
IBM_db2icc81....
.
.
Program db2_deinstall completed successfully...