RAC环境下的备份与恢复(二)

本文涉及的产品
对象存储 OSS,20GB 3个月
对象存储 OSS,恶意文件检测 1000次 1年
对象存储 OSS,内容安全 1000次 1年
简介:

本节将简要的介绍下,rac环境下将归档日志存放到集群文件系统场景下的备份和恢复操作,集群文件系统采用oracle的ocfs2;
一:环境介绍
节点1 IP:192.168.1.41/24
操作系统:centos4.8 64位 (kvm虚拟机)
主机名:  rac1.yang.com

节点2 IP:192.168.1.42/24
操作系统: centos4.8 64位 (kvm虚拟机)
主机名:  rac2.yang.com

共享存储IP:192.168.1.100/24
操作系统: rhel6.0 64位
主机名:   rhel6.yang.com

二:安装和配置ocfs2集群文件系统

 [root@rac1 ~]# wget http://oss.oracle.com/projects/ocfs2/dist/files/RedHat/RHEL4/x86_64/1.2.9-1/2.6.9-89.EL/ocfs2-2.6.9-89.EL-debuginfo-1.2.9-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2/dist/files/RedHat/RHEL4/x86_64/1.2.9-1/2.6.9-89.EL/ocfs2-2.6.9-89.ELlargesmp-1.2.9-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2/dist/files/RedHat/RHEL4/x86_64/1.2.9-1/2.6.9-89.EL/ocfs2-2.6.9-89.ELsmp-1.2.9-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2-tools/dist/files/RedHat/RHEL4/x86_64/1.2.7-1/ocfs2-tools-1.2.7-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2-tools/dist/files/RedHat/RHEL4/x86_64/1.2.7-1/ocfs2-tools-debuginfo-1.2.7-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2-tools/dist/files/RedHat/RHEL4/x86_64/1.2.7-1/ocfs2-tools-devel-1.2.7-1.el4.x86_64.rpm
[root@rac1 ~]# wget 
http://oss.oracle.com/projects/ocfs2-tools/dist/files/RedHat/RHEL4/x86_64/1.2.7-1/ocfs2console-1.2.7-1.el4.x86_64.rpm

[root@rac1 ~]# rpm -ivh *.rpm  (在节点2上也需要安装这些rpm包)
準備中...                ########################################### [100%]
   1:ocfs2-tools            ########################################### [ 13%]
   2:ocfs2-2.6.9-89.EL      ########################################### [ 25%]
   3:ocfs2-2.6.9-89.EL-debug########################################### [ 38%]
   4:ocfs2-2.6.9-89.ELlarges########################################### [ 50%]
   5:ocfs2-2.6.9-89.ELsmp   ########################################### [ 63%]
   6:ocfs2console           ########################################### [ 75%]
   7:ocfs2-tools-debuginfo  ########################################### [ 88%]
   8:ocfs2-tools-devel      ########################################### [100%]

利用ocfs2console工具创建配置文件,并复制到节点2上
[root@rac1 ~]# ocfs2console

 

[root@rac2 ~]# cat /etc/ocfs2/cluster.conf 
node:
        ip_port = 7777
        ip_address = 192.168.1.41
        number = 0
        name = rac1
        cluster = ocfs2

node:
        ip_port = 7777
        ip_address = 192.168.1.42
        number = 1
        name = rac2
        cluster = ocfs2

cluster:
        node_count = 2
        name = ocfs2

初始化o2cb,两个节点都需要如下操作
[root@rac1 ~]# /etc/init.d/o2cb unload
Stopping O2CB cluster ocfs2: OK
Unmounting ocfs2_dlmfs filesystem: OK
Unloading module "ocfs2_dlmfs": OK
Unmounting configfs filesystem: OK
Unloading module "configfs": OK

[root@rac1 ~]# /etc/init.d/o2cb configure
Configuring the O2CB driver.

This will configure the on-boot properties of the O2CB driver.
The following questions will determine whether the driver is loaded on
boot.  The current values will be shown in brackets ('[]').  Hitting
<ENTER> without typing an answer will keep that current value.  Ctrl-C
will abort.

