语言
<< 返回文章列表

DBA必备技能:RAC 如何安装新主机识别老存储恢复数据库

2017年12月19日
张大朋
1601

Lunar 拥有超过十年的 ORACLE SUPPORT 从业经验,曾经服务于ORACLE ACS部门,现就职于 ORACLE Sales Consultant 部门,负责的产品主要是 Exadata,Golden Gate,Database 等。


在有些场景下,RAC环境中如果主机出现问题,比如硬件故障等,不能启动,我们需要尽快从存储上启动数据库,恢复业务,这样就需要迁移以前的RAC环境到新的主机环境下。在时间中,恢复过程还是很快的,基本上就是安装软件的过程,如果真实场景恢复业务,有两种方法:

1,按照我这里的方法重新安装主机,恢复RAC和数据库;
2,如果之前有可用的操作系统的备份(比如NBU备份了OS),那么直接使用NBU还原即可;


这里测试的场景是:

重新安装11204的GI(Grid Infrastructure)和ORACLE RDBMS软件,然后识别老存储;操作系统是OEL Linux 6.6, 数据库版本是11.2.0.4,单节点RAC 。

image.png


首先,因为存储使用的是11204的ASM,测试过程只安装11204的GI(Grid Infrastructure)软件,不用OUI配置GI。

/u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
 
Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.

执行root.sh:

/u01/app/11.2.0.4/grid/root.sh
Performing root user operation for Oracle 11g
 
The following environment variables are set as:
    ORACLE_OWNER= grid
    ORACLE_HOME=  /u01/app/11.2.0.4/grid
 
Enter the full pathname of the local bin directory: [/usr/local/bin]:
The contents of "dbhome" have not changed. No need to overwrite.
The contents of "oraenv" have not changed. No need to overwrite.
The contents of "coraenv" have not changed. No need to overwrite.
  
Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
 
Using configuration parameter file: /u01/app/11.2.0.4/grid/crs/install/crsconfig_params
Creating trace directory
User ignored Prerequisites during installation
Installing Trace File Analyzer
OLR initialization - successful
  root wallet
。。。。
Adding Clusterware entries to upstart
CRS-2672: Attempting to start 'ora.mdnsd' on 'lunar5'
CRS-2676: Start of 'ora.mdnsd' on 'lunar5' succeeded
CRS-2672: Attempting to start 'ora.gpnpd' on 'lunar5'
CRS-2676: Start of 'ora.gpnpd' on 'lunar5' succeeded
CRS-2672: Attempting to start 'ora.cssdmonitor' on 'lunar5'
CRS-2672: Attempting to start 'ora.gipcd' on 'lunar5'
CRS-2676: Start of 'ora.cssdmonitor' on 'lunar5' succeeded
CRS-2676: Start of 'ora.gipcd' on 'lunar5' succeeded
CRS-2672: Attempting to start 'ora.cssd' on 'lunar5'
CRS-2672: Attempting to start 'ora.diskmon' on 'lunar5'
CRS-2676: Start of 'ora.diskmon' on 'lunar5' succeeded
CRS-2676: Start of 'ora.cssd' on 'lunar5' succeeded
 
ASM created and started successfully.
 
Disk Group TEMPDG created successfully.
 
clscfg: -install mode specified
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'root', privgrp 'root'..
Operation successful.
CRS-4256: Updating the profile
Successful addition of voting disk 381226346c054f62bf5f219ee16d7e25.
Successfully replaced voting disk group with +TEMPDG.
CRS-4256: Updating the profile
CRS-4266: Voting file(s) successfully replaced
##  STATE    File Universal Id                File Name Disk group
--  -----    -----------------                --------- ---------
 1. ONLINE   381226346c054f62bf5f219ee16d7e25 (/dev/asm-diski) [TEMPDG]
Located 1 voting disk(s).
CRS-2672: Attempting to start 'ora.asm' on 'lunar5'
CRS-2676: Start of 'ora.asm' on 'lunar5' succeeded
CRS-2672: Attempting to start 'ora.TEMPDG.dg' on 'lunar5'
CRS-2676: Start of 'ora.TEMPDG.dg' on 'lunar5' succeeded
Configure Oracle Grid Infrastructure for a Cluster ... succeeded

相应的checkpoint文件内容:

image.png

这里看到“DESC=”ROOTCRS_NODECONFIG” STATE=”SUCCESS””表示GI已经配置完成。
图形界面点击ok,继续执行其余配置,配置完成后,再次检查checkpoint文件:

ll  /u01/app/grid/Clusterware

/ckptGridHA_lunar5.xml

-rw-r--r-- 1 grid oinstall 4176 Feb 15 19:31

/u01/app/grid/Clusterware/ckptGridHA_lunar5.xml

[root@lunar5 ~]# cd /u01/app/grid/Clusterware/
[root@lunar5 Clusterware]# ll
total 8

-rw-r--r-- 1 grid oinstall 4176

Feb 15 19:31 ckptGridHA_lunar5.xml

