2. 利用duplicate配置容灾端
1.配置容灾端oracle用户的环境变量,这里以192.166.1.61为例。
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/11gR2/db
export GRID_HOME=/opt/oracrs/product/11gR2/grid
export ORACLE_SID=ipccs1
export ORACLE_TERM=xterm
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:$ORACLE_HOME/rdbms/lib
export LD_LIBRARY_PATH
SHLIB_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib
export SHLIB_PATH
# Set shell search paths:
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH:/usr/local/bin
# CLASSPATH must include the following JRE locations:
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export NLS_LANG=AMERICAN_AMERICA.UTF8
export PATH=$ORACLE_HOME/OPatch:$PATH
export NLS_DATE_FORMAT="MM/DD/YYYY HH24:MI:SS"
2.在生产端192.166.1.191产生初始化参数文件:
SQL> create pfile='$ORACLE_HOME/dbs/pfilebackup1017.ora' from SPFILE='+DG_ORA/ipccp/spfileipccp.ora';
其中SPFILE='+DG_ORA/ipccp/spfileipccp.ora'是从$ORACLE_HOME/dbs下的initipccp1.ora里拷贝出来的。
3.将上一步骤中产生的初始化参数文件拷贝到容灾端192.166.1.61对应路径上,在192.166.1.61上检查该文件并修改属主:
oracle@DB1:/opt/oracle/product/11gR2/db/dbs> sudo scp pfilebackup1017.ora
oracle@DB1:/opt/oracle/product/11gR2/db/dbs> ls –la
-rw------- 1 root root 3022 2013-10-17 17:40 pfilebackup1017.ora
oracle@dbfs1:/opt/oracle/product/11gR2/db/dbs> sudo chown oracle:oinstall pfilebackup1017.ora
4.在容灾端节点192.166.1.61上修改pfilebackup1017.ora文件,使得以下参数等于对应的参数值(包括参数值的一对’是在更改时也要加上):
DB_UNIQUE_NAME : ‘ipccs’
CONTROL_FILES : ‘+DG_ORA(CONTROLFILE)/ipccs/ora_ctl01’, ‘+DG_ORA(CONTROLFILE)/ipccs/ora_ctl02’, ‘+DG_ORA(CONTROLFILE)/ipccs/ora_ctl03’
LOG_ARCHIVE_DEST_2 : ‘service="ipccp" LGWR ASYNC NOAFFIRM delay=0 optional compression=disable max_failure=0 max_connections=1 reopen=300 db_unique_name="ipccp" net_timeout=30 valid_for=(all_logfiles, primary_role)’
FAL_SERVER : ‘ipccp’
DB_FILE_NAME_CONVERT : ‘+DG_DATA’, ‘+DG_DATA’
LOG_FILE_NAME_CONVERT : ‘+DG_ORA/ipccp’, ‘+DG_ORA/ipccs’
& 说明:
- 数据库参数db_file_name_convert和log_file_name_convert这两个参数里的路径对里,前者必须是对端的路径,后者必须是本端的路径。
- LOG_ARCHIVE_CONFIG : ‘dg_config=(ipccp,ipccs)’里的ipccp和ipccs均为db_uniqe_name参数值。
- LOG_ARCHIVE_DEST_2 里‘service="ipccp"的ipccp是容灾端tnsnames.ora里的用于连接生产端的连接字符串别名。
- FAL_SERVER 里’ipccp’的ipccp是容灾端tnsnames.ora里的用于连接生产端的连接字符串别名。
5. 利用上一步骤产生的pfilebackup1017.ora生成spfile:
以oracle用户登录192.166.1.61,根据$ORACLE_HOME/dbs/initipccs1.ora的内容获得spfile文件:SPFILE='+DG_ORA/ipccs/spfileipccs.ora'。
如果没有initipccs1.ora,可以在对应目录创建一个,并将SPFILE='+DG_ORA/ipccs/spfileipccs.ora'拷贝到该文件,容灾端两个节点都需要初始化参数文件,192.166.1.61上文件名为initipccs1.ora,192.166.1.60上文件名为initipccs2.ora。
执行以下命令生成spfile:
oracle@dbfs1:/opt/oracle/product/11gR2/db/dbs> sqlplus / as sysdba
SQL>create SPFILE='+DG_ORA/ipccs/spfileipccs.ora' from pfile=’$ORACLE_HOME/dbs/ pfilebackup1017.ora’
6. 在生产端192.166.1.191上将密码文件拷贝到容灾端所有节点,并在每个容灾端节点对属主和文件名进行必要修改:
oracle@DB1:/opt/oracle/product/11gR2/db/dbs> sudo scp orapwipccp1
oracle@DB1:/opt/oracle/product/11gR2/db/dbs> sudo scp orapwipccp1
在192.166.1.61上修改密码文件的属主和文件名:
oracle@dbfs1:/opt/oracle/product/11gR2/db/dbs>sudo chown oracle:oinstall orapwipccp1
oracle@dbfs1:/opt/oracle/product/11gR2/db/dbs> mv orapwipccp1 orapwipccs1
在192.166.1.60上修改密码文件的属主和文件名:
oracle@dbfs2:/opt/oracle/product/11gR2/db/dbs>sudo chown oracle:oinstall orapwipccp1
oracle@dbfs2:/opt/oracle/product/11gR2/db/dbs> mv orapwipccp1 orapwipccs2
7. 将容灾端启动到nomount状态,并使用duplicate将数据文件从生产端拷贝到容灾端。
在192.166.1.61上执行以下SQL将数据库实例启动到nomount状态:
oracle@dbfs1:~> sqlplus / as sysdba
SQL>startup nomount;
在192.166.1.191上执行以下命令数据文件从生产端拷贝到容灾端:
rman target / auxiliary sys/SYS@192.166.1.61:1526/ipccs
RMAN> run {
allocate channel primary1 type disk;
allocate auxiliary channel standby1 type disk;
duplicate target database for standby from active database nofilenamecheck;
}
8.在容灾端节点添加重做日志组:
SQL> alter database add logfile thread 1 group 1 ' +DG_ORA/ipcca/ora_redo01_1' size 524288000;
SQL> alter database add logfile thread 1 group 2 ' +DG_ORA/ipcca/ora_redo02_1' size 524288000;
SQL> alter database add logfile thread 2 group 3 ' +DG_ORA/ipcca/ora_redo03_1' size 524288000;
SQL> alter database add logfile thread 2 group 4 ' +DG_ORA/ipcca/ora_redo04_1' size 524288000;
9.在容灾端节点添加容灾日志组:
SQL> alter database add standby logfile thread 1 group 5 '+DG_ORA/ipccs/ora_sdb05_1' size 524288000;
SQL> alter database add standby logfile thread 1 group 6 '+DG_ORA/ipccs/ora_sdb06_1' size 524288000;
SQL> alter database add standby logfile thread 1 group 7 '+DG_ORA/ipccs/ora_sdb07_1' size 524288000;
SQL> alter database add standby logfile thread 2 group 8 '+DG_ORA/ipccs/ora_sdb08_1' size 524288000;
SQL> alter database add standby logfile thread 2 group 9 '+DG_ORA/ipccs/ora_sdb09_1' size 524288000;
SQL> alter database add standby logfile thread 2 group 10 '+DG_ORA/ipccs/ora_sdb010_1' size 524288000;
& 说明:
- 容灾端容灾日志组必须要比生产端对应thread的重做日志组的组数至少大于一,如生产端两个thread的重做日志组均为3,则容灾端的两个thread的容灾日志组必须至少均为4。
- 容灾日志组大小必须和重做日志一样。
10. 配置容灾端所有节点的监听:
以grid用户登录192.166.1.191,执行以下命令:
grid@dbfs1:/opt/oracrs/product/11gR2/grid/network/admin> srvctl add listener -l listener_dbfs2 -p "TCP:1526"
grid@dbfs1:/opt/oracrs/product/11gR2/grid/network/admin>srvctl start listener -l listener_dbfs2
以grid用户登录192.166.1.61,进入到$ORACLE_HOME/network/admin下,编辑listener.ora添加以下内容:
SID_LIST_LISTENER_DBFS2 =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ipccs)
(ORACLE_HOME = /opt/oracle/product/11gR2/db)
(SID_NAME = ipccs1)
)
)
以oracle用户登录192.166.1.61上数据库实例,修改LOCAL_LISTENER参数值:
oracle@dbfs1:/opt/oracle/product/11gR2/db/network/admin> sqlplus / as sysdba
SQL>alter system set local_listener='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.166.1.115)(PORT=1526))))' scope=both sid=’ipccs1’;
以grid用户登录192.166.1.191,重启监听:
grid@dbfs1:~> srvctl stop listener -l listener_dbfs2
grid@dbfs1:~> srvctl start listener -l listener_dbfs2
以grid用户登录192.166.1.60,进入到$ORACLE_HOME/network/admin下,编辑listener.ora添加以下内容:
SID_LIST_LISTENER_DBFS2 =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ipccs)
(ORACLE_HOME = /opt/oracle/product/11gR2/db)
(SID_NAME = ipccs2)
)
)
以oracle用户登录192.166.1.60上数据库实例,修改LOCAL_LISTENER参数值:
oracle@dbfs2:/opt/oracle/product/11gR2/db/network/admin> sqlplus / as sysdba
SQL>startup;
SQL>alter system set local_listener='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.166.1.116)(PORT=1526))))' scope=both sid=’ipccs2’;
SQL>shutdown immediate;
以grid用户登录192.166.1.60,重启监听:
grid@dbfs2:~> srvctl stop listener -l listener_dbfs2
grid@dbfs2:~> srvctl start listener -l listener_dbfs2
11. 配置容灾端所有节点的tnsnames.ora:
以oracle用户登录192.166.1.61,进入到$ORACLE_HOME/network/admin下,编辑tnsnames.ora添加以下内容:
ipccp =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.166.1.107)(PORT = 1525))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ipccp)
)
)
以oracle用户登录192.166.1.60,进入到$ORACLE_HOME/network/admin下,编辑tnsnames.ora添加以下内容:
ipccp =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.166.1.107)(PORT = 1525))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ipccp)
)
)
12.在容灾端节点192.166.1.61上打开日志应用:
SQL>alter database open;
SQL> alter database recover managed standby database using current logfile disconnect from session;
& 说明:
- 如果执行alter database open;时出现以下错误:
ORA-10458: standby database requires recovery
ORA-01190: control file or data file 1 is from before the last RESETLOGS
ORA-01110: data file 1: '+DG_ORA/ipccp/ora_system'
可以先执行以下命令:
SQL> alter database recover managed standby database using current logfile disconnect from session;
待以上命令执行一会儿,再执行以下命令:
SQL> alter database recover managed standby database cancel;
SQL>alter database open;
SQL> alter database recover managed standby database using current logfile disconnect from session;
13.启动生产端节点192.166.1.190和容灾端节点192.166.1.60上的数据库实例:
SQL> startup;