Oracle11g 使用RMAN Duplicate部署ADG
一、准备工作
 
1.修改主机名

# vim /etc/sysconfig/network

# hostname wmssh6-3-56
2.修改hosts,将主机添加到hosts
# cat /etc/hosts
10.0.3.56 tms-56
3.添加时间同步计划任务

# crontab -l

*/1 * * * * /usr/sbin/ntpdate 192.168.254.250 > /dev/null 2>&1

# /usr/sbin/ntpdate 192.168.254.250

4.修改域名解析,以下是南汇的DNS服务器地址

# vim /etc/resolv.conf

nameserver 10.4.42.110
nameserver 10.4.42.120

5.关闭防火墙和selinux

# /etc/init.d/iptables stop

# chkconfig iptables off

# vim /etc/selinux/config

6.磁盘分区和挂载
# fdisk /dev/sdb
# fdisk /dev/sdc
# fdisk /dev/sdd
# fdisk /dev/sde
# fdisk /dev/sdf
# fdisk /dev/sdg
格式化

# mkfs.ext4 /dev/sdb1

# mkfs.ext4 /dev/sdc1
# mkfs.ext4 /dev/sdd1
# mkfs.ext4 /dev/sde1
# mkfs.ext4 /dev/sdf1
# mkfs.ext4 /dev/sdg1

其他5块ssd盘按上面的方式也进行创建
创建挂载目录
[root@localhost ~]# mkdir -p /ssd/data1
[root@localhost ~]# mkdir -p /ssd/data2
[root@localhost ~]# mkdir -p /ssd/data3
[root@localhost ~]# mkdir -p /ssd/data4
[root@localhost ~]# mkdir -p /ssd/data5
[root@localhost ~]# mkdir -p /ssd/data6
挂载磁盘
[root@localhost ~]# mount -o defaults,noatime,nodiratime,barrier=0 /dev/sdb1 /ssd/data1
[root@localhost ~]# mount -o defaults,noatime,nodiratime,barrier=0 /dev/sdc1 /ssd/data2
[root@localhost ~]# mount -o defaults,noatime,nodiratime,barrier=0 /dev/sdd1 /ssd/data3
[root@localhost ~]# mount -o defaults,noatime,nodiratime,barrier=0 /dev/sde1 /ssd/data4
[root@localhost ~]# mount -o defaults,noatime,nodiratime,barrier=0 /dev/sdf1  /ssd/data5
[root@localhost ~]# mount -o defaults,noatime,nodiratime,barrier=0 /dev/sdg1 /ssd/data6
写开机启动文件
# vim /etc/fstab
/dev/sdb1 /ssd/data1 ext4 defaults 0 0
/dev/sdc1 /ssd/data2 ext4 defaults 0 0
/dev/sdd1 /ssd/data3 ext4 defaults 0 0
/dev/sde1 /ssd/data4 ext4 defaults 0 0
/dev/sdf1 /ssd/data5 ext4 defaults 0 0
/dev/sdg1 /ssd/data6 ext4 defaults 0 0
配置好上面的系统环境后重启系统。
/*大于3T的硬盘分区方式

# parted /dev/sdb -s mklabel gpt

# parted /dev/sdb -s mkpart primary 0% 100%

# mkdir /data

# mkfs.ext4 /dev/sdb1

# mount -o nobarrier,noatime,nodiratime /dev/sdb1 /data

# echo ‘/dev/sdb1 /data ext4 defaults,nobarrier,noatime,nodiratime 0 0′ >> /etc/fstab

*/
二、安装Oracle软件
运行11gR2-preinstall,该工具会安装Oracle需要的软件相关包,并会创建用户,调整系统内核参数

# cd /etc/yum.repos.d/
# yum -y install oracle-rdbms-server-11gR2-preinstall
使用Oracle用户配置Oracle环境变量,新增一下内容

$ cat ~/.bash_profile

