ITPub博客

首页 > 数据库 > Oracle > 【DG】MAA-RAC to RAC ADG配置

【DG】MAA-RAC to RAC ADG配置

原创 Oracle 作者:恩强Boy 时间:2020-07-18 21:56:12 0 删除 编辑

一、  环境规划

primary db name: ORCL

instance_name:   ORCL1,ORCL2

standby db_unique_name:  SBDB

instance_name:   SBDB1,SBDB2

主库RAC VIP:   172.16.70.172/173

SCAN-IP:   172.16.70.175

备库RAC IP:   172.16.70.152/153

SCAN-IP:   172.16.70.154

二、  前提条件

ü  主库RAC 处于归档模式

ü  主库RAC 使用 ASM 实例

ü  备库RAC 已经安装完 GI Grid Infrastructure )、 ASM 实例, Oracle 数据库软件

ü  使用OMF Oracle Managed Files )命名格式

三、  思路清晰

step1: 主库配置

step2: 主库收集文件、执行备份

step3: 主备库配置 Oracle Net(listener.ora,tnsnames.ora)

step4: 创建备库 instance database

step5: 备库开启实时应用

step6: 确认 Data Guard 配置

四、  实施过程

1.  主库配置

1)  主库开启force_logging

SQL> alter database force logging;

2)  主库添加standby logfile

SQL> select group#,thread#,bytes/1024/1024 m,members,status from v$log;

SQL>   alter database add standby logfile thread 1 group 5 size 50m ;

SQL>  alter database add standby logfile thread 1 group 6  size 50m ;

SQL>  alter database add standby logfile thread 1 group 7 size 50m ;

SQL>  alter database add standby logfile thread 2  group 8  size 50m ;

SQL>  alter database add standby logfile thread 2  group 9  size 50m ;

SQL>  alter database add standby logfile thread 2 group 10  size 50m ;

standby 日志组应比每个节点多一组,大小保持一致)

3)  主库修改pfile 参数

SQL> alter system set db_unique_name=ORCL scope= spfile  sid='*' ;

SQL> alter system set log_archive_config='DG_CONFIG= ( ORCL ,SBDB) ' scope=both sid='*' ;

SQL> alter system set log_archive_dest_2='SERVICE= SBDB _STANDBY  LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME= SBDB ' scope=both sid='*';

SQL> alter system set DB_FILE_NAME_CONVERT='+DATA/SBDB','+DATA/ORCL'   scope=spfile sid='*';

SQL> alter system set LOG_FILE_NAME_CONVERT='+DATA/SBDB','+DATA/ORCL'   scope=spfile sid='*';

SQL> alter system set standby_file_management=AUTO scope=both sid='*' ;

SQL> alter system set fal_ client =' ORCL_PRIMARY ' scope=both sid='*';

SQL>   alter system set fal_server=' SBDB _STANDBY ' scope=both sid='*';

4)  重启db ,使参数生效

grid 用户)

$ srvctl stop database -d ORCL

$ srvctl start database -d ORCL

2.  主库收集文件、执行备份

1)  主库创建临时文件夹

$ mkdir -p /home/oracle/temp

2)  备库创建相同文件夹

$ mkdir -p /home/oracle/temp

3)  主库创建pfile

SQL> create pfile='/home/oracle/temp/initORCL.ora' from spfile;

4)  主库执行RMAN 备份,并将备份集放在 temp 目录下

RMAN> backup format '/home/oracle/temp/db_arch_%U' database plus archivelog;

RMAN> backup format '/home/oracle/temp/control_%U' current controlfile for standby;

5)  Oracle 用户复制 tnsnames.ora 放在 temp 目录下

$ cp $ORACLE_HOME/network/admin/ tnsnames .ora /home/oracle/temp/

6)  grid 用户复制 listener.ora 放在 temp 目录下

$ cp $ORACLE_HOME/network/admin/listener.ora /home/oracle/temp/

7)  temp 文件夹所有东西传输到备库 temp 文件夹

