HeartBeat+ DRBD +Oracle10g HA集群配置实例

Normal 0 0 2 false false false *根据其它相关资料编辑与修改完成

一、安装环境说明

操作系统:CentOS 5.5 X86-64Bit

主要软件及版本:HeartBeat2.1.3DRBD-8.4.0

依赖软件及版本:Libnet 1.1.2.1HeartBeat所需) 

数据库版本:Oracle 10.2.0.1 32

 

二、安装前配置

网卡:

两台机器配双网卡,eth0用于连接公用网络,eth1用于做心跳测试。

 

主机名:

节点1drbd01 节点2drbd02,虚拟节点:DRBD

 

IP

drbd01eth0 10.192.29.168   eth1 10.1.1.8

drbd02eth0 10.192.29.169   eth1 10.1.1.9

虚拟IP10.192.29.170

 

/etc/hosts文件示例如下

10.192.29.168           drbd01

10.192.29.169           drbd02

10.192.29.170           drbd

 

磁盘:

两台机器分别加上一个大小10G的硬盘(Vmware ESX虚拟机环境)。用来做DRBD网络共享存储,并在上面安装Oracle数据库

 

三、安装HeartBeat

两台机器上要做一样的安装和配置

添加用户和用户组

[root@drbd01 ~]# groupadd haclient

[root@drbd01 ~]# useradd -g haclient hacluster

 

首先要安装libnet

[root@drbd01 ~]# cd /usr/local/src/

[root@drbd01 src]# tar zxvf libnet-1.1.2.1.tar.gz

[root@drbd01 src]# cd libnet/

[root@drbd01 libnet]# ./configure

[root@drbd01 libnet]# make

[root@drbd01 libnet]# make install

 

再安装HeartBeat 2.1.3

[root@drbd01 src]# tar zxvf HeartBeat-2-1-3d298bca0d0a.tar.gz

[root@drbd01 src]# cd HeartBeat-2-1-3d298bca0d0a/

[root@drbd01 HeartBeat-2-1-3d298bca0d0a]# ./ConfigureMe configure

[root@drbd01 HeartBeat-2-1-2d298bca0d0a]# make

[root@drbd01 HeartBeat-2-1-2d298bca0d0a]# make install

复制三个配置文件到/etc/ha.d/目录下

[root@drbd01 HeartBeat-2-1-2d298bca0d0a]# cp doc/ha.cf doc/haresources doc/authkeys /etc/ha.d/

 

至此两台机器上的HeartBeat就安装完成,再继续安装DRBD

 

四、安装配置DRBD

1.对虚拟共享磁盘分区

分别在两节点上使用fdisk对要做共享存储的磁盘进行分区,这里整个磁盘只建立一个Primary分区

 

2、安装DRBD

两台机器都要安装drbd

[root@drbd01 src]# tar zxvf drbd-8.4.0.tar.gz

[root@drbd01 src]# cd drbd-8.4.0/

[root@drbd01 drbd-8.4.0]# ./configure

[root@drbd01 drbd-8.4.0]# make rpm

[root@drbd01 drbd-8.4.0]# make km-rpm

[root@drbd01 drbd-8.4.0]# cd /usr/src/redhat/RPMS/i386/

[root@drbd01 i386]# ls

drbd-8.4.0-1.i386.rpm                  drbd-HeartBeat-8.4.0-1.i386.rpm          drbd-pacemaker-8.4.0-1.i386.rpm  drbd-xen-8.4.0-1.i386.rpm

drbd-bash-completion-8.4.0-1.i386.rpm  drbd-km-2.6.18_194.el5-8.4.0-1.i386.rpm  drbd-udev-8.4.0-1.i386.rpm

drbd-debuginfo-8.4.0-1.i386.rpm        drbd-km-debuginfo-8.4.0-1.i386.rpm       drbd-utils-8.4.0-1.i386.rpm

[root@drbd01 i386]# rpm -ivh drbd*

[root@drbd01 i386]# modprobe drbd     #加载drbd到内核

[root@drbd01 i386]# lsmod |grep drbd   #查看是否加载成功