ORACLE_BASE=/home/oracle/app
ORACLE_HOME=/home/oracle/app/product/11.2.0.3/db_1
export ORACLE_BASE ORACLE_HOME
ORACLE_SID=tms2
export ORACLE_SID
ORACLE_TERM=xterm
export ORACLE_TERM
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export CLASSPATH
PATH=$HOME/bin:$ORACLE_HOME/bin:/home/oracle/tools:$PATH
NLS_LANG=AMERICAN_AMERICA.UTF8
export NLS_LANG
export PATH
alias dbs=’cd $ORACLE_HOME/dbs’
alias  tailalert=’tail  -n 200 -f    /home/oracle/app/diag/rdbms/tms56/tms2/trace/alert_tms2.log’
解压缩Oracle home并进行克隆
$ tar zxvf app.tar.gz
$ cd /home/oracle/app/product/11.2.0.3/db_1/clone/bin
$/home/oracle/app/product/11.2.0.3/db_1/perl/bin/perl  clone.pl ORACLE_BASE=”/home/oracle/app” ORACLE_HOME=”/home/oracle/app/product/11.2.0.3/db_1″ OSDBA_GROUP=dba -defaultHomeName
使用root执行以下命令
# /home/oracle/oraInventory/orainstRoot.sh
# /home/oracle/app/product/11.2.0.3/db_1/root.sh

$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Tue Mar 17 11:13:00 2015
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to an idle instance.

创建监听文件,tnsnames这里将主库和其他备库的信息也添加进来
$ cat listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = /home/oracle/app/product/11.2.0.3/db_1)
(SID_NAME = tms2)
)
)
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.56)(PORT = 1521))
)
$ cat tnsnames.ora
tmsdg1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.17.2.4)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(sid = tms2)
)
)
tmsdg2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.17.2.6)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(sid = tms2)
)
)

tms51 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.51)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = tms2)
)
)

tms56 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.56)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = tms2)
)
)

这时可以启动监听了
$ lsnrctl start
三、配置和创建DG
主库操作:
在主库监听文件tnsnames.ora里面加入新备库的地址
tms56 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.3.56)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = tms2)
)
)
通过tnsping命令测试备库监听连通性
$ tnsping tms56
在主库修改配置文件,新增tms56这个主机
*.log_archive_config=’DG_CONFIG=(tms51,tmsdg1,tmsdg2,tms56)’
*.log_archive_dest_2=’service=tms56 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=tms56′
*.log_archive_dest_state_2=’enable’
可以通过alter system进行动态调整 不需要重启数据库。
alter system set log_archive_config=’DG_CONFIG=(tms51,tmsdg1,tmsdg2,tms56)’ scope=both;
alter system set log_archive_dest_2=’service=tms56 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=tms56′ scope=both;
alter system set log_archive_dest_state_2=’enable’ scope=both;
将主库的pfile和密码文件拷贝到备库
$ scp inittms2.ora orapwtms2 oracle@10.0.3.56:/home/oracle/app/product/11.2.0.3/db_1/dbs/

备库操作:

修改pfile配置文件
[oracle@tms-56 dbs]$ cat inittms2.ora
tms2.__db_cache_size=93952409600
tms2.__java_pool_size=268435456
tms2.__large_pool_size=268435456
tms2.__oracle_base=’/home/oracle/app’ #ORACLE_BASE set from environment
tms2.__pga_aggregate_target=20669530112
tms2.__sga_target=102542344192
tms2.__shared_io_pool_size=0
tms2.__shared_pool_size=7516192768
tms2.__streams_pool_size=0
*.compatible=’11.2.0.0.0′
*.control_files=’/ssd/data1/oracle/oradata/tms2/control.ctl’,’/ssd/data2/oracle/oradata/tms2/control.ctl’,’/ssd/data3/oracle/oradata/tms2/control.ctl’
*.db_block_size=8192
*.db_domain=”
*.db_name=’tms2′
*.db_unique_name=’tms56′
*.diagnostic_dest=’/home/oracle/app’
*.local_listener='(ADDRESS_LIST=(Address=(Protocol=tcp)(Host=10.0.3.56)(Port=1521)))’
*.log_archive_config=’DG_CONFIG=(tms51,tmsdg1,tmsdg2,tms56)’
*.log_archive_dest_1=’LOCATION=/home/oracle/arch’
*.log_archive_dest_2=”
*.log_archive_dest_3=’service=tms51 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=tms51′
*.log_archive_dest_state_1=’enable’
*.log_archive_dest_state_2=’defer’
*.log_archive_format=’%t_%s_%r.dbf’
*.db_file_name_convert=’/data1/oracle/oradata/tms2′,’/ssd/data1/oracle/oradata/tms2′,’/data2/oracle/oradata/tms2′,’/ssd/data2/oracle/oradata/tms2′,’/data3/oracle/oradata/tms2′,’/ssd/data3/oracle/oradata/tms2′,’/data4/oracle/oradata/tms2′,’/ssd/data4/oracle/oradata/tms2′,’/data5/oracle/oradata/tms2′,’/ssd/data5/oracle/oradata/tms2′,’/data6/oracle/oradata/tms2′,’/ssd/data6/oracle/oradata/tms2′
*.log_file_name_convert=’/data/oracle/arch’,’/home/oracle/arch’
*.open_cursors=300
*.processes=3000
*.remote_login_passwordfile=’EXCLUSIVE’
*.resource_manager_plan=”
*.sga_max_size=102400000000
*.sga_target=102400000000
*.standby_file_management=’AUTO’
*.undo_tablespace=’UNDOTBS1′
修改好配置后同时需要创建好对应的目录
配置好参数文件后可以将数据库启动到nomount状态下
SQL> create spfile from pfile;
SQL> startup nomount
使用rman duplicate来创建备库
[oracle@tms-56 dbs]$ rman auxiliary sys/oracle@tms56 target sys/oracle@tms51 nocatalog
RMAN>duplicate target database for standby from active database dorecover nofilenamecheck;
应用日志同步操作命令
SQL> alter database recover managed standby database disconnect;
SQL> alter database recover managed standby database cancel;
SQL> alter database recover managed standby database using current logfile disconnect;
SQL> select open_mode from v$database;
OPEN_MODE
——————–
READ ONLY WITH APPLY
说明:

如果副本数据库与目标库不在同一台机器上,并且副本数据库的在线日志文件路径与目标库相同,则运行duplicate命令时必须指定NOFILENAMECHECK参数以避免冲突提示。晕了吧,异机操作路径相同还必需指定NOFILENAMECHECK。此处oracle表现的很傻,它不知道你要恢复的路径是在另一台机器上,它只是认为要恢复到的路径怎么跟目标数据库表现的一样呢?会不会是要覆盖目标数据库啊,为了避免这种情形,于是它就报错。所以一旦异机恢复,并且路径相同,那么你必须通过指定NOFILENAMECHECK来避免oracle的自动识别。

DORECOVER并不是必选的,如果不指定,则duplicate仅修复数据文件到目标服务器,不过并不会Recover数据文件,最后将standby数据库打开到MOUNT状态,此时新创建的物理standby有可能与primary相差较远(因为备份后所有的redologs均未在standby数据库上应用过),指定DORECOVER参数后,DUPLICATE在修复数据文件到目标路径下后,就会自动对这些文件执行RECOVER。
后续问题:

如果出现如下问题,是因为standby_file_management设置为了’AUTO’, redolog无法转换路径。需要将standby_file_management更改为manaul,然后进行rename操作更改文件路径。并手动从主库拷过来日志文件。

duplicate时的提示如下:

