与CRS有关的命令均存放在$ORA_CRS_HOME/bin目录下,使用时请多加留意。本文将在日常CRS维护中较常用的命令予以演示,供参考。
1.启动CRS
如果CRS没有启动在使用crs_stat命令查看集群状态的时候将会收到如下的报错信息。
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stat -t
CRS-0184: Cannot communicate with the CRS daemon.
在RAC环境下启动所有节点上的CRS。
[[email protected] ~]# /oracle/app/crs/bin/crsctl start crs
Attempting to start CRS stack
The CRS stack will be started shortly
[[email protected] ~]# /oracle/app/crs/bin/crsctl start crs
Attempting to start CRS stack
The CRS stack will be started shortly
集群从启动到全部启动完毕的总时间与系统想能和配置有关,一般需要3~10分钟的时间,请耐心等待。
注意:为保证集群环境可以正常无误的启动,一定要确保集群环境中各个节点的时钟保持一致。
与之对应的停止CRS命令为:“crsctl stop crs”。
2.查看CRS资源状态
集群资源启动完毕后,以在第一节点查看集群状态为例。
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE ONLINE rac1
ora....B2.inst application ONLINE ONLINE rac2
ora.RACDB.db application ONLINE ONLINE rac2
ora....DB1.srv application ONLINE ONLINE rac1
ora....DB2.srv application ONLINE ONLINE rac2
ora.....taf.cs application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
3.关闭特定集群资源
1)获取集群资源名的方法
crs_stat命令会给出集群资源名的基本信息,结合适当的Shell技巧便可以得到当前环境下集群资源名信息。
[email protected] /home/oracle$ crs_stat | grep -i name= | cut -d '=' -f2
ora.RACDB.RACDB1.inst
ora.RACDB.RACDB2.inst
ora.RACDB.db
ora.RACDB.taf.RACDB1.srv
ora.RACDB.taf.RACDB2.srv
ora.RACDB.taf.cs
ora.rac1.ASM1.asm
ora.rac1.LISTENER_RAC1.lsnr
ora.rac1.gsd
ora.rac1.ons
ora.rac1.vip
ora.rac2.ASM2.asm
ora.rac2.LISTENER_RAC2.lsnr
ora.rac2.gsd
ora.rac2.ons
ora.rac2.vip
2)以关闭ora.RACDB.RACDB1.inst资源为例
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stop ora.RACDB.RACDB1.inst
Attempting to stop `ora.RACDB.RACDB1.inst` on member `rac1`
Stop of `ora.RACDB.RACDB1.inst` on member `rac1` succeeded.
提示已成功关闭RACDB1数据库实例。
确认关闭后集群 资源 状态:
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application OFFLINE OFFLINE
ora....B2.inst application ONLINE ONLINE rac2
ora.RACDB.db application ONLINE ONLINE rac2
ora....DB1.srv application ONLINE OFFLINE
ora....DB2.srv application ONLINE ONLINE rac2
ora.....taf.cs application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
4.启动特定集群资源
启动ora.RACDB.RACDB1.inst 资源
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_start ora.RACDB.RACDB1.inst
Attempting to start `ora.RACDB.RACDB1.inst` on member `rac1`
Start of `ora.RACDB.RACDB1.inst` on member `rac1` succeeded.
确认启动后状态:
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE ONLINE rac1
ora....B2.inst application ONLINE ONLINE rac2
ora.RACDB.db application ONLINE ONLINE rac2
ora....DB1.srv application ONLINE ONLINE rac1
ora....DB2.srv application ONLINE ONLINE rac2
ora.....taf.cs application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
5.同时停掉所有集群资源
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stop -all
Attempting to stop `ora.RACDB.taf.RACDB1.srv` on member `rac1`
Attempting to stop `ora.rac1.gsd` on member `rac1`
Attempting to stop `ora.RACDB.taf.cs` on member `rac1`
Attempting to stop `ora.rac1.ons` on member `rac1`
Attempting to stop `ora.RACDB.taf.RACDB2.srv` on member `rac2`
Attempting to stop `ora.rac2.gsd` on member `rac2`
Attempting to stop `ora.rac2.ons` on member `rac2`
Stop of `ora.RACDB.taf.RACDB2.srv` on member `rac2` succeeded.
Stop of `ora.RACDB.taf.RACDB1.srv` on member `rac1` succeeded.
Attempting to stop `ora.RACDB.db` on member `rac2`
Stop of `ora.rac2.gsd` on member `rac2` succeeded.
Stop of `ora.rac1.gsd` on member `rac1` succeeded.
Stop of `ora.rac1.ons` on member `rac1` succeeded.
Stop of `ora.rac2.ons` on member `rac2` succeeded.
Stop of `ora.RACDB.taf.cs` on member `rac1` succeeded.
Stop of `ora.RACDB.db` on member `rac2` succeeded.
`ora.RACDB.RACDB1.inst` is already OFFLINE.
`ora.RACDB.RACDB2.inst` is already OFFLINE.
Attempting to stop `ora.rac1.LISTENER_RAC1.lsnr` on member `rac1`
Attempting to stop `ora.rac1.ASM1.asm` on member `rac1`
Attempting to stop `ora.rac2.ASM2.asm` on member `rac2`
Attempting to stop `ora.rac2.LISTENER_RAC2.lsnr` on member `rac2`
Stop of `ora.rac1.LISTENER_RAC1.lsnr` on member `rac1` succeeded.
Attempting to stop `ora.rac1.vip` on member `rac1`
Stop of `ora.rac2.LISTENER_RAC2.lsnr` on member `rac2` succeeded.
Attempting to stop `ora.rac2.vip` on member `rac2`
Stop of `ora.rac1.vip` on member `rac1` succeeded.
Stop of `ora.rac2.vip` on member `rac2` succeeded.
Stop of `ora.rac2.ASM2.asm` on member `rac2` succeeded.
Stop of `ora.rac1.ASM1.asm` on member `rac1` succeeded.
CRS-0216: Could not stop resource 'ora.RACDB.RACDB1.inst'.
CRS-0216: Could not stop resource 'ora.RACDB.RACDB2.inst'.
确认集群资源停止后状态
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application OFFLINE OFFLINE
ora....B2.inst application OFFLINE OFFLINE
ora.RACDB.db application OFFLINE OFFLINE
ora....DB1.srv application OFFLINE OFFLINE
ora....DB2.srv application OFFLINE OFFLINE
ora.....taf.cs application OFFLINE OFFLINE
ora....SM1.asm application OFFLINE OFFLINE
ora....C1.lsnr application OFFLINE OFFLINE
ora.rac1.gsd application OFFLINE OFFLINE
ora.rac1.ons application OFFLINE OFFLINE
ora.rac1.vip application OFFLINE OFFLINE
ora....SM2.asm application OFFLINE OFFLINE
ora....C2.lsnr application OFFLINE OFFLINE
ora.rac2.gsd application OFFLINE OFFLINE
ora.rac2.ons application OFFLINE OFFLINE
ora.rac2.vip application OFFLINE OFFLINE
6.同时启动所有集群资源
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_start -all
Attempting to start `ora.rac1.vip` on member `rac1`
Attempting to start `ora.rac1.ASM1.asm` on member `rac1`
Attempting to start `ora.rac2.vip` on member `rac2`
Attempting to start `ora.rac2.ASM2.asm` on member `rac2`
Start of `ora.rac1.vip` on member `rac1` succeeded.
Attempting to start `ora.rac1.LISTENER_RAC1.lsnr` on member `rac1`
Start of `ora.rac2.vip` on member `rac2` succeeded.
Attempting to start `ora.rac2.LISTENER_RAC2.lsnr` on member `rac2`
Start of `ora.rac1.LISTENER_RAC1.lsnr` on member `rac1` succeeded.
Start of `ora.rac2.LISTENER_RAC2.lsnr` on member `rac2` succeeded.
Start of `ora.rac1.ASM1.asm` on member `rac1` succeeded.
Attempting to start `ora.RACDB.RACDB1.inst` on member `rac1`
Start of `ora.rac2.ASM2.asm` on member `rac2` succeeded.
Attempting to start `ora.RACDB.RACDB2.inst` on member `rac2`
Start of `ora.RACDB.RACDB2.inst` on member `rac2` succeeded.
Start of `ora.RACDB.RACDB1.inst` on member `rac1` succeeded.
CRS-1002: Resource 'ora.rac1.ons' is already running on member 'rac1'
CRS-1002: Resource 'ora.rac2.ons' is already running on member 'rac2'
CRS-1002: Resource 'ora.RACDB.db' is already running on member 'rac1'
Attempting to start `ora.RACDB.taf.RACDB2.srv` on member `rac2`
Attempting to start `ora.RACDB.taf.cs` on member `rac1`
Attempting to start `ora.RACDB.taf.RACDB1.srv` on member `rac1`
Attempting to start `ora.rac1.gsd` on member `rac1`
Attempting to start `ora.rac2.gsd` on member `rac2`
Start of `ora.RACDB.taf.cs` on member `rac1` succeeded.
Start of `ora.RACDB.taf.RACDB2.srv` on member `rac2` succeeded.
Start of `ora.rac2.gsd` on member `rac2` succeeded.
Start of `ora.RACDB.taf.RACDB1.srv` on member `rac1` succeeded.
Start of `ora.rac1.gsd` on member `rac1` succeeded.
CRS-0223: Resource 'ora.RACDB.db' has placement error.
CRS-0223: Resource 'ora.rac1.ons' has placement error.
CRS-0223: Resource 'ora.rac2.ons' has placement error.
确认集群资源启动后状态
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE ONLINE rac1
ora....B2.inst application ONLINE ONLINE rac2
ora.RACDB.db application ONLINE ONLINE rac1
ora....DB1.srv application ONLINE ONLINE rac1
ora....DB2.srv application ONLINE ONLINE rac2
ora.....taf.cs application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
NOTE:如果集群资源状态是UNKNOWN,使用crs_start –all命令将无法完成正常启动。
7.使用srvctl停止和启动节点应用
[email protected] /home/oracle$ /oracle/app/crs/bin/srvctl stop nodeapps -n rac1
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE ONLINE rac1
ora....B2.inst application ONLINE ONLINE rac2
ora.RACDB.db application ONLINE ONLINE rac1
ora....DB1.srv application ONLINE OFFLINE
ora....DB2.srv application ONLINE ONLINE rac2
ora.....taf.cs application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application OFFLINE OFFLINE
ora.rac1.gsd application OFFLINE OFFLINE
ora.rac1.ons application OFFLINE OFFLINE
ora.rac1.vip application OFFLINE OFFLINE
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
[email protected] /home/oracle$ /oracle/app/crs/bin/srvctl start nodeapps -n rac1
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE ONLINE rac1
ora....B2.inst application ONLINE ONLINE rac2
ora.RACDB.db application ONLINE ONLINE rac1
ora....DB1.srv application ONLINE ONLINE rac1
ora....DB2.srv application ONLINE ONLINE rac2
ora.....taf.cs application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
有关更多的srvctl命令的参考可以通过下面的方法获得:
[email protected] /home/oracle$ /oracle/app/crs/bin/srvctl
Usage: srvctl <command> <object> [<options>]
command: enable|disable|start|stop|relocate|status|add|remove|modify|getenv|setenv|unsetenv|config
objects: database|instance|service|nodeapps|asm|listener
For detailed help on each command and object and its options use:
srvctl <command> <object> -h
使用“-h”选项可以获得更加详细的用法。
8.停止当前节点所有CRS资源
[email protected] /home/oracle$ /oracle/app/crs/bin/crsctl stop resources
Stopping resources. This could take several minutes.
Successfully stopped CRS resources.
[email protected] /home/oracle$ /oracle/app/crs/bin/crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE OFFLINE
ora....B2.inst application ONLINE ONLINE rac2
ora.RACDB.db application ONLINE OFFLINE
ora....DB1.srv application ONLINE OFFLINE
ora....DB2.srv application ONLINE ONLINE rac2
ora.....taf.cs application ONLINE OFFLINE
ora....SM1.asm application ONLINE OFFLINE
ora....C1.lsnr application OFFLINE OFFLINE
ora.rac1.gsd application OFFLINE OFFLINE
ora.rac1.ons application OFFLINE OFFLINE
ora.rac1.vip application OFFLINE OFFLINE
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
9.启动当前节点所有CRS资源
[email protected] /home/oracle$ /oracle/app/crs/bin/crsctl start resources
Starting resources.
Successfully started CRS resources
[email protected] /home/oracle$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE ONLINE rac1
ora....B2.inst application ONLINE ONLINE rac2
ora.RACDB.db application ONLINE ONLINE rac2
ora....DB1.srv application ONLINE ONLINE rac1
ora....DB2.srv application ONLINE ONLINE rac2
ora.....taf.cs application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
10.对CRS后台进程做健康检查
[email protected] /home/oracle$ /oracle/app/crs/bin/crsctl check crs
CSS appears healthy
CRS appears healthy
EVM appears healthy
11.检查OCR
[email protected] /home/oracle$ /oracle/app/crs/bin/ocrcheck
Status of Oracle Cluster Registry is as follows :
Version : 2
Total space (kbytes) : 104216
Used space (kbytes) : 4604
Available space (kbytes) : 99612
ID : 529429773
Device/File Name : /dev/raw/raw1
Device/File integrity check succeeded
Device/File not configured
Cluster registry integrity check succeeded
12.检查表决磁盘
[email protected] /home/oracle$ /oracle/app/crs/bin/crsctl query css votedisk
0. 0 /dev/raw/raw2
located 1 votedisk(s).
13.小结
以上演示了在RAC环境与CRS有关的维护命令,这些命令的使用频率较高,需要熟练掌握。管理CRS的命令较多,建议对每一个命令的具体选项做实际的测试,以便降低误操作的风险。