一、DG环境配置

此次搭建Standby的主库为:” RedHat 6.5+11G+RAC+ASM安装与配置(三节点)”11g单实例ASM安装使用ASMLib的方式,不在使用UDEV方式,磁盘为本机磁盘,非远程挂载的磁盘。本次搭建包含了11g单实例ASM的详细安装过程。

 

1、 基本环境

主库:

实例名:racdb1racdb2racdb3        DB_NAMEracdb              DB_UNIQUE_NAMEracdb

备库:

实例名:racdg                         DB_NAMEracdb              DB_UNIQUE_NAMEracdg

IP172.16.1.15                       HOSTNAMEasm-standby

 

2、 配置软件安装环境

A、安装oracle RAC所需的linux软件包

[root@asm-standby~] # yum –y install binutils* compat-libstdc++* compat-libcap1 * elfutils-libelf*elfutils-libelf-devel* elfutils-libelf-devel-static* gcc* gcc-c++* glibc*glibc-common* glibc-devel* glibc-headers* ksh* libaio* libaio-devel* libgcc*libgomp* libstdc++* libstdc++-devel* make* sysstat* unixODBC * unixODBC-devel*

 

B、配置内核参数

执行如下脚本:

#!/bin/bash
prepareSystem(){
# Set SElinux to disabled mode regardless of its initial value
  sed -i -e's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
  setenforce 0
# stop iptables
  /etc/init.d/iptables stop
  chkconfig --level 0123456iptables off
  chkconfig --level 0123456ip6tables off
}
 