media recovery complete, elapsed time: 00:02:17
Finished recover at 17-MAR-15
ORACLE error from auxiliary database: ORA-01511: error in renaming log/data files
ORA-01275: Operation RENAME is not allowed if standby file management is automatic.
RMAN-05535: WARNING: All redo log files were not defined properly.
alert文件错误提示:
Errors in file /home/oracle/app/diag/rdbms/tms56/tms2/trace/tms2_lgwr_600.trc:
ORA-00313: open failed for members of log group 27 of thread 0
ORA-00312: online log 27 thread 0: ‘/data6/oracle/oradata/tms2/stdredo27.log’
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
查看当前日志文件路径
SQL> select member from v$logfile;
MEMBER
——————————————————————————————————————————————————
/data6/oracle/oradata/tms2/redo01.log
/data6/oracle/oradata/tms2/redo02.log
/data6/oracle/oradata/tms2/redo03.log
/data6/oracle/oradata/tms2/redo04.log
/data6/oracle/oradata/tms2/redo05.log
/data6/oracle/oradata/tms2/stdredo20.log
/data6/oracle/oradata/tms2/stdredo21.log
/data6/oracle/oradata/tms2/stdredo22.log
/data6/oracle/oradata/tms2/stdredo23.log
/data6/oracle/oradata/tms2/stdredo24.log
/data6/oracle/oradata/tms2/redo06.log
MEMBER
——————————————————————————————————————————————————
/data6/oracle/oradata/tms2/redo07.log
/data6/oracle/oradata/tms2/stdredo25.log
/data6/oracle/oradata/tms2/stdredo26.log
/data6/oracle/oradata/tms2/stdredo27.log
15 rows selected.
SQL> alter database rename file ‘/data6/oracle/oradata/tms2/redo01.log’ to ‘/ssd/data6/oracle/oradata/tms2/redo01.log';
alter database rename file ‘/data6/oracle/oradata/tms2/redo01.log’ to ‘/ssd/data6/oracle/oradata/tms2/redo01.log’
*
ERROR at line 1:
ORA-01511: error in renaming log/data files
ORA-01275: Operation RENAME is not allowed if standby file management is automatic.
SQL> show parameter standby
NAME     TYPE VALUE
———————————— ———– ——————————
standby_archive_dest     string ?/dbs/arch
standby_file_management     string AUTO
SQL>  alter system set standby_file_management=manual;
alter database rename file ‘/data6/oracle/oradata/tms2/redo01.log’ to ‘/ssd/data6/oracle/oradata/tms2/redo01.log';
alter database rename file ‘/data6/oracle/oradata/tms2/redo02.log’ to ‘/ssd/data6/oracle/oradata/tms2/redo02.log';
alter database rename file ‘/data6/oracle/oradata/tms2/redo03.log’ to ‘/ssd/data6/oracle/oradata/tms2/redo03.log';
alter database rename file ‘/data6/oracle/oradata/tms2/redo04.log’ to ‘/ssd/data6/oracle/oradata/tms2/redo04.log';
alter database rename file ‘/data6/oracle/oradata/tms2/redo05.log’ to ‘/ssd/data6/oracle/oradata/tms2/redo05.log';
alter database rename file ‘/data6/oracle/oradata/tms2/redo06.log’ to ‘/ssd/data6/oracle/oradata/tms2/redo06.log';
alter database rename file ‘/data6/oracle/oradata/tms2/redo07.log’ to ‘/ssd/data6/oracle/oradata/tms2/redo07.log';
alter database rename file ‘/data6/oracle/oradata/tms2/stdredo20.log’ to ‘/ssd/data6/oracle/oradata/tms2/stdredo20.log';
alter database rename file ‘/data6/oracle/oradata/tms2/stdredo21.log’ to ‘/ssd/data6/oracle/oradata/tms2/stdredo21.log';
alter database rename file ‘/data6/oracle/oradata/tms2/stdredo22.log’ to ‘/ssd/data6/oracle/oradata/tms2/stdredo22.log';
alter database rename file ‘/data6/oracle/oradata/tms2/stdredo23.log’ to ‘/ssd/data6/oracle/oradata/tms2/stdredo23.log';
alter database rename file ‘/data6/oracle/oradata/tms2/stdredo24.log’ to ‘/ssd/data6/oracle/oradata/tms2/stdredo24.log';
alter database rename file ‘/data6/oracle/oradata/tms2/stdredo25.log’ to ‘/ssd/data6/oracle/oradata/tms2/stdredo25.log';
alter database rename file ‘/data6/oracle/oradata/tms2/stdredo26.log’ to ‘/ssd/data6/oracle/oradata/tms2/stdredo26.log';
alter database rename file ‘/data6/oracle/oradata/tms2/stdredo27.log’ to ‘/ssd/data6/oracle/oradata/tms2/stdredo27.log';
alter system set standby_file_management=auto;
更改完成后从主库拷过来日志文件
$ scp *.log oracle@10.0.3.56:/ssd/data6/oracle/oradata/tms2/
或者重建日志

共有 0 条评论

Top