这里看到,checkpoint文件的日期没有变化,说明checkpoint文件是执行root.sh的时候才有用的,也就是这个过程是11.2中为了方便客户,增加了root.sh的失败后继续配置二设计的,非常体贴的功能。在12.2中,该功能更加方便,他将会只管的告诉你当前配置的检查点情况,如果有些步骤失败后,oracle会自动清除老的配置,以便可以失败安装后不用重装,而是纠正错误后继续配置,类似“断点续传”那种意思。


继续检查老的asm磁盘组:

image.png

将上述磁盘组添加到ASM启动磁盘组的列表中:

image.png

对新添加的磁盘组执行mount和

dismount后,这些磁盘组就会自动添加到ocr中:


image.png

检查ASM磁盘组中的内容(比如包含哪些数据库),因为ASM是采用OMF的,因此大部分情况下,通过磁盘组的目录结构就可以看出来这个存储中以前包含哪些数据库和其他相关信息:

image.png


这里看到,该存储中,包含了一个数据库,crsdg中的信息已经被我删除了,因此,没有老的ocr和voting disk文件了

现在,已经确定只有datadg2上面有数据,因此可以重组磁盘组,以便合理利用空间(后续我要用这个vm做很多其他测试):

image.png

使用kfod查看:

image.png

确认当前的crs状态都是正常的:

[root@lunar5 ~]# crsctl status res -t
——————————————————————————–
NAME TARGET STATE SERVER STATE_DETAILS
——————————————————————————–
Local Resources
——————————————————————————–
ora.DATADG1.dg ONLINE ONLINE lunar5
ora.DATADG2.dg ONLINE ONLINE lunar5
ora.DATADG3.dg ONLINE ONLINE lunar5
ora.LISTENER.lsnr ONLINE ONLINE lunar5
ora.TEMPDG.dg ONLINE ONLINE lunar5
ora.asm ONLINE ONLINE lunar5 Started
ora.gsd OFFLINE OFFLINE lunar5
ora.net1.network ONLINE ONLINE lunar5
ora.ons ONLINE ONLINE lunar5
——————————————————————————–
Cluster Resources
——————————————————————————–
ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE lunar5
ora.cvu 1 ONLINE ONLINE lunar5
ora.lunar5.vip 1 ONLINE ONLINE lunar5
ora.oc4j 1 ONLINE ONLINE lunar5
ora.scan1.vip 1 ONLINE ONLINE lunar5

至此老存储的ASM磁盘组已经在新的主机上可以识别了。


假设原来的主机已经完全不能启动了(比如硬件故障等),只能在存储上的ASM中查找数据库使用的参数文件:

image.png

这里看到,数据库使用的参数文件是spfilelunar.ora,它是spfile.272.892409049的别名文件。
我们在ASM中查看一下:

image.png

检查数据库的spfile的内容:

image.png

这里确定的,该文件+datadg2/lunar/spfilelunar.ora(也就是+DATADG2/LUNAR/PARAMETERFILE/spfile.272.892409049)就是我们需要使用的数据库参数文件。

安装Oracle 11.2.0.4数据库软件,然后执行root.sh,这个没有特别的东西,略。
之后,我们需要修改ORACLE RDBMS的oracle二进制文件的权限,让oracle 数据库进程可以获取ASM磁盘组。

su - grid

$ORACLE_HOME/bin/setasmgidwrap

o=/u01/app/oracle/product/11.2.0.4/

dbhome_1/bin/oracle

ll /u01/app/oracle/product/11.2.0.4/dbhome_1/bin/oracle

-rwsr-s--x 1 oracle asmadmin 239626689 Feb 15 22:09

/u01/app/oracle/product/11.2.0.4/dbhome_1/bin/oracle

注意,这里的/u01/app/oracle/product/11.2.0.4/dbhome_1/bin/oracle就是安装ORACLE RDBMS的ORACLE_HOME。
然后,将数据库添加到CRS中,启动数据库:

srvctl add database -d lunar -n lunar5

-o $ORACLE_HOME

-p +DATADG2/LUNAR/PARAMETERFILE/spfile.272.892409049

-s OPEN -y AUTOMATIC

-a "TEMPDG,DATADG1,DATADG2,DATADG3"

-t IMMEDIATE

检查数据库在ocr中的配置:

srvctl config database -d lunar
Database unique name: lunar
Database name: lunar5
Oracle home: /u01/app/oracle/product/11.2.0.4/dbhome_1
Oracle user: oracle
Spfile: +DATADG2/LUNAR/PARAMETERFILE/spfile.272.892409049
Domain:
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: lunar
Database instances:
Disk Groups: TEMPDG,DATADG1,DATADG2,DATADG3
Mount point paths:
Services:
Type: RAC
Database is administrator managed

启动数据库:

[oracle@lunar5 ~]$ srvctl start database -d lunar

检查crs的状态:

image.png


至此,整个使用新主机识别老存储的RAC(主要是识别ASM)就完成了。如果是文件系统的环境,比这个简单很多,ASM的全部可以省略了。