Configure1(){
    cat >> /etc/sysctl.conf<>/etc/security/limits.conf <> /etc/pam.d/login< 
  

[root@asm-standby~] # sh confirure.sh

 

C、创建相关组和用户

创建组:

[root@ asm-standby ~] # groupadd oinstall

[root@ asm-standby ~] # groupadd asmadmin

[root@ asm-standby ~] # groupadd asmdba

[root@ asm-standby ~] # groupadd asmoper

[root@ asm-standby ~] # groupadd dba

[root@ asm-standby ~] # groupadd oper

 

创建grid用户:

节点一ORACLE_SID=+ASM

[root@ asm-standby ~] # useradd -g oinstall -G asmadmin,asmdba,asmoper,dba grid

这里和RAC安装时的所属组不同,多了一个dba组,若不添加此组则会导致数据文件无法写入ASM磁盘组。

[root@ asm-standby ~] # passwd grid

编辑grid用户的环境配置文件(~/.bash_profile),加入如下内容

export PS1="`/bin/hostname -s`-> "

export TMP=/tmp

export TMPDIR=$TMP

export ORACLE_SID=+ASM

export ORACLE_BASE=/u/app/grid

export ORACLE_HOME=/u/app/11.2.0/grid

export ORACLE_TERM=xterm

export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'

export TNS_ADMIN=$ORACLE_HOME/network/admin

export PATH=/usr/sbin:$PATH

export PATH=$ORACLE_HOME/bin:$PATH

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

exportCLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

umask 022

 

创建ORACLE用户:

节点一:ORACLE_SID=racdg

[root@ asm-standby ~] # usermodd -g oinstall-G dba,oper,asmdba,asmadmin oracle

这里和RAC安装时的所属组不同,多了一个asmadmin组,若不添加此组则会导致在使用RMAN恢复时无写入ASM的权限,不过这里也可以通过修改$ORACLE_HOME/bin/oracle的权限来解决,chgrp asmadmin$ORACLE_HOME/bin/oracle,chmod 6751 $ORACLE_HOME/bin/oracle,(root用户下修改)

[root@ asm-standby ~] # passwd oracle

编辑oracle用户的环境配置文件(~/.bash_profile,加入如下内容

export TMP=/tmp

export TMPDIR=$TMP

export ORACLE_SID=racdg   #这里你没看错,就是与主库的SID不同

export ORACLE_BASE=/u/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1

export ORACLE_UNQNAME=racdg

export TNS_ADMIN=$ORACLE_HOME/network/admin

export ORACLE_TERM=xterm

export PATH=/usr/sbin:$PATH

export PATH=$ORACLE_HOME/bin:$PATH

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

exportCLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'

umask 022

 

创建软件安装目录:

[root@ asm-standby ~] # mkdir-p /u/app/grid

[root@ asm-standby ~] # mkdir-p /u/app/11.2.0/grid

[root@ asm-standby ~] # chown-R grid:oinstall /u/app

[root@ asm-standby ~] # mkdir-p /u/app/oracle

[root@ asm-standby ~] # chownoracle:oinstall /u/app/oracle

[root@ asm-standby ~] # chmod -R 775 /u

 

3、  配置ASM磁盘

A、添加磁盘分区:

[root@ asm-standby ~]# fdisk -l | tail -n 4  #分区,但请勿格式化,也不要使用LVM方式分区

    Device Boot      Start         End      Blocks  Id  System

/dev/sdb1               1         1306  10490413+  83 Linux

/dev/sdb2            1307        7834  52436160  83  Linux

/dev/sdb3            7835        13054 41929650   83  Linux

B、安装ASMlib

关于ASMlib包需要注意的问题,需要根据OS内核版本选择对应的ASMlib包,RedHat 5的镜像中是自带,RedHat 6就需要费些功夫了,RedHat6.4之前的版本对应的ASMlib包相对较好查找,RedHat6.4之前使用kmod-oracleasm-2.0.6.rh1-2.el6.x86_64.rpmRedHat6.5请具体

参考https://access.redhat.com/solutions/698613,需要安装的三个ASMlib包如下:

kmod-oracleasm-2.0.6.rh1-3.el6.x86_64.rpm

oracleasmlib-2.0.4-1.el6.x86_64.rpm

oracleasm-support-2.1.8-1.el6.x86_64.rpm

[root@ asm-standby ~]#uname–r        #查看OS内核版本

2.6.32-431.el6.x86_64

[root@ asm-standby ~]#rpm -qpR kmod-oracleasm-2.0.6.rh1-3.el6_5.x86_64.rpm|grep“2.6”

kernel >= 2.6.32-431.el6

kernel < 2.6.32-432.el6     #通过rpm –qpR知道此安装包支持的内核版本范围

[root@ asm-standby ~]#rpm –ivh kmod-oracleasm-2.0.6.rh1-3.el6_5.x86_64.rpm  #按顺序安装

[root@ asm-standby ~]#rpm –ivh oracleasmlib-2.0.4-1.el6.x86_64.rpm

[root@ asm-standby ~]#rpm –ivh oracleasm-support-2.1.8-1.el6.x86_64.rpm

 

C、加载ASMlib模块

[root@ asm-standby ~]#whichoracleasm

/usr/sbin/oracleasm

[root@ asm-standby ~]#oracleasm configure –i  #创建/etc/sysconfig/oracleasm配置文件

Oracle 11g RAC到单实例ASM的物理Standby搭建_第1张图片

[root@ asm-standby ~]#oracleasm init  #创建/dev/oracleasm挂载点

Oracle 11g RAC到单实例ASM的物理Standby搭建_第2张图片

ASM相关服务

D、创建ASM磁盘

[root@ asm-standby ~]#oracleasm createdisk VOL1/dev/sdb1

[root@ asm-standby ~]#oracleasm createdisk VOL2/dev/sdb2

[root@ asm-standby~]#oracleasm createdisk VOL3 /dev/sdb3

[root@ asm-standby ~]#oracleasm scandisks

[root@ asm-standby ~]#oracleasm listdisks

[root@ asm-standby ~]#ls –lh /dev/oracleasm/disks

以上命令均是调用/usr/lib/oracleasm/目录下的脚本,有兴趣的可以认真研究一下。

 

二、DG软件安装

1、安装GRID软件

[root@ asm-standby ~]#export display=0.0

[root@ asm-standby ~]#xhost +

[root@ asm-standby ~]#su - grid

[grid@ asm-standby grid]#./runInstaller    #进入OUI界面,只截取重要截图

Oracle 11g RAC到单实例ASM的物理Standby搭建_第3张图片

这里说说选第二项,而不选第四项的理由:因为第二项是图形化安装和配置,会配置ASM实例,以后开机启动时,会随spfile自启动ASM实例。而如果选第四项的话,则需要使用asmca图形化界面配置ASM实例,启动时,不会随机启动,在安装完软件之后,还会提示执行如下的命令:

/u/app/11.2.0/grid/perl/bin/perl–l /u/app/11.2.0/grid/perl/lib –I /u/app/11.2.0/grid/crs/install /u/app/11.2.0/grid/crs/install/roothas.pl

Oracle 11g RAC到单实例ASM的物理Standby搭建_第4张图片

忽略[INS-32018]错误,这是因为按单实例的方式安装的话,Oracle是不建议将ORACLE_HOME建立在ORACLE_BASE之外的。点击“Yes”,软件会正常安装


Oracle 11g RAC到单实例ASM的物理Standby搭建_第5张图片

root用户执行脚本:

[root@ asm-standby ~]# sh /u/app/oraInventory/orainstRoot.sh

[root@ asm-standby ~]# sh /u/app/11.2.0/grid/root.sh

 

2、安装ORACLE软件

[root@ asm-standby ~]#export display=0.0

[root@ asm-standby ~]#xhost +

[root@ asm-standby ~]#su - grid

[oracle@ asm-standby database]#./runInstaller    #进入OUI界面,只截取重要截图

Oracle 11g RAC到单实例ASM的物理Standby搭建_第6张图片


Oracle 11g RAC到单实例ASM的物理Standby搭建_第7张图片

执行脚本:

[root@ asm-standby~]# sh /u/app/oracle/product/11.2.0/db_1/root.sh


3、 配置ASM磁盘组

之前在安装RAC时,使用的是图像化界面,这里不再使用,而是使用命令进行创建ASM磁盘组。

[root@ asm-standby ~]#su – grid

[grid@ asm-standby ~]#sqlplus / as sysasm

 

SQL>create diskgroup DATA external redundancydisk ‘ORCL:VOL2’;

 

SQL>create diskgroup ARCH external redundancydisk ‘ORCL:VOL3’;

 

这里说明一下如使用ASMLib建立ASM磁盘的话,则ASM磁盘路径为ORCL:ASMDISK_NAME,若使用UDEV方式建立的话,则在使用命令新增磁盘组或新增磁盘时,其磁盘路径为UDEV建立时的绝对路径。

 

[grid@ asm-standby ~]#crs_stat –t –v

Oracle 11g RAC到单实例ASM的物理Standby搭建_第8张图片


三、DG搭建

1 主库操作

A、查看主库

[oracle@ note1 ~]#sqlplus / as sysdba

 

SQL> select name,log_mode,protection_mode,force_loggingfrom v$database;

 

NAME     LOG_MODE     PROTECTION_MODE      FORCE_LOGGING

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

RACDB    ARCHIVELOG   MAXIMUMPERFORMANCE  NO

 

SQL> alter database force logging;

 

Database altered

 

B、创建RAMN备份

[oracle@ note1~]#rman target / 

RMAN> run {

allocate channel c1 type disk;

allocate channel c2 type disk;

backup database format ‘/u/rman/%d_%T_%U.full’;

sql ‘alter system archive log current’;

backup currnet controlfile for standby format‘/u/rman/%d_%T_%U.ctl’;

release channel c1;

release channel c2;

}

因新建的库,没有很频繁的归档切换,这里就不对归档进行备份。

 

C、创建pfile文件

[oracle@ note1 ~]#sqlplus / as sysdba

 

SQL>create pfile=’/u/rman/pfile. ora’ fromspfile;

 

接下来将RMAN备份集、pfile文件和密码文件拷贝到备库

[oracle@ note1 ~]#ls –lh /u/rman

Oracle 11g RAC到单实例ASM的物理Standby搭建_第9张图片


[oracle@ note1~]#scp –r /u/rman/* 172.16.1.15:/u/rman/

[oracle@ note1~]#scp –r $ORACLE_HOME/dbs/orapwracdb1 172.16.1.15:$ORACLE_HOME/dbs/orapwracdg


2、 备库操作

A、 修改备库参数文件

修改前的参数文件:

racdb1.__db_cache_size=956301312
racdb3.__db_cache_size=939524096
racdb2.__db_cache_size=889192448
racdb1.__java_pool_size=16777216
racdb3.__java_pool_size=16777216
racdb2.__java_pool_size=16777216
racdb1.__large_pool_size=16777216
racdb2.__large_pool_size=16777216
racdb3.__large_pool_size=16777216
racdb1.__pga_aggregate_target=1006632960
racdb3.__pga_aggregate_target=1006632960
racdb2.__pga_aggregate_target=1006632960
racdb1.__sga_target=1509949440
racdb3.__sga_target=1509949440
racdb2.__sga_target=1509949440
racdb1.__shared_io_pool_size=0
racdb3.__shared_io_pool_size=0
racdb2.__shared_io_pool_size=0
racdb1.__shared_pool_size=486539264
racdb3.__shared_pool_size=503316480
racdb2.__shared_pool_size=553648128
racdb1.__streams_pool_size=0
racdb3.__streams_pool_size=0
racdb2.__streams_pool_size=0
*.audit_file_dest='/u/app/oracle/admin/racdb/adump'
*.audit_trail='db'
*.cluster_database=true
*.compatible='11.2.0.0.0'
*.control_files='+DATA/racdb/controlfile/current.256.909939065','+ARCH/racdb/controlfile/current.256.909939067'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_name='racdb'
*.db_recovery_file_dest='+ARCH'
*.db_recovery_file_dest_size=6948913152
*.diagnostic_dest='/u/app/oracle'
*.dispatchers='(protocol=TCP)'
racdb3.instance_number=3
racdb2.instance_number=2
racdb1.instance_number=1
*.log_archive_dest_1='LOCATION=+ARCH'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=2506096640
*.open_cursors=300
*.processes=300
*.remote_listener='cluster-scan:1521'
*.remote_login_passwordfile='exclusive'
*.sessions=335
*.shared_servers=20
racdb2.thread=2
racdb3.thread=3
racdb1.thread=1
racdb3.undo_tablespace='UNDOTBS3'
racdb2.undo_tablespace='UNDOTBS2'
racdb1.undo_tablespace='UNDOTBS1'

修改后的参数文件:

racdg.__db_cache_size=956301312
racdg.__java_pool_size=16777216
racdg.__large_pool_size=16777216
racdg.__pga_aggregate_target=1006632960
racdg.__sga_target=1509949440
racdg.__shared_io_pool_size=0
racdg.__shared_pool_size=553648128
racdg.__streams_pool_size=0
*.audit_file_dest='/u/app/oracle/admin/racdg/adump'
*.audit_trail='db'
*.cluster_database=false
*.compatible='11.2.0.0.0'
*.control_files='+DATA/racdg/controlfile/current.256.909939065','+ARCH/racdg/controlfile/current.256.909939067'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_name='racdb'
*.db_recovery_file_dest='+ARCH'
*.db_recovery_file_dest_size=6948913152
*.diagnostic_dest='/u/app/oracle'
*.dispatchers='(protocol=TCP)'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=2506096640
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='exclusive'
*.sessions=335
*.shared_servers=20
*.thread=1
*.undo_tablespace='UNDOTBS1'
*.db_unique_name='racdg'
*.FAL_CLIENT='racdg'
*.FAL_SERVER='racdb1','racdb2','racdb3'
*.LOG_ARCHIVE_CONFIG='dg_config=(racdb,racdg)'
*.LOG_ARCHIVE_DEST_1='LOCATION=+ARCH/RACDG/archivelog/valid_for=(all_logfiles,all_roles) db_unique_name=racdg'
*.LOG_ARCHIVE_DEST_2='SERVICE=racdb1 LGWRASYNC valid_for=(online_logfiles,primary_role) db_unique_name=racdb'
*.LOG_ARCHIVE_DEST_STATE_1=ENABLE
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.STANDBY_FILE_MANAGEMENT=AUTO
*.DB_FILE_NAME_CONVERT='+DATA/RACDB/','+DATA/RACDG/','+ARCH/RACDB/','+ARCH/RACDG/'
*.LOG_FILE_NAME_CONVERT='+ARCH/RACDB/','+ARCH/RACDG/'

B、 RAC主库、备库TNSNAMES.ORA文件:

RACDB =
 (DESCRIPTION =
    (ADDRESS= (PROTOCOL = TCP)(HOST = 172.16.1.10)(PORT = 1521))
    (ADDRESS= (PROTOCOL = TCP)(HOST = 172.16.1.11)(PORT = 1521))
   (CONNECT_DATA =
      (SERVER= DEDICATED)
     (SERVICE_NAME = racdb)
    )
  )
 
RACDB1 =
 (DESCRIPTION =
    (ADDRESS= (PROTOCOL = TCP)(HOST = 172.16.1.7)(PORT = 1521))
   (CONNECT_DATA =
      (SERVER= DEDICATED)
     (SERVICE_NAME = racdb)
     (INSTANCE_NAME = racdb1)
    )
  )
 
RACDB2 =
 (DESCRIPTION =
    (ADDRESS= (PROTOCOL = TCP)(HOST = 172.16.1.8)(PORT = 1521))
   (CONNECT_DATA =
      (SERVER= DEDICATED)
     (SERVICE_NAME = racdb)
     (INSTANCE_NAME = racdb2)
    )
  )
 
RACDB3 =
 (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =172.16.1.9)(PORT = 1521))
   (CONNECT_DATA =
      (SERVER= DEDICATED)
     (SERVICE_NAME = racdb)
     (INSTANCE_NAME = racdb3)
    )
  )
 
