前言:年底了,公司需要部署一套DB2环境+应用系统来对客户进行相关的功能模块演示操作,之前对DB2接触不多,利用这次机会,开启对DB2的探索学习之路。
DB2 数据库部署
硬件环境信息:
机器IP:10.162.64.78
OS版本:RHEL 6.6
内存:256G
1.文件系统划分
查看已经创建的PV,VG
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 VolGroup00 lvm2 a-- 557.38g 379.38g
# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup00 1 2 0 wz--n- 557.38g 379.38g
创建LV
# lvcreate -L 20G -n lvdb2log VolGroup00
# lvcreate -L 30G -n lvdb2arch VolGroup00
# lvcreate -L 150G -n lvdb2data VolGroup00
格式化LV
# mkfs.ext4 /dev/VolGroup00/lvdb2log
# mkfs.ext4 /dev/VolGroup00/lvdb2arch
# mkfs.ext4 /dev/VolGroup00/lvdb2data
创建目录并挂载
# mkdir -p /oradata4
# mkdir -p /db2arch
# mkdir -p /db2log
# mount /dev/VolGroup00/lvdb2log /db2log
# mount /dev/VolGroup00/lvdb2arch /db2arch
# mount /dev/VolGroup00/lvdb2data /oradata4
# tune2fs -c 0 -i 0 /dev/VolGroup00/lvdb2log
# tune2fs -c 0 -i 0 /dev/VolGroup00/lvdb2arch
# tune2fs -c 0 -i 0 /dev/VolGroup00/lvdb2data
# echo "/dev/VolGroup00/lvdb2log /db2log ext4 defaults 0 0" >> /etc/fstab
# echo "/dev/VolGroup00/lvdb2arch /db2arch ext4 defaults 0 0" >> /etc/fstab
# echo "/dev/VolGroup00/lvdb2data /oradata4 ext4 defaults 0 0" >> /etc/fstab
2.安装所需软件包
libstdc++.so.6
3.修改系统内核参数
# vi /etc/sysctl.conf
kernel.shmmax = 137438953472 --设置为物理内存的一半或稍大
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
4.创建用户
# groupadd -g 1011 db2iadm1
# groupadd -g 1012 db2fadm1
# useradd -u 1016 -g db2iadm1 -d /home/db2inst1 -m db2inst1
# useradd -u 1017 -g db2fadm1 -d /home/db2fenc1 -m db2fenc1
# echo 'db2inst1' |passwd --stdin db2inst1
# echo 'db2fenc1' |passwd --stdin db2fenc1
# chown db2inst1:db2iadm1 /oradata4
# chown db2inst1:db2iadm1 /db2log
# chown db2inst1:db2iadm1 /db2arch
5.安装数据库
# tar zxvf v10.5fp7_linuxx64_universal_fixpack.tar.gz
# cd universal/
# ./db2_install
DBI1324W Support of the db2_install command is deprecated.
Default directory for installation of products - /opt/ibm/db2/V10.5
***********************************************************
Install into default directory (/opt/ibm/db2/V10.5) ? [yes/no]
yes
Specify one of the following keywords to install DB2 products.
SERVER
CONSV
EXP
Enter "help" to redisplay product names.
Enter "quit" to exit.
***********************************************************
SERVER
***********************************************************
Do you want to install the DB2 pureScale Feature? [yes/no]
no
DB2 installation is being initialized.
......
The execution completed successfully.
For more information see the DB2 installation log at
"/tmp/db2_install.log.25687".
6.查看并安装license
# find / -name db2licm
/opt/ibm/db2/V10.5/adm/db2licm
# /opt/ibm/db2/V10.5/adm/db2licm -l
Product name: "DB2 Enterprise Server Edition"
License type: "License not registered"
Expiry date: "License not registered"
Product identifier: "db2ese"
Version information: "10.5"
# ./db2licm -a /install/isrs.lic
Product name: "DB2 Enterprise Server Edition"
License type: "CPU Option"
Expiry date: "Permanent"
Product identifier: "db2ese"
Version information: "10.5"
7.创建实例
修改/etc/hosts如下配置:
127.0.0.1 localhost
10.162.64.78 OSS-ZYGL-294
# /opt/ibm/db2/V10.5/instance/db2icrt -a server -p 9999 -u db2fenc1 db2inst1
DBI1446I The db2icrt command is running.
DB2 installation is being initialized.
......
The execution completed successfully.
For more information see the DB2 installation log at "/tmp/db2icrt.log.9284".
DBI1070I Program db2icrt completed successfully.
# /opt/ibm/db2/V10.5/instance/db2ilist
db2inst1
启动实例: --切换到db2inst1用户
配置环境变量 --root用户和db2inst1用户
# vi ~/.bash_profile
$ vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/opt/ibm/db2/V10.5/bin
# source ~/.bash_profile
$ source ~/.bash_profile
$ db2start
01/23/2017 13:36:37 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
8.创建DB
$ db2 "create db RESDB on /oradata4 using codeset UTF-8 territory cn"
DB20000I The CREATE DATABASE command completed successfully.
批注:创建数据库时若为指定路径,将使用默认路径,数据库用户的家目录,如下查看:
$ db2 get dbm cfg | grep -i DFTDBPATH
Default database path (DFTDBPATH) = /home/db2inst1
9.参数调整
$ db2 connect to resdb
$ db2iauto -on db2inst1 --设置数据库实例开机自启动
9.1参数调整
$ db2 update dbm cfg using SVCENAME 9999 DFT_MON_BUFPOOL on DFT_MON_UOW on NUM_POOLAGENTS 4100
DB20000I The UPDATE DATABASE MANAGER CONFIGURATION command completed successfully.
SQL1362W One or more of the parameters submitted for immediate modification
were not changed dynamically. Client changes will not be effective until the
next time the application is started or the TERMINATE command has been issued.
Server changes will not be effective until the next DB2START command.
批注:需要重启数据库生效
9.2日志调整
--日志位置和大小调整
$ db2 update db cfg for RESDB using NEWLOGPATH /db2log
$ db2 update db cfg for RESDB using LOGARCHMETH1 disk:/db2arch