Chinaunix首页 | 论坛 | 博客
  • 博客访问: 453807
  • 博文数量: 67
  • 博客积分: 2792
  • 博客等级: 少校
  • 技术积分: 1038
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-13 19:00
文章分类

全部博文(67)

文章存档

2014年(2)

2013年(7)

2012年(1)

2011年(1)

2010年(56)

分类: 系统运维

2013-05-10 16:18:59

一、  Gentoo下安装IBM DB2 9.5

1、安装所需要 AIO/libstdc++

     V9.7需要安装 dev-libs/libaio

emerge dev-libs/libaio

     V9.5需要安装 libstdc++

emerge virtual/libstdc++

2、开始安装

tar -xvzf v9.5fp8_linuxx64_server.tar.gz

cd server

./db2_install -b /opt/ibm/db2/V9.5

   升级为fp10,则执行

tar –xvzf v9.5fp10_linuxx64_universal_fixpack.tar.gz

cd universal

./installFixPack -f db2lib -b /opt/ibm/db2/V9.5

3、创建需要的用户组。As root

groupadd -g 999 db2iadm1

groupadd -g 998 db2fadm1

groupadd -g 997 db2sadm1

4、创建需要的用户。As root

useradd -u 1004 -g db2iadm1 -m -d /home/db2inst1 db2inst1 -p password1

useradd -u 1003 -g db2fadm1 -m -d /home/db2fenc1 db2fenc1 -p password2

useradd -u 1002 -g db2sadm1 -m -d /home/db2admn1 db2admn1 -p password3

5、增加FCM port mapping 否则无法启动,in /etc/services

     注意:如果没有 "db2inst1 50000/tcp" 则会 db2start 时候报告 SQL5043N 错误,没有其他这无法启动实例

echo "#Add DB2 FCM port information" >> /etc/services

echo "#" >> /etc/services

echo "db2inst1               50000/tcp" >> /etc/services

echo "DB2_db2inst1           60000/tcp" >> /etc/services

echo "DB2_db2inst1_1         60001/tcp" >> /etc/services

echo "DB2_db2inst1_2         60002/tcp" >> /etc/services

echo "DB2_db2inst1_END       60003/tcp" >> /etc/services

6、创建 DB2 实例,注意,先检查 hostname hosts 是否正确设置

/opt/ibm/db2/V9.5/instance/db2icrt -p db2inst1 -u db2fenc1 db2inst1

    如果安装实例失败,则用下列命令删除实例后重装

/opt/ibm/db2/V9.5/instance/db2idrop db2inst1