drbd                  250852  0

 

3、配置DRBD

配置文件为/etc/drbd.conf

[root@drbd02 /]# vi /etc/drbd.conf

 

# You can find an example in  /usr/share/doc/drbd.../drbd.conf.example

 

#include "drbd.d/global_common.conf";

#include "drbd.d/*.res";

 

 

global { usage-count yes; }

common { syncer { rate 100M; } }

resource r0 {

        protocol C;

        startup {

 

        }

        disk {

                on-io-error   detach;

                #size 1G;

        }

        net {

        }

        on drbd01 {

                device    /dev/drbd01;

                disk      /dev/sdb1;

                address   10.1.1.8:7789;

                meta-disk internal;

        }

        on drbd02 {

                device    /dev/drbd01;

                disk      /dev/sdb1;

                address   10.1.1.9:7789;

                meta-disk internal;

        }

}

将一台机器上配置好的DRBD.Conf文件拷贝到第二台机器相同目录下,然后在两台机器上都执行如下命令创建r0资源。

 

[root@drbd01 ~]# drbdadm create-md r0

md_offset 21467942912

al_offset 21467910144

bm_offset 21467254784

 

Found ext3 filesystem

    20964116 kB data area apparently used

    20964116 kB left usable by current configuration

 

Even though it looks like this would place the new meta. data into

unused space, you still need to confirm, as this is only a guess.

 

Do you want to proceed?

[need to type 'yes' to confirm] yes

 

You want me to create a v08 style. flexible-size internal meta. data block.

There appears to be a v08 flexible-size internal meta. data block

already in place on /dev/sdb1 at byte offset 21467942912

Do you really want to overwrite the existing v08 meta-data?

[need to type 'yes' to confirm] yes

 

Writing meta. data...

initializing activity log

NOT initializing bitmap

New drbd meta. data block successfully created.

 

4、启动DRBD

再在两台机器上分别启动DRBD

[root@drbd01 ~]# /etc/init.d/drbd start

 

查看DRBD运行状态:

[root@drbd01 ~]# cat /proc/drbd

version: 8.4.0 (api:1/proto:86-100)

GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@drbd01, 2011-12-27 15:00:40

 

 1: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----

ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:20964116

 

目前两台机器上的DRBD都为Secondary模式,因此需要指定哪个为主,哪个为从设备

DRBD01节点上执行如下命令:

[root@drbd01 ~]# drbdsetup /dev/drbd01 primary –force

 

再次在DRBD01节点上查看DRBD运行状态,发现DRBD01已变成主节点,并且两个节点正在同步数据。

[root@drbd01 ~]# cat /proc/drbd

version: 8.4.0 (api:1/proto:86-100)

GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@drbd01, 2011-12-27 15:00:40

 

 1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----

    ns:1149952 nr:0 dw:0 dr:1158144 al:0 bm:69 lo:3 pe:1 ua:8 ap:0 ep:1 wo:b oos:19815188

        [>...................] sync'ed:  5.6% (19348/20472)M

        finish: 0:04:35 speed: 71,808 (71,808) K/sec

这里需要等待一点时间,让数据同步完成。

数据同步完成后再分别查看DRBD的运行状态,此时节点1角色为Primary,节点2角色为Secondary

[root@drbd01 ~]# cat /proc/drbd

version: 8.4.0 (api:1/proto:86-100)

GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@drbd01, 2011-12-27 15:00:40

 

 1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----

ns:20964116 nr:0 dw:0 dr:20964116 al:0 bm:1280 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0

 

[root@drbd02 ~]# cat /proc/drbd

version: 8.4.0 (api:1/proto:86-100)

GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@drbd02, 2011-12-27 15:06:19

 

 1: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----

ns:0 nr:20964116 dw:20964116 dr:0 al:0 bm:1280 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0

 

DRBD设备同一时间只能在primary机器上被使用因此这里只在DRBD01上做设备挂载与格式化:

 

[root@drbd01 ~]# mkfs -t ext3 /dev/drbd01

[root@drbd01 ~]# mkdir /u01   #drbd02上面也要新建这个目录

[root@drbd01 ~]# mount /dev/drbd01 /u01/

到此,DRBD配置完成。

 

五、安装Oracle 10g

在两台机器上,做同样的Oracle安装前的配置,下面以drbd01为例:

查看是否安装libXp,如果没有安装,则用yum进行安装:

[root@drbd01 ~]# rpm –aq | grep libXp

[root@drbd01 ~]# yum install libXp

 

创建用户和用户组:

[root@drbd01 ~]# groupadd  oinstall

[root@drbd01 ~]# groupadd  dba

[root@drbd01 ~]# useradd  -g  oinstall  -G dba  Oracle

[root@drbd01 ~]# passwd Oracle

 

/etc/sysctl.conf里面修改添加如下参数:

kernel.shmall = 2097152

kernel.shmmax = 2147483648

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 = 1048576

net.core.rmem_max = 1048576

net.core.wmem_default = 262144

net.core.wmem_max = 262144

保存后执行如下命令应用参数

[root@drbd01 ~]# sysctl  -p

 

Oracle用户设置限制,加入/etc/security/limits.conf文件,如下:

Oracle                  soft     nproc     2047

Oracle                  hard     nproc     16384

Oracle                  soft     nofile    1024

Oracle                  hard     nofile    65536

 

/etc/pam.d/login文件加入如下内容:

session      required       /lib/security/pam_limits.so

session      required       pam_limits.so

 

编辑/etc/profile 末尾加入如下脚本:

if [ "$USER" = "Oracle" ]; then

  if [ "$SHELL" = "/bin/ksh" ]; then

    ulimit -p 16384

    ulimit -n 65536

  else

    ulimit -u 16384 -n 65536

  fi

fi

 

Oracle BASE目录赋权限:

[root@drbd01 ~]# chown –R Oracle:oinstall /oradate

[root@drbd01 ~]# chmod –R 755 /oradate

 

编辑Oracle用户的.bash_profile文件,加入如下环境变量:

ORACLE_BASE=/oradate

ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1

ORACLE_SID=orcl

PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:/lib:/usr/lib

export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH LD_LIBRARY_PATH

 

修改系统版本文件/etc/redhat-release把如下内容

CentOS release 5.5 (Final)改成

Redhat 4保存

 

解压缩Oracle安装包,注销root,用Oracle用户登录,并启动图形界面

[Oracle@drbd01 ~]$ startx

在图形界面下,开启一个终端,临时修改系统字符变量为英文

[Oracle@drbd01 ~]$ export LANG=en_US

进入Oracle安装包目录,开始安装Oracle

[Oracle@drbd01 ~]$ cd /opt/database/

[Oracle@drbd01 database]$ ./runInstaller

详细图形安装过程参考官方文档

 

安装完成后,对Oracle监听进行配置:

[Oracle@drbd01 database]$ cd $ORACLE_HOME/network/admin

[Oracle@drbd01 database]$ cat listener.ora

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (SID_NAME = PLSExtProc)

      (ORACLE_HOME = /oradate/product/10.2.0/db_1)

      (PROGRAM = extproc)

    )(SID_DESC =

     (GLOBAL_DBNAME = orcl)

     (ORACLE_HOME = /oradate/product/10.2.0/db_1)

     (SID_NAME = orcl)

     )

  )

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))

      (ADDRESS = (PROTOCOL = TCP)(HOST = drbd)(PORT = 1521))

    )

  )

 

LISTENERHOST部分,填上虚拟ip或者虚拟ip的主机名,这里为主机名drbd

最后关闭监听,关闭数据库

 

六、配置HeartBeat

drbd01上进行配置

[root@drbd01 ~]# cd /etc/ha.d/

1authkeys双机互联验证文件

[root@drbd01 ha.d]# cat authkeys

auth 1

1 crc

[root@drbd01 ha.d]# chmod 600 authkeys

 

2、主配置文件ha.cf

[root@drbd01 ha.d]# cat ha.cf

debugfile /var/log/ha-debug          #Debug结果存放文件,排错用

logfile /var/log/ha-log                #HeartBeat日志文件,排错用

logfacility     local0