Load O2CB driver on boot (y/n) [n]: y
Cluster to start on boot (Enter "none" to clear) [ocfs2]: 
Specify heartbeat dead threshold (>=7) [31]: 61  
Specify network idle timeout in ms (>=5000) [30000]: 
Specify network keepalive delay in ms (>=1000) [2000]: 
Specify network reconnect delay in ms (>=2000) [2000]: 
Writing O2CB configuration: OK
Loading module "configfs": OK
Mounting configfs filesystem at /config: OK
Loading module "ocfs2_nodemanager": OK
Loading module "ocfs2_dlm": OK
Loading module "ocfs2_dlmfs": OK
Mounting ocfs2_dlmfs filesystem at /dlm: OK
Starting O2CB cluster ocfs2: OK

[root@rac1 ~]# /etc/init.d/o2cb status
Module "configfs": Loaded
Filesystem "configfs": Mounted
Module "ocfs2_nodemanager": Loaded
Module "ocfs2_dlm": Loaded
Module "ocfs2_dlmfs": Loaded
Filesystem "ocfs2_dlmfs": Mounted
Checking O2CB cluster ocfs2: Online
  Heartbeat dead threshold: 61
  Network idle timeout: 30000
  Network keepalive delay: 2000
  Network reconnect delay: 2000
Checking O2CB heartbeat: Not active

三:对共享存储进行分区
[root@rac1 ~]# fdisk -l /dev/sda
Disk /dev/sda: 10.7 GB, 10737418240 bytes
64 heads, 32 sectors/track, 10240 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1       10240    10485744   83  Linux

四:利用o2fsconsole工具格式化共享存储,并在各个节点进行挂载
[root@rac1 ~]# ocfs2console

[root@rac1 ~]# mkdir /u01/app/oracle/rac_archivelog
[root@rac1 ~]# mount -t ocfs2 -o datavolume,nointr /dev/sda1 /u01/app/oracle/rac_archivelog/
[root@rac1 ~]# mount |grep sda
/dev/sda1 on /u01/app/oracle/rac_archivelog type ocfs2 (rw,_netdev,datavolume,nointr,heartbeat=local)

[root@rac2 ~]# tail -1 /etc/fstab  (开机自动挂载配置)
/dev/sda1               /u01/app/oracle/rac_archivelog ocfs2 datavolume,nointr 0 0
[root@rac2 ~]# mount -a
[root@rac1 ~]# chown -R oracle.oinstall /u01/app/oracle/rac_archivelog/

五:修改归档路径到集群文件系统上

[oracle@rac1 ~]$ crs_stat -t -v
Name           Type           R/RA   F/FT   Target    State     Host        
----------------------------------------------------------------------
ora....SM1.asm application    0/5    0/0    ONLINE    ONLINE    rac1        
ora....C1.lsnr application    0/5    0/0    ONLINE    ONLINE    rac1        
ora.rac1.gsd   application    0/5    0/0    ONLINE    ONLINE    rac1        
ora.rac1.ons   application    0/3    0/0    ONLINE    ONLINE    rac1        
ora.rac1.vip   application    0/0    0/0    ONLINE    ONLINE    rac1        
ora....SM2.asm application    0/5    0/0    ONLINE    ONLINE    rac2        
ora....C2.lsnr application    0/5    0/0    ONLINE    ONLINE    rac2        
ora.rac2.gsd   application    0/5    0/0    ONLINE    ONLINE    rac2        
ora.rac2.ons   application    0/3    0/0    ONLINE    ONLINE    rac2        
ora.rac2.vip   application    0/0    0/0    ONLINE    ONLINE    rac2        
ora.racdb.db   application    0/0    0/1    ONLINE    ONLINE    rac1        
ora....b1.inst application    0/5    0/0    ONLINE    ONLINE    rac1        
ora....b2.inst application    0/5    0/0    ONLINE    ONLINE    rac2    