rm -rf /home/db2inst1/*

nano -w /etc/conf.d/hostname

nano -w /etc/hosts

/opt/ibm/db2/V9.5/instance/db2icrt -p db2inst1 -u db2fenc1 db2inst1

7、创建 DB2 Administration Server:

/opt/ibm/db2/V9.5/instance/dascrt -u db2admn1

8、切换到DB2实例帐号 db2inst1,设置通讯参数,启动实例 db2inst1,安装示例数据库

su - db2inst1

db2 update dbm cfg using SVCENAME db2inst1

db2set DB2COMM=tcpip

db2start

db2sampl

9、检查安装是否正确(连接到示例数据库)

db2 LIST DB DIRECTORY

db2 CONNECT TO SAMPLE

db2 list tables

db2level

10、设置许可信息

    新增许可文件

db2licm -a db2ese_cV9.5CPU.lic

    查看许可情况

db2licm -l

Product name:                     "DB2 Enterprise Server Edition"

License type:                     "CPU Option"

Expiry date:                      "Permanent"

Product identifier:               "db2ese"

Version information:              "9.5"

Enforcement policy:               "Soft Stop"

Features:

DB2 Database Partitioning:        "Not licensed"

DB2 Performance Optimization ESE: "Not licensed"

DB2 Storage Optimization:         "Not licensed"

DB2 Advanced Access Control:      "Not licensed"

DB2 Geodetic Data Management:     "Not licensed"

IBM Homogeneous Replication ESE:  "Not licensed"

 

Product name:                     "DB2 Connect Server"

License type:                     "Trial"

Expiry date:                      "08/31/2010"

Product identifier:               "db2consv"

Version information:              "9.5"

    删除无用的许可

db2licm -r "db2consv"

到此DB2安装完成。我只做到这一步,下面步骤除去第15步,其他暂时未执行

11、安全设置(Security)

     禁止自动发现

db2 update dbm cfg using DISCOVER_INST disable

db2 update dbm cfg using DISCOVER disable

db2 update admin cfg using DISCOVER disable

12、配置系统参数,as root

    修改内核参数 /etc/sysctl.conf 内容如下

# added by caviler

# for db2

kernel.shmmax = 6884901888

kernel.msgmni = 1024

kernel.sem = 250 256000 32 1024

    使修改后的内核参数生效

sysctl –p

13、卸载 DB2

db2stop

exit

/opt/ibm/db2/V9.5/instance/dasdrop

/opt/ibm/db2/V9.5/instance/db2idrop db2inst1

rm -rf /home/db2inst1/*

./db2_deinstall -a -b /opt/ibm/db2/V9.5

14、安装 init.d 启动脚本以便开机自动启动

nano /etc/init.d/db2

chmod 755 /etc/init.d/db2

/home/db2inst1/sqllib/bin/db2iauto -on db2inst1

nano /etc/conf.d/local.start

在其中配置/etc/init.d/db2 start

   /etc/init.d/db2 文件内容如下

#!/sbin/runscript

 

# Path to the DB2 installation

DB2DIR="/opt/ibm/db2/V9.5"

 

# User name of the administration instance owner

DASUSR=$(${DB2DIR}/instance/daslist)

 

# List of database instances

DB2INSTS=$(${DB2DIR}/instance/db2ilist)

 

depend() {

    need net

    use dns clock logger ldap

}

 

find_homedir() {

    getent passwd $1 | cut -d":" -f 6

}

 

start() {

    LOGFILE=$(mktemp)

    for db2inst in ${DB2INSTS}; do

        INSTSTART=$(${DB2DIR}/instance/db2iset DB2AUTOSTART -i ${db2inst})

        if [[ ${INSTSTART} == "TRUE" ]] || [[ ${INSTSTART} == "YES" ]]; then

            ebegin "Starting IBM DB2 database instance ${db2inst}"

            INSTHOME="$(find_homedir ${db2inst})"

            su ${db2inst} -l -c "\

                source ${INSTHOME}/sqllib/db2profile ; \

                db2start" >${LOGFILE} 2>&1

            rc=${?}

            eend ${rc}

            [[ ${rc} -ne 0 ]] && cat ${LOGFILE}

        fi

    done

    if [[ -n "$DASUSR" ]]; then

        ebegin "Starting IBM DB2 administration instance ${DASUSR}"

        INSTHOME="$(find_homedir ${DASUSR})"

        su ${DASUSR} -l -c "\

            source ${INSTHOME}/das/dasprofile ; \

            db2admin start" >${LOGFILE} 2>&1

        rc=${?}

        eend ${rc}

        [[ ${rc} -ne 0 ]] && cat ${LOGFILE}

    fi

    rm -f ${LOGFILE}

}

 

stop() {

    LOGFILE=$(mktemp)

    if [[ -n "${DASUSR}" ]]; then

        ebegin "Stopping IBM DB2 administration instance ${DASUSR}"

        INSTHOME="$(find_homedir ${DASUSR})"

        su ${DASUSR} -c "\

            source ${INSTHOME}/das/dasprofile ; \

            db2admin stop" >${LOGFILE} 2>&1

        rc=${?}

        eend ${rc}

        [[ ${rc} -ne 0 ]] && cat ${LOGFILE}

    fi

    for db2inst in ${DB2INSTS}; do

        ebegin "Stopping IBM DB2 database instances ${db2inst}"

        INSTHOME="$(find_homedir ${db2inst})"

        su - ${db2inst} -c "\

            source ${INSTHOME}/sqllib/db2profile ; \

            db2stop force" >${LOGFILE} 2>&1

        rc=${?}

        eend ${rc}

        [[ ${rc} -ne 0 ]] && cat ${LOGFILE}

    done

    rm -f ${LOGFILE}

}

15、设置DB2环境变量

db2set DB2_CAPTURE_LOCKTIMEOUT=ON

db2set DB2_SKIPINSERTED=ON

db2set DB2_EVALUNCOMMITTED=ON

db2set DB2CONNECT_IN_APP_PROCESS=NO

db2set DB2COMM=tcpip

db2set DB2CODEPAGE=1386

db2set DB2AUTOSTART=YES

 


二、  恢复DB2数据库

目的:把外网的备份文件,恢复到内网测试环境中

1、磁盘空间规划:

恢复数据库之前要做好磁盘空间规划,外网DB28600G硬盘,内部测试环境则为61T硬盘。因为服务器使用软Raid10,所以规划时需要在外网使用df –lh,查看外网的磁盘规划是什么样的。然后在内网做出来的分区要与外网一样。大概计算方式为:

比如一个分区做完Raid10后为80G,实际上占用磁盘分区大小是160G,8块磁盘的话,也就是每个磁盘上一个分区分出20G个做Raid10,做完Raid10后为80G

6块磁盘的话大概就是Raid10之前的160G/6块磁盘=6块磁盘上某分区的大小。

2、准备备份数据:

从外网DB2服务器上拷贝DB2的备份文件到测试环境,备份文件为:

/data/bak/UNA_WWW.0.db2inst1.NODE0000.CATN0000.20130219000003.001

3、开始恢复(切换到db2inst1用户):

db2inst1@db2 ~ $ db2 RESTORE DB UNA_WWW FROM /data/bak/ TAKEN AT 20130219000003当看到successful字样,说明恢复成功(此过程非常漫长,建议放到晚上进行)

4、连接数据库:

db2inst1@db2 ~ $ db2 connect to UNA_WWW

报错:SQL1117N  A connection to or activation of database "UNA_WWW" cannot be made

because of ROLL-FORWARD PENDING.  SQLSTATE=57019

原因:此原因是数据库恢复成功,但需要做日志回滚操作才能正常连接数据库。

解决:db2inst1@db2 ~ $ db2 rollforward db UNA_WWW to end of logs

报错:SQL4970N  Roll-forward recovery on database "UNA_WWW" cannot reach the

specified stop point (end-of-log or point-in-time) on database partition(s)

"0". Roll-forward recovery processing has halted on log file "S0363523.LOG".

原因:提示恢复到end of logs需要日志文件S0363523.LOG

解决:db2inst1@db2 ~ $ db2 "restore database UNA_WWW logs from '/data/bak/' taken at 20130219000003 logtarget '/data/bak/logs/'"

/data/bak/logs目录不存在,则新建,注意权限!当出现如下字样,说明提取日志成功:

DB20000I  The RESTORE DATABASE command completed successfully.

继续进行日志回滚操作:

db2inst1@db2 ~ $ db2 "rollforward database UNA_WWW to end of logs and COMPLETE overflow log path('/data/bak/logs')"

报错:SQL1218N  There are no pages currently available in bufferpool "".  SQLSTATE=57011

原因:由于恢复的数据库buffer pool的设置很大,测试机器内存只有32G,正式环境内存则比这个大

解决:db2inst1@db2 ~ $ db2set DB2_OVERRIDE_BPF=500

再次进行日志回滚操作:

db2inst1@db2 ~ $ db2 "rollforward database UNA_WWW to end of logs and complete overflow log path('/data/bak/logs')"

提示如下,则表示回滚成功:

                                 Rollforward Status

 

 Input database alias                   = UNA_WWW

 Number of nodes have returned status   = 1

 

 Node number                            = 0

 Rollforward status                     = not pending

 Next log file to be read               =

 Log files processed                    = S0363523.LOG - S0363572.LOG

 Last committed transaction             = 2013-02-19-07.53.47.000000 Local

DB20000I  The ROLLFORWARD command completed successfully.

连接数据库:

db2inst1@db2 ~ $ db2 connect to UNA_WWW

Database Connection Information

 

 Database server        = DB2/LINUXX8664 9.5.10

 SQL authorization ID   = DB2INST1

 Local database alias   = UNA_WWW

5、恢复成功

阅读(1421) | 评论(0) | 转发(1) |
0

上一篇:NTP配置

下一篇:gentoo下搭建nagios

给主人留下些什么吧!~~