1.环境准备

[root@db2node1 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.9 (Santiago)


[root@db2node1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.107 db2node1
192.168.2.164 db2node2

关闭防火墙​

[root@db2node1 ~]# chkconfig iptables off
[root@db2node1 ~]# service iptables stop
关闭selinux

安装补丁包

yum install dapl sg3_utils libnes.x86_64  libmthca.x86_64 libipathverbs.x86_64 libibumad.x86_64 libibmad.x86_64 libcxgb3.x86_64 ibutils.x86_64 ibsim.x86_64 librdmacm.x86_64 libibcm.x86_64 pam-1.1.1-24.el6.i686 -y


yum install rsh rsh-server ksh vim nfs-utils.x86_64 pam.i686 ntp.x86_64 ntpdate.x86_64 openssh-clients.x86_64 sg3_utils.x86_64 dapl.x86_64 dapl.i686 compat-dapl.x86_64 compat-dapl.i686 rdma.noarch libaio.x86_64 libaio.i686 libstdc++.x86_64 libstdc++.i686 compat-libstdc++-33.x86_64

2.添加端口/etc/services,两个节点都需要做。

db2c_db2inst1   50000/tcp    # DB2 connections service port
DB2_db2inst1 60000/tcp
DB2_db2inst1_1 60001/tcp
DB2_db2inst1_2 60002/tcp
DB2_db2inst1_3 60003/tcp
DB2_db2inst1_END 60004/tcp

3.禁止和自启动一些软件

chkconfig iptables off
chkconfig ip6tables off
chkconfig postfix off
chkconfig rpcbind on
chkconfig nfs on
chkconfig nfslock on
chkconfig netfs on
chkconfig rsh on
chkconfig xinetd on
chkconfig ntpd on
chkconfig rdma on

4.创建db2用户

mkdir /db2home
groupadd -g 999 db2iadm1
groupadd -g 998 db2fadm1
groupadd -g 997 dasadm1

useradd -u 1004 -g db2iadm1 -m -d /db2home/db2inst1 db2inst1
useradd -u 1003 -g db2fadm1 -m -d /db2home/db2fenc1 db2fenc1
useradd -u 1002 -g dasadm1 -m -d /home/dasusr1 dasusr1
echo "wwwwww" | passwd --stdin db2inst1
echo "wwwwww" | passwd --stdin db2fenc1
echo "wwwwww" | passwd --stdin dasusr1
chmod 775 /db2home/db2inst1

5.配置安全终端

vi /etc/securetty

在最后加入
rsh
rlogin
rexec

分别修改/etc/xinetd.d/rsh|rlogin|rexec文件,将 disable = yes 该为 disable = no (这里一共3个文件,不是一个文件):

vim /etc/xinetd.d/rsh
vim /etc/xinetd.d/rlogin
vim /etc/xinetd.d/rexec

把disable = yes 改成disable = no

重启rsh

service xinetd restart
  1. 配置.rhosts
    用db2inst1登录,新建rhosts文件。
su - db2inst1
vim ~/.rhosts

添加如下:

db2node1    db2inst1
db2node2 db2inst1

7.安装DB2软件
过程略去

8.验证rsh是否成功,不需要输入密码,返回结果,则说明成功

[db2inst1@db2node1 ~]$ rsh db2node1 date
Sun Aug 25 13:25:29 CST 2019
[db2inst1@db2node1 ~]$ rsh db2node2 date
Sun Aug 25 13:25:32 CST 2019

9.配置ntp,以db2node1为准

10.配置nfs,在db2node1节点

vim /etc/exports
加入
/db2home 192.168.2.0/24(rw,sync,no_root_squash)

加载配置

exportfs -r

重启服务

service nfs restart
service nfslock restart
service netfs restart

在db2node2上挂载db2node1共享的目录:
在/etc/fstab加入:

db2node1:/db2home /db2home nfs rw,timeo=7,hard,intr,bg,suid,lock 0 0

查看是否挂载上

[root@db2node2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_db01-lv_root
50G 3.4G 44G 8% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 477M 41M 412M 9% /boot
/dev/mapper/vg_db01-lv_home
41G 2.6G 37G 7% /home
/dev/sr0 3.7G 3.7G 0 100% /mnt
db2node1:/db2home 50G 3.4G 44G 8% /db2home

11.创建db2实例,此时在db2node1一边创建即可


cd /opt/ibm/db2/V10.1/instance
./db2icrt -u db2fenc1 db2inst1

12.修改节点配置文件

vim /db2home/db2inst1/sqllib/db2nodes.cfg

修改为​

0 db2node1 0
1 db2node1 1
2 db2node2 0
3 db2node2 1

在节点1上使用db2inst1登录:

su - db2inst1
vi /db2home/db2inst1/.profile

添加
. /db2home/db2inst1/sqllib/db2profile

在db2node1上启动数据库:

[db2inst1@db2node1 bin]$ db2start
08/25/2019 14:28:23 1 0 SQL1063N DB2START processing was successful.
08/25/2019 14:28:23 0 0 SQL1063N DB2START processing was successful.
08/25/2019 14:28:24 3 0 SQL1063N DB2START processing was successful.
08/25/2019 14:28:26 2 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.

测试联通性

[db2inst1@db2node1 ~]$ db2_all date

Sun Aug 25 13:44:08 CST 2019
db2node1: date completed ok

Sun Aug 25 13:44:08 CST 2019
db2node1: date completed ok

Sun Aug 25 13:44:08 CST 2019
db2node2: date completed ok

Sun Aug 25 13:44:09 CST 2019
db2node2: date completed ok

13.创建testdb库

[db2inst1@db2node1 db2data]$ mkdir /db2data/testdb
[db2inst1@db2node1 db2data]$ db2 "create db testdb on /db2data/testdb dbpath on /db2data/testdb using codeset UTF-8 territory CN"
DB20000I The CREATE DATABASE command completed successfully.

14.创建表空间

CREATE LARGE TABLESPACE TBS_HBHE_4K
IN DATABASE PARTITION GROUP "IBMDEFAULTGROUP"
PAGESIZE 4K
MANAGED BY DATABASE
USING ( File '/db2data/testdb/db2inst1/NODE0000/TESTDB/TABLESPACES/TBS_MAST_DAT001.DBF' 200M ) ON DBPARTITIONNUM(0)
USING ( File '/db2data/testdb/db2inst1/NODE0001/TESTDB/TABLESPACES/TBS_MAST_DAT001.DBF' 200M ) ON DBPARTITIONNUM(1)
USING ( File '/db2data/testdb/db2inst1/NODE0002/TESTDB/TABLESPACES/TBS_MAST_DAT001.DBF' 200M ) ON DBPARTITIONNUM(2)
USING ( File '/db2data/testdb/db2inst1/NODE0003/TESTDB/TABLESPACES/TBS_MAST_DAT001.DBF' 200M ) ON DBPARTITIONNUM(3)
EXTENTSIZE 32
PREFETCHSIZE 32
BUFFERPOOL IBMDEFAULTBP
OVERHEAD 12.67
TRANSFERRATE 0.18
DROPPED TABLE RECOVERY OFF;

15.创建表t1

[db2inst1@db2node1 db2data]$ db2 "create table t1(id int, name varchar(20), addr varchar(30) ) compress yes distribute by hash(id) in TBS_HBHE_4K"
DB20000I The SQL command completed successfully.

16.插入数据

[db2inst1@db2node1 db2data]$ db2 "insert into t1 values(1,'a','a'),(2,'b','b'),(3,'c','c'),(4,'d','d')"
DB20000I The SQL command completed successfully.
[db2inst1@db2node1 db2data]$ db2 "insert into t1 values(5,'e','e'),(6,'f','f'),(7,'g','g'),(8,'h','h')"
DB20000I The SQL command completed successfully.

这里使用了一个脚本循环插入10W条数据​

[db2inst1@db2node1 db2data]$ cat 1.sh 
#!/bin/sh

insert_data_FUNC(){
for ((i = 0; i <100000; i++))
do
db2 "insert into t1 values($i,'e','e')"
done
}

db2 connect to testdb
insert_data_FUNC

17.执行命令查看数据分布情况



[db2inst1@db2node1 ~]$ db2 "select dbpartitionnum(id) as cnt, count(*) as cnt2 from t1 group by dbpartitionnum(id) order by dbpartitionnum(id)  with ur"

CNT CNT2
----------- -----------
0 25069
1 24752
2 25240
3 24947

4 record(s) selected.

版权声明:本文为博主原创文章,未经博主允许不得转载。

Linux,oracle