[oracle@rac1 ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.5.0 - Production on Thu Dec 15 13:29:44 2011
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

SQL> conn /as sysdba
Connected.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            +FRA
Oldest online log sequence     42
Next log sequence to archive   43
Current log sequence           43
SQL> conn 
sys/123456@racdb2 as sysdba
Connected.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            +FRA
Oldest online log sequence     18
Next log sequence to archive   19
Current log sequence           19

SQL> conn /as sysdba
Connected.
SQL> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/rac_archivelog';
System altered.

SQL> conn sys/123456@racdb2 as sysdba
Connected.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/app/oracle/rac_archivelog
Oldest online log sequence     18
Next log sequence to archive   19
Current log sequence           19
SQL> alter system archive log current;
System altered.

[root@rac2 ~]# ls /u01/app/oracle/rac_archivelog/
1_43_769205632.dbf  2_19_769205632.dbf  lost+found

六:测试数据库的恢复

RMAN> list backup of database summary;

List of Backups
===============
Key     TY LV S Device Type Completion Time     #Pieces #Copies Compressed Tag
------- -- -- - ----------- ------------------- ------- ------- ---------- ---
7       B  0  A DISK        2011-12-12 20:34:22 1       1       NO         RACDB_BAK_20121212
8       B  0  A DISK        2011-12-12 20:34:22 1       1       NO         RACDB_BAK_20121212

 

[oracle@rac1 ~]$ sqlplus test/hr@racdb2 
SQL*Plus: Release 10.2.0.5.0 - Production on Thu Dec 15 13:38:43 2011
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options

SQL> create table t2 as select * from t1;
Table created.

SQL> insert into t2 select * from t2;
1 row created.

SQL> /
2 rows created.

SQL> /
4 rows created.

SQL> commit;
Commit complete.

SQL> conn /as sysdba
Connected.
SQL> alter system archive log current;
System altered.

SQL> select file_name from dba_data_files where tablespace_name='USERS';

FILE_NAME
----------------------------------------
+DATA/racdb/datafile/users.259.769728851

[oracle@rac1 ~]$ srvctl stop database -d racdb -o immediate
[oracle@rac1 ~]$ export ORACLE_SID=+ASM1
[oracle@rac1 ~]$ asmcmd rm -rf +DATA/racdb/datafile/users.259.769728851

[oracle@rac1 ~]$ srvctl start  database -d racdb 
PRKP-1001 : Error starting instance racdb1 on node rac1
CRS-0215: Could not start resource 'ora.racdb.racdb1.inst'.
PRKP-1001 : Error starting instance racdb2 on node rac2
CRS-0215: Could not start resource 'ora.racdb.racdb2.inst'.

[oracle@rac1 ~]$ tail -f /u01/app/oracle/admin/racdb/bdump/alert_racdb1.log
ALTER DATABASE OPEN
This instance was first to open
Thu Dec 15 13:52:03 CST 2011
Errors in file /u01/app/oracle/admin/racdb/bdump/racdb1_dbw0_23072.trc:
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '+DATA/racdb/datafile/users.259.769728851'
ORA-17503: ksfdopn:2 Failed to open file +DATA/racdb/datafile/users.259.769728851
ORA-15012: ASM file '+DATA/racdb/datafile/users.259.769728851' does not exist
ORA-1157 signalled during: ALTER DATABASE OPEN...
Thu Dec 15 13:52:05 CST 2011
Shutting down instance (abort)
License high water mark = 1
Instance terminated by USER, pid = 23262

[oracle@rac1 ~]$ srvctl start  database -d racdb -o mount
[oracle@rac1 ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Thu Dec 15 13:54:43 2011
Copyright (c) 1982, 2007, Oracle.  All rights reserved.
connected to target database: RACDB (DBID=766822397, not open)

RMAN> restore datafile 4;
RMAN> recover datafile 4;
RMAN> alter database open;
database opened
RMAN> exit

[oracle@rac1 ~]$ sqlplus sys/123456@racdb2 as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on Thu Dec 15 13:57:18 2011
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options

SQL> select name,open_mode from v$database;

NAME                        OPEN_MODE
--------------------------- ------------------------------
RACDB                       MOUNTED

SQL> alter database open;
Database altered.

SQL> select * from test.t2;

         A
----------
         1
         1
         1
         1
         1
         1
         1
         1

8 rows selected.

本文转自斩月博客51CTO博客,原文链接http://blog.51cto.com/ylw6006/743205如需转载请自行联系原作者


ylw6006

相关实践学习
借助OSS搭建在线教育视频课程分享网站
本教程介绍如何基于云服务器ECS和对象存储OSS,搭建一个在线教育视频课程分享网站。
相关文章
|
Oracle Java 关系型数据库
RAC 环境中 gc block lost 和私网通信性能问题的诊断
对于每个节点,以及集群汇总统计信息中的global cache数据块丢失的统计信息("gc cr block lost" 和/或 "gc current block lost") 代表了私网通信的包处理效率低或者包的处理存在异常。
259 0
|
数据库 数据安全/隐私保护
使用rman把单机的备份集恢复到RAC的方法
环境准备 在ASM磁盘组里面创建相应的目录
211 0
|
存储 Oracle 关系型数据库