RACDG =
 (DESCRIPTION =
    (ADDRESS= (PROTOCOL = TCP)(HOST = 172.16.1.15)(PORT = 1521))
   (CONNECT_DATA =
      (SERVER= DEDICATED)
     (SERVICE_NAME = racdg)
    )
  )


C、 创建备库

[oracle@ asm-standby ~]#mkdir –p /u/app/oracle/admin/racdg/adump

[oracle@ asm-standby ~]#sqlplus / as sysdba

 

SQL> startup nomount pfile=’/u/rman/pfile.ora’;

 

SQL> create spfile from pfile=’/u/rman/pfile.ora’;

 

SQL> shutdown immediate;

 

SQL> startup nomount;

 

[oracle@ asm-standby~]#rman target /

 

RMAN> restore standby controlfile from‘/u/rman/RACDB_20160504_05r4ogte_1_1.ctl’;

 

RMAN>sql ‘alter database mount standby database’;

 

RMAN>restore database;


Oracle 11g RAC到单实例ASM的物理Standby搭建_第10张图片

[oracle@ asm-standby~]#sqlplus / as sysdba

 

SQL>recover managed standby database disconnectfrom session;

#现在执行这个是为将ONLINELOG目录建立起来,因为数据字典中有LOGFILE的记录,会根据记录建立LOGFILE,若不执行的话,在ASMCMD中是看不到ONLINELOG目录的。

 