$ scp /home/oracle/temp/* 172.16.70.150:/home/oracle/temp/

3.  配置listener.ora tnsnames.ora

1)  备库grid 用户复制 listener.ora 到两节点 $ORACLE_HOME/network/admin/

2)  备库两节点修改listener.ora ,添加以下内容

(备库 1 节点

SID_LIST_LISTENER =

   (SID_LIST =

        (SID_DESC =

          (GLOBAL_DBNAME = SBDB )

        (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

          (SID_NAME = SBDB1 )

        )

)

(备库 2 节点

SID_LIST_LISTENER =

   (SID_LIST =

        (SID_DESC =

          (GLOBAL_DBNAME = SBDB )

        (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

          (SID_NAME = SBDB2 )

        )

)

开启备库监听

grid 用户

$ srvctl stop listener

$ srvctl start listener

3)  主备库两节点修改tnsnames.ora

Oracle 用户)

主备库(1&2 节点)

ORCL =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = ORCL)

    )

  )

ORCL_PRIMARY =

  (DESCRIPTION =

     (ADDRESS_LIST =

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

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

     )

     (CONNECT_DATA =

       (SERVER = DEDICATED)

       (SERVICE_NAME = ORCL)

    )

  )

 

SBDB =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = SBDB)

    )

  )

SBDB_STANDBY =

  (DESCRIPTION =

     (ADDRESS_LIST =

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

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

     )

     (CONNECT_DATA =

       (SERVER = DEDICATED)

       (SERVICE_NAME = SBDB)

    )

  )

4.  创建备库instance database

1)  备库创建密码文件

(备库1 节点)

$ cd /u01/app/oracle/product/11.2.0/db_1/dbs

$ orapwd file=orapwSBDB 1  password=oracle

(备库2 节点)

$ cd /u01/app/oracle/product/11.2.0/db_1/dbs

$ orapwd file=orapwSBDB 2  password=oracle

2)  复制并且重命名备库pfile

(备库1 节点)

$ cp /home/oracle/temp/initORCL.ora /u01/app/oracle/product/11.2.0/db_1/dbs/initSBDB.ora

3)  修改initSBDB.ora

执行以下命令:

$ vi initSBDB.ora

:%s# ORCL #AAAA#g

:%s# SBDB # ORCL #g

:%s#AAAA#SBDB#g

:%s#ORCL_PRIMARY#AAAA#g

:%s#SBDB_STANDBY#ORCL_PRIMARY#g

:%S#AAAA#SBDB_STANDBY#g

注意 db_name 修改回 ORCL ,主备库的 db_name 应保持一致。

最后结果如下:

*.db_unique_name=SBDB

*.audit_file_dest='/u01/app/oracle/admin/SBDB/adump'

*.audit_trail='db'

*.cluster_database=true

*.compatible='11.2.0.4.0'

*.control_files='+DATA/orcl/controlfile/current.260.1045841213'

*.db_block_size=8192

*.db_create_file_dest='+DATA'

*.db_domain=''

*.db_file_name_convert='+DATA/ORCL','+DATA/SBDB'

*.db_name=' ORCL '

*.diagnostic_dest='/u01/app/oracle'

*.dispatchers='(PROTOCOL=TCP) (SERVICE=SBDBXDB)'

*.fal_client='SBDB_STANDBY'

*.fal_server='ORCL_PRIMARY'

SBDB1.instance_number=1

SBDB2.instance_number=2

*.log_archive_config='DG_CONFIG=(SBDB,ORCL)'

*.log_archive_dest_1='LOCATION=+ARCH'

*.log_archive_dest_2='SERVICE=ORCL_PRIAMRY LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL'

*.log_archive_format='%t_%s_%r.dbf'

*.log_file_name_convert='+DATA/ORCL','+DATA/SBDB'

*.memory_target=3279945728

*.open_cursors=300

*.processes=150

*.remote_listener='cluster-scan-ip:1521'

*.remote_login_passwordfile='exclusive'

*.standby_file_management='AUTO'

SBDB2.thread=2

SBDB1.thread=1

SBDB1.undo_tablespace='UNDOTBS1'

SBDB2.undo_tablespace='UNDOTBS2'

4)  给备库添加磁盘组目录

grid 用户)

(备库1 节点)

$ sqlplus / as sysasm

SQL> alter diskgroup DATA add directory'+DATA/SBDB';

5)  备库创建spfile

Oracle 用户)

(备库1 节点)

SQL> create spfile='+DATA/SBDB/spfileSBDB.ora' from pfile='?/dbs/initSBDB.ora';

6)  备库两节点创建pfile

(备库1 节点)

$ cd $ORACLE_HOME/dbs/

$ echo "SPFILE='+DATA/SBDB/spfileSBDB.ora'" > initSBDB1.ora

(备库2 节点)

$ cd $ORACLE_HOME/dbs/

$ echo "SPFILE='+DATA/SBDB/spfileSBDB.ora'" > initSBDB 2 .ora

7)  备库两节点创建目录

$ mkdir -p /u01/app/oracle/admin/SBDB/adump

8)  备库开启到nomount 状态

(备库1 节点)

$ export ORACLE_SID=SBDB1

$ sqlplus / as sysdba

SQL> startup nomount;

9)  备库进行RMAN 复制

(备库1 节点)

$ export ORACLE_SID=SBDB1

$ rman target sys/oracle@ORCL auxiliary /

Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jul 16 15:28:59 2020

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1573621948)

connected to auxiliary database: ORCL (not mounted)

 

RMAN> duplicate target database for standby;

注:对于11g 和以后的版本,我们可以使用以下命令:

RMAN> duplicate target database for standby  from avtive database;

5.  备库开启实时应用

1)  备库查询database 状态

SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;

2)  备库开启实时应用

SQL> ALTER  DATABASE RECOVER MANAGED STANDBY  DATABASE DISCONNECT FROM SESSION;

3)  备库取消实时应用

SQL> ALTER  DATABASE RECOVER MANAGED STANDBY  DATABASE cancel;

4)  开启备库

SQL> alter database open read only;

5)  备库再次开启实时应用

SQL> ALTER  DATABASE RECOVER MANAGED STANDBY  DATABASE DISCONNECT FROM SESSION;

6)  开启备库2 节点

SQL> startup;

7)  SBDB 添加到 GI 中( Oracle 用户)

$ srvctl add database -d SBDB -o /u01/app/oracle/product/11.2.0/db_1

$ srvctl add instance -d SBDB -i SBDB1 -n rac1

$ srvctl add instance -d SBDB -i SBDB2 -n rac2

6.  确定Dataguard 配置

1) 备库查询

SQL> select sequence#, first_time, next_time

from v$archived_log order by sequence#;

2) 主库切换日志

SQL> alter system archive log current;

3) 备库再次查询

SQL> select sequence#, first_time, next_time

from v$archived_log order by sequence#;

 

 

 

 

--------- end ----------


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

请登录后发表评论 登录
全部评论
勤奋,专注和练习

注册时间:2018-04-03

  • 博文量
    76
  • 访问量
    152384