keepalive 2

deadtime 30

warntime 10

initdead 120

udpport 694

baud    19200

ucast eth1 10.1.1.8  #此处选择单播方式进行通信,ip地址为对方节点的心跳ip

auto_failback on

node    drbd01

node    drbd02

apiauth ipfail gid=root uid=root

ping 10.192.29.1      #一个能正常ping通的ip,这里选择固定的网关

hopfudge 1

 

/var/log/ha-debug/var/log/ha-log两文件存放HeartBeat日志信息,是排错的重要依据

 

3haresources资源配置文件

[root@drbd01 ha.d]# cat haresources

drbd01   IPaddr::10.192.29.170/24/eth0  drbddisk::r0 Filesystem::/dev/drbd1::/u01::ext3

 

Remark

drbd01为主节点的主机名,从节点也同样的配置;

IPaddrHeartBeat对虚拟ip的设置;

drbddisk设置drbd资源的角色r0;

Filesystem挂载drbd磁盘 /dev/drbd1

notechange.shOracle启动关闭脚本。

 

这个脚本存放在/etc/ha.d /resource.d下,脚本内容如下:

[root@drbd01 ha.d]# cat  resource.d/notechange.sh

#!/bin/sh

#It’s used to startup/shutdown Oracle database

 

export ORACLE_BASE=/oradate

export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1

export ORACLE_SID=orcl

export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib:/lib:/usr/lib

 

MOUNTDEV=/dev/drbd01

MOUNTPOINT=/oradate

case $1 in

start)

/bin/mount $MOUNTDEV $MOUNTPOINT

su - Oracle -c "dbstart"

;;

stop)

su – Oracle –c "dbshut"

fuser -k -m -v $MOUNTPOINT

/bin/umount $MOUNTPOINT

;;

*)

echo "Usage: $0 {start|stop}"

;;

esac

 

notechange.sh脚本一定对root用户赋予执行权限,否则HeartBeat启动时会报错

 

其中,需要说明的是dbstartdbshut两个脚本,这两个脚本为安装数据库后,自动生成的脚本,用来启动,关闭监听和数据库,其中dbstart部分地方需要做修改,才能正常启动。修改如下:

ORACLE_HOME_LISTNER=${ORACLE_HOME}

脚本通过ORACLE_HOME_LISTNER的值来定位到监听程序的可执行程序,从而启动监听,由于默认脚本设置的值和自己安装的目录路径不一样,因此需要修改成当前Oracle的安装家目录。

 

4、配置oratab文件

dbstart脚本通过读取/etc/oratab文件来决定是否启动数据库实例,启动哪个数据库实例。

修改如下:

orcl:/oradate/product/10.2.0/db_1:Y

将最后面的N改成Y,则为要启动orcl实例,路径为/u01/product/10.2.0/db_1

 

5、配置文件同步

在主节点上配置完HeartBeat后,需要将配置文件拷贝到从节点上。

 

[root@drbd01 ~]# scp -r drbd02:/etc/ha.d/*  /etc/ha.d/

Remark:

ha.cf文件里面单播通讯的地方,ip地址要填对方节点的心跳ip,除了这里需要修改外,其它地方完全一样!

 

复制主节点/etc/oratab文件到从节点

[root@drbd02 ~]# scp drbd01:/etc/ora*  /etc/

这里将主节点上安装数据库时生成的两个文件都拷贝过来,包括修改后的oratab文件。

 

七、启动HeartBeat

1、确保DRBD已被启动,且磁盘同步完成

[root@drbd01 ~]# cat /proc/drbd

version: 8.4.0 (api:1/proto:86-100)

GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@drbd01, 2011-12-27 15:00:40

 

 1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----

ns:20964644 nr:0 dw:528 dr:20964373 al:7 bm:1280 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0

此时,DRBD已经在正常运行,可以启动HeartBeat了。

 

2、在两台机器上分别启动HeartBeat

[root@drbd01 ~]# /etc/init.d/HeartBeat start

Starting High-Availability services:

2012/01/07_20:32:25 INFO:  Resource is stopped

                                                           [确定]

[root@drbd01 ~]#

 

3、查看DRBD是否挂载

[root@drbd01 ~]# ls /u01/

admin  flash_recovery_area  lost+found  oradata  oraInventory  product

 

可以看到,/u01目录下已经有了Oracle的安装文件了

[root@drbd01 ~]# mount

/dev/sda2 on / type ext3 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

/dev/sda3 on /usr type ext3 (rw)

/dev/sda1 on /boot type ext3 (rw)

tmpfs on /dev/shm type tmpfs (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

.host:/ on /mnt/hgfs type vmhgfs (rw,ttl=1)

none on /proc/fs/vmblock/mountPoint type vmblock (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

/dev/drbd01 on /oradate type ext3 (rw)

 

4、查看侦听状态

[root@drbd01 ~]# su - Oracle

[Oracle@drbd01 ~]$ lsnrctl status

 

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 07-JAN-2012 20:35:06

 

Copyright (c) 1991, 2005, Oracle.  All rights reserved.

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production

Start Date                07-JAN-2012 20:33:00

Uptime                    0 days 0 hr. 2 min. 5 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /oradate/product/10.2.0/db_1/network/admin/listener.ora

Listener Log File         /oradate/product/10.2.0/db_1/network/log/listener.log

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=135.255.10.200)(PORT=1521)))

Services Summary...

Service "PLSExtProc" has 1 instance(s).

  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...

Service "orcl" has 1 instance(s).

  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

 

5、查看数据库的运行状态

[Oracle@drbd01 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jan 7 20:35:48 2012

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

 

SQL> select database_status from v$instance;

 

DATABASE_STATUS

-----------------

ACTIVE

 

SQL> show user;

USER is "SYS"

SQL> !hostname

drbd01

数据库开启并且活跃,用户为sys,当前服务器主机名为drbd01,即主节点。

 

八、测试HeartBeat切换是否正常

关闭主节点drbd01,稍后待HeartBeat切换完成后,到节点2上查看drbd运行状态和数据库的运行状态

[root@drbd02 ~]# cat /proc/drbd

version: 8.4.0 (api:1/proto:86-100)

GIT-hash: 28753f559ab51b549d16bcf487fe625d5919c49c build by root@drbd02, 2011-12-27 15:06:19

 

 1: cs:WFConnection ro:Primary/Unknown ds:UpToDate/DUnknown C r-----

ns:0 nr:20984860 dw:20985092 dr:7561 al:10 bm:1280 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:204

可以看到节点2drbd当前为Primary状态从节点为Unknown

[root@drbd02 ~]# ls /oradate/

admin  flash_recovery_area  lost+found  oradata  oraInventory  product

[root@drbd02 ~]# mount

/dev/sda2 on / type ext3 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

/dev/sda3 on /usr type ext3 (rw)

/dev/sda1 on /boot type ext3 (rw)

tmpfs on /dev/shm type tmpfs (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

.host:/ on /mnt/hgfs type vmhgfs (rw,ttl=1)

none on /proc/fs/vmblock/mountPoint type vmblock (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

/dev/drbd01 on /oradate type ext3 (rw)

 

最后一行表明已经drbd设备已经被节点2挂载,此时虚IP已切换到节点2上。

 

[root@drbd02 ~]# su - Oracle

 

[Oracle@drbd02 ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jan 7 20:43:05 2012

 

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

 

 

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

 

SQL> select status from v$instance;

 

STATUS

------------

OPEN

 

SQL> !hostname

drbd02

数据库为open状态,客户端可用10.192.29.170虚地址连接到数据库。

 

九、DRBD脑裂故障处理

首先要选择一个节点做主节点,这个节点的数据将用于同步从节点

drbdadm  primary r0

 

在选择的主节点上重新连接资源

drbdadm  connect  r0

 

在从节点上重新创建资源

drbdadm  create-md r0

 

此时主从节点开始重新同步数据,数据同步完成后DRBD脑裂即得到解决

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/38267/viewspace-718735/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/38267/viewspace-718735/

你可能感兴趣的:(HeartBeat+ DRBD +Oracle10g HA集群配置实例)