SQL>alter database recover managed standbydatabase cancel;

 

D、 添加主库参数

[oracle@ note1~]#sqlplus / as sysdba

 

SQL>alter system set standby_file_management=auto scope=both;

 

SQL>alter system setlog_archive_config=’dg_config=(racdg,racdb)’ scope=both;

 

SQL>alter system set fal_server=’racdg’scope=both;

 

SQL>alter system setlog_archive_dest_1=’LOCATION=+ARCH valid_for=(all_logfiles,all_roles)db_unique_name=racdb’ scope=both;

 

SQL>alter system set log_arhive_dest_2=’SERVICE=racdg LGWR ASYNC valid_for=(online_logfiles,primary_role)db_unique_name=racdg' scope=both;

 

SQL>alter system setlog_archive_dest_state_1=ENABLE scope=both;

 

SQL>alter system set log_archive_dest_state_2=ENABLE scope=both;

 

SQL>alter system archive log current;

 

备库查看归档是否传过来了

 

SQL>select sequence#,applied from v$archived_log;

 

F、 创建Standby redolog

RAC数据库:Standby Redo Log组数=(所有节点中日志组数最大值 + 1) * RAC节点数

 

[oracle@ asm-standby~]#sqlplus / as sysdba

 

SQL>alter database add standby logfile thread 1 ('+ARCH') size 50m ;

Database altered. 

SQL> /

Database altered.

SQL> /

Database altered.

SQL> /

Database altered.

SQL>c/1/2

l* alter database add standby logfile thread 2 ('+ARCH') size 50m

SQL>/

Database altered.

SQL> /

Database altered.

SQL> /

Database altered.

SQL> /

Database altered.

SQL>c/2/3

l* alter database add standby logfile thread 3 ('+ARCH') size 50m

SQL>/

Database altered.

SQL> /

Database altered.

SQL> /

Database altered.

SQL> /

Database altered.

 

SQL>recover managed standby database usingcurrent logfile disconnect from session;

 

查看归档是否同步:

wKiom1cp4ivz5nD1AAAbUTc2z7A468.jpg

总结:

     Oracle 11g RAC到单实例ASM的物理Standby搭建其实与使用普通文件无很大区别,只需要将单实例ASM的安装结合起来就没事困难的。在搭建过程中,可能出问题最头痛的就是归档无法从主库中传到备库,经常遇到的error is 1034主备库密码不一致的问题,error is 12520 TNS无法连通问题,这些都较好解决。error1033的话基本上就是备库配置有问题了,主库无法访问备库造成的。