Oracle Clusterware的命令集可以分为以下4种:
节点层:osnodes
网络层:oifcfg
集群层:crsctl, ocrcheck,ocrdump,ocrconfig
应用层:srvctl,onsctl,crs_stat
节点层:
管理节点层的命令为:olsnode。
[oracle@node1 bin]$ ./olsnodes -help
Usage: olsnodes [-n] [-p] [-i] [<node> | -l] [-g] [-v]
where
-n print node number with the node name
-p print private interconnect name with the node name
-i print virtual IP name with the node name
<node> print information for the specified node
-l print information for the local node
-g turn on logging
-v run in verbose mode
-n显示每个节点编号
-p显示每个节点用于private interconnect网卡名称
-i显示每个node vip
-g:打印日志信息
-v:打印详细信息
显示每个节点的ID:
[oracle@node1 bin]$ ./olsnodes -n
node1 1
node2 2
显示用于private interconnect网卡名称:
[oracle@node1 bin]$ ./olsnodes -n -p
node1 1 rac1-priv
node2 2 rac2-priv
[oracle@node1 bin]$
显示每个节点的vip:
[oracle@node1 bin]$ ./olsnodes -n -p -i
node1 1 rac1-priv rac1-vip
node2 2 rac2-priv rac2-vip
[oracle@node1 bin]$
网络层:
网络层由各个节点的网络组件组成,包括2个物理网卡和3个IP 地址。对这一层管理时用到的命令是:oifcfg。此命令用来定义和修改Oracle集群需要的网卡属性,这些属性包括网卡的网段地址,子网掩码,接口类型等。 要想正确的使用这个命令,必须先知道Oracle是如何定义网络接口的,Oracle的每个网络接口包括名称,网段地址,接口类型3个属性。
oifcfg 命令的格式:interface_name/subnet:interface_type
这些属性中没有IP地址,但接口类型有两种,public和private,前者说明接口用于外部通信,用于Oracle Net和VIP 地址,而后者说明接口用于私有网络。
接口的配置方式分为两类:global 和node-specific。 前者说明集群所有节点的配置信息相同,也就是说所有节点的配置是对称的;而后者意味着这个节点的配置和其他节点配置不同,是非对称的。
oifcfg命令有以下4个子命令,每个命令可以有不同参数:
Iflist:显示网口列表
Getif: 获得单个网口信息
Setif:配置单个网口
Delif:删除网口
[oracle@node1 bin]$ ./oifcfg -help
Name:
oifcfg - Oracle Interface Configuration Tool.
Usage: oifcfg iflist [-p [-n]]
oifcfg setif {-node <nodename> | -global} {<if_name>/<subnet>:<if_type>}...
oifcfg getif [-node <nodename> | -global] [ -if <if_name>[/<subnet>] [-type <if_type>] ]
oifcfg delif [-node <nodename> | -global] [<if_name>[/<subnet>]]
oifcfg [-help]
<nodename> - name of the host, as known to a communications network
<if_name> - name by which the interface is configured in the system
<subnet> - subnet address of the interface
<if_type> - type of the interface { cluster_interconnect | public | storage }
显示网口列表:
[oracle@node1 bin]$ ./oifcfg iflist
eth0 192.168.2.0
eth1 10.0.0.0
获得网口信息(名称,网段地址,接口类型3个属性):
[oracle@node1 bin]$ ./oifcfg getif
eth0 192.168.2.0 global public
eth1 10.0.0.0 global cluster_interconnect
注:eth0接口的网段地址是192.168.2.0,网卡类型是public,也就是用于oracle net和vip;配置类型global说明所有节点的eth0网卡都属于192.168.2.0网段并都是public类型。
查看public 类型的网卡:
[oracle@node1 bin]$ ./oifcfg getif -type public
eth0 192.168.2.0 global public
查看cluster_interconnect 类型的网卡:
[oracle@node1 bin]$ ./oifcfg getif -type cluster_interconnect
eth1 10.0.0.0 global cluster_interconnect
添加接口配置
[root@raw1 bin]# ./oifcfg setif -global eth0/192.168.1.119:public
[root@raw1 bin]# ./oifcfg setif -global eth1/10.85.10.119:cluster_interconnect
删除接口配置
[root@raw1 bin]# ./oifcfg delif -global
集群层
这一层的管理命令包括crsctl、ocrcheck、ocrdump、ocrconfig,其中后3个命令是针对OCR磁盘的。
CRSCTL:
crsctl是一个命令行工具,用于管理Oracle Clusterware daemons(何谓daemon,又名守护进程、后台进程,名称以字母d结尾)。
这些daemon包括Cluster Synchronization Services (CSS), Cluster-Ready Services (CRS), and Event Manager (EVM)。
查看crsctl的help:
[oracle@node1 bin]$ ./crsctl
Usage: crsctl check crs - checks the viability of the CRS stack
crsctl check cssd - checks the viability of CSS
crsctl check crsd - checks the viability of CRS
crsctl check evmd - checks the viability of EVM
crsctl set css <parameter> <value> - sets a parameter override
crsctl get css <parameter> - gets the value of a CSS parameter
crsctl unset css <parameter> - sets CSS parameter to its default
crsctl query css votedisk - lists the voting disks used by CSS
crsctl add css votedisk <path> - adds a new voting disk
crsctl delete css votedisk <path> - removes a voting disk
crsctl enable crs - enables startup for all CRS daemons
crsctl disable crs - disables startup for all CRS daemons
crsctl start crs - starts all CRS daemons.
crsctl stop crs - stops all CRS daemons. Stops CRS resources in case of cluster.
crsctl start resources - starts CRS resources.
crsctl stop resources - stops CRS resources.
crsctl debug statedump evm - dumps state info for evm objects
crsctl debug statedump crs - dumps state info for crs objects
crsctl debug statedump css - dumps state info for css objects
crsctl debug log css [module:level]{,module:level} ...
- Turns on debugging for CSS
crsctl debug trace css - dumps CSS in-memory tracing cache
crsctl debug log crs [module:level]{,module:level} ...
- Turns on debugging for CRS
crsctl debug trace crs - dumps CRS in-memory tracing cache
crsctl debug log evm [module:level]{,module:level} ...
- Turns on debugging for EVM
crsctl debug trace evm - dumps EVM in-memory tracing cache
crsctl debug log res <resname:level> turns on debugging for resources
crsctl query crs softwareversion [<nodename>] - lists the version of CRS software installed
crsctl query crs activeversion - lists the CRS software operating version
crsctl lsmodules css - lists the CSS modules that can be used for debugging
crsctl lsmodules crs - lists the CRS modules that can be used for debugging
crsctl lsmodules evm - lists the EVM modules that can be used for debugging
If necesary any of these commands can be run with additional tracing by
adding a "trace" argument at the very front.
Example: crsctl trace check css
检查crs状态
[oracle@node1 bin]$ ./crsctl check crs
CSS appears healthy
CRS appears healthy
EVM appears healthy
检查单个状态
[oracle@node1 bin]$ ./crsctl check cssd
CSS appears healthy
[oracle@node1 bin]$ ./crsctl check crsd
CRS appears healthy
[oracle@node1 bin]$ ./crsctl check evmd
EVM appears healthy
启动crs栈,必须使用root用户
# ./crsctl start crs
Attempting to start CRS stack
The CRS stack will be started shortly
停止crs栈,必须使用root用户:
# ./crsctl stop crs
Stopping resources.
Successfully stopped CRS resources
Stopping CSSD.
Shutting down CSS daemon.
Shutdown request successfully issued.
配置crs进程栈是否随着操作系统的启动而自启动,有时出于维护目的需要关闭这个特性,可以用root用户执行下面命令。
# ./crsctl disable crs
# ./crsctl enable crs
这个命令实际是修改了/etc/oracle/scls_scr/node1/root/crsstart这个文件里的内容。
查看votedisk磁盘位置:
[oracle@node1 bin]$ ./crsctl query css votedisk
0. 0 /dev/raw/raw2
located 1 votedisk(s).
[oracle@node1 bin]$
--增加votedisk:
--# ./crsctl add css votedisk /dev/raw/raw3 -force
--Now formatting voting disk: /dev/raw/raw3
--successful addition of votedisk /dev/raw/raw3.
--删除votedisk:
--# ./crsctl delete css votedisk /dev/raw/raw4 -force
--successful deletion of votedisk /dev/raw/raw4.
查看crs参数
[oracle@node1 bin]$ ./crsctl get css misscount
60
[oracle@node1 bin]$
修改crs参数,必须为root用户
# ./crsctl set css miscount 60
CRS由CRS,CSS,EVM三个服务组成,每个服务又是由一系列module组成,crsctl允许对每个module进行跟踪,并把跟踪内容记录到日志中。
查看3个服务各自的模块列表分别如下:
[oracle@node1 bin]$ crsctl lsmodules css
The following are the CSS modules ::
CSSD
COMMCRS
COMMNS
[oracle@node1 bin]$ crsctl lsmodules evm
The following are the EVM modules ::
EVMD
EVMDMAIN
EVMCOMM
EVMEVT
EVMAPP
EVMAGENT
CRSOCR
CLUCLS
CSSCLNT
COMMCRS
COMMNS
[oracle@node1 bin]$ crsctl lsmodules crs
The following are the CRS modules ::
CRSUI
CRSCOMM
CRSRTI
CRSMAIN
CRSPLACE
CRSAPP
CRSRES
CRSCOMM
CRSOCR
CRSTIMER
CRSEVT
CRSD
CLUCLS
CSSCLNT
COMMCRS
COMMNS
[oracle@node1 bin]$
跟踪CSSD模块,需要root用户执行:
# ./crsctl debug log css "CSSD:1"
Configuration parameter trace is now set to 1.
Set CRSD Debug Module: CSSD Level: 1
查看跟踪日志:
复制代码
查看跟踪日志
# pwd
/opt/ora10g/product/10.2.0/crs_1/log/node1/cssd
[oracle@node1 cssd]$ tail -200 ocssd.log|more
应用层:
应用层就是指RAC数据库了,这一层有若干资源组成,每个资源都是一个进程或者一组进程组成的完整服务,这一层的管理和维护都是
围绕这些资源进行的。有如下命令: onsctl,srvctl,crs_stat三个命令。
命令:onsctl
这个命令用于管理配置ONS(Oracle Notification Service). ONS是Oracle Clusterware实现FAN Event Push模型的基础。在传统模型
中,客户端需要定期检查服务器来判断服务端状态,本质上是一个pull模型,Oracle 10g引入了一个全新的PUSH机制--FAN(Fast
Application Notification),当服务端发生某些事件时,服务器会主动的通知客户端这种变化,这样客户端就能尽早得知服务端的变化。而引入这种机制就是依赖ONS实现, 在使用onsctl命令之前,需要先配置ONS服务。
ons配置内容:
在RAC环境中,需要使用$CRS_HOME下的ONS,而不是$ORACLE_HOME下面的ONS, 这点需要注意。 配置文件在$CRS_HOME/opmn/conf/ons.config.
[root@rac1 conf]#pwd
/opt/ora10g/product/10.2.0/crs_1/opmn/conf
[oracle@node1 conf]$ more ons.config
localport=6113
remoteport=6200
loglevel=3
useocr=on
参数说明:
Localport: 这个参数代表本地监听端口,这里本地特指:127.0.0.1这个回环地址,用来和运行在本地的客户端进行通信
Remoteport:这个参数代表的是远程监听端口,也就是除了127.0.0.1以外的所有本地IP地址,用来和远程的客户端进行通信。
Loglevel: Oracle允许跟踪ONS进程的运行,并把日志记录到本地文件中,这个参数用来定义ONS进程要记录的日志级别,从1-9,缺省值是3.
Logfile: 这个参数和loglevel参数一起使用,用于定义ONS进程日志文件的位置,缺省值是$CRS_HOME/opmn/logs/opmn.log
nodes和useocr:这两个参数共同决定了本地的ONS daemon要和哪些远程节点上的ONS daemon进行通信。
Nodes参数值格式如下:Hostname/IP:port[hostname/ip:port]
如:useoce=off
Nodes=rac1:6200,rac2:6200
useocr参数值为on/off,如果useocr是ON, 说明信息保存在OCR中;如果是OFF,说明信息取nodes中的配置。对于单实例而言,要把useocr设置为off。
当useocr=on时,信息保存在DATABASE.ONS_HOSTS键中。如下:
[oracle@node1 bin]$ ./ocrdump -stdout -keyname DATABASE.ONS_HOSTS -xml|more
配置ons:
可以直接编译ONS的配置文件来修改配置。如果使用了OCR,则可以通过racgons命令进行配置,但必须以root用户来执行,如果用oracle用户来执行,不会提示任何错误,但也不会更改任何配置。
若要添加配置,可以使用下面命令:
Racgons add_config rac1:6200 rac2:6200
若要删除配置,可以用下面命令:
Racgons remove_config rac1:6200 rac2:6200
onsctl命令:
使用onsctl命令可以启动,停止,调试ONS,并重新载入配置文件,其命令格式如下:
复制代码
[oracle@node1 bin]$ ./onsctl
usage: ./onsctl start|stop|ping|reconfig|debug
start - Start opmn only.
stop - Stop ons daemon
ping - Test to see if ons daemon is running
debug - Display debug information for the ons daemon
reconfig - Reload the ons configuration
help - Print a short syntax description (this).
detailed - Print a verbose syntax description.
[oracle@node1 bin]$
复制代码
示例:
复制代码
1.在OS级别查看进程状态。
[oracle@node1 bin]$ ps -ef|grep -v grep |grep ons
oracle 5909 1 0 21:59 ? 00:00:00 /opt/ora10g/product/10.2.0/crs_1/opmn/bin/ons -d
oracle 5910 5909 0 21:59 ? 00:00:00 /opt/ora10g/product/10.2.0/crs_1/opmn/bin/ons -d
[oracle@node1 bin]$
2.确认ONS服务的状态
[oracle@node1 bin]$ ./onsctl ping
Number of onsconfiguration retrieved, numcfg = 2
onscfg[0]
{node = node1, port = 6200}
Adding remote host node1:6200
onscfg[1]
{node = node2, port = 6200}
Adding remote host node2:6200
ons is running ...
[oracle@node1 bin]$
3.启动ONS服务
[root@rac1 bin]#./onsctl start
复制代码
4.使用debug选项,可以查看详细信息,其中最有意义的就是能显示所有连接:
复制代码
[oracle@node1 bin]$ ./onsctl debug
ocr命令系列
Oracle Clusterware把整个集群的配置信息放在共享存储上,这个存储就是OCR Disk.在整个集群中,
只有一个节点能对OCR Disk进行读写操作,这个节点叫作Master Node,
所有节点都会在内存中保留一份OCR的拷贝,同时用一个OCR Process从这个内存中读取内容。
OCR内容发生改变时,由Master Node的OCR Process负责同步到其他节点的OCR Process。
因为OCR的内容如此重要,Oracle每4个小时对其做一次备份,并且保留最后的3个备份,以及前一天,前一周的最后一个备份。
这个备份由Master Node CRSD进程完成,备份的默认位置是$CRS_HOME/crs/cdata/<cluster_name>目录下。
每次备份后,备份文件名自动更改,以反应备份时间顺序,最近一次的备份叫作backup00.ocr。这些备份文件除了保存在本地,DBA还应该在其他存储设备上保留一份,以防止意外的存储故障。
命令:ocrdump
该命令能以ASCII的方式打印出OCR的内容,但是这个命令不能用作OCR的备份恢复,也就是说产生的文件只能用作阅读,而不能用于恢复。
命令格式:ocrdump [-stdout] [filename] [-keyname name] [-xml]
参数说明:
-stdout:把内容打印输出到屏幕上
Filename:内容输出到文件中
-keyname:只打印某个键及其子健内容
-xml:以xml格式打印输出
示例:把SYSTEM.css键的内容以.xml格式打印输出到屏幕
[oracle@node1 bin]$ ./ocrdump -stdout -keyname SYSTEM.css -xml|more
<OCRDUMP>
<TIMESTAMP>06/14/2013 22:59:03</TIMESTAMP>
<COMMAND>./ocrdump.bin -stdout -keyname SYSTEM.css -xml </COMMAND>
<KEY>
<NAME>SYSTEM.css</NAME>
<VALUE_TYPE>UNDEF</VALUE_TYPE>
<VALUE><![CDATA[]]></VALUE>
<USER_PERMISSION>PROCR_ALL_ACCESS</USER_PERMISSION>
<GROUP_PERMISSION>PROCR_READ</GROUP_PERMISSION>
<OTHER_PERMISSION>PROCR_READ</OTHER_PERMISSION>
<USER_NAME>root</USER_NAME>
<GROUP_NAME>root</GROUP_NAME>
<KEY>
<NAME>SYSTEM.css.interfaces</NAME>
<VALUE_TYPE>UNDEF</VALUE_TYPE>
<VALUE><![CDATA[]]></VALUE>
<USER_PERMISSION>PROCR_ALL_ACCESS</USER_PERMISSION>
<GROUP_PERMISSION>PROCR_CREATE_SUB_KEY</GROUP_PERMISSION>
<OTHER_PERMISSION>PROCR_READ</OTHER_PERMISSION>
<USER_NAME>oracle</USER_NAME>
<GROUP_NAME>oinstall</GROUP_NAME>
……
这个命令在执行过程中,会在$CRS_HOME/log/<node_name>/client目录下产生日志文件,文件名ocrdump_<pid>.log,如果命令执行出现问题,可以从这个日志查看问题原因。
命令:ocrcheck
ocrcheck命令用于检查OCR内容的一致性,命令执行过程会在$CRS_HOME/log/nodename/client目录下产生ocrcheck_pid.log日志文件。 这个命令不需要参数。
[oracle@node1 bin]$ ./ocrcheck
Status of Oracle Cluster Registry is as follows :
Version : 2
Total space (kbytes) : 104344
Used space (kbytes) : 3832
Available space (kbytes) : 100512
ID : 447841508
Device/File Name : /dev/raw/raw1
Device/File integrity check succeeded
Device/File not configured
Cluster registry integrity check succeeded
[oracle@node1 bin]$
命令:ocrconfig
该命令用于维护OCR磁盘,安装clusterware过程中,如果选择External Redundancy冗余方式,则只能输入一个OCR磁盘位置。但是Oracle允许配置两个OCR磁盘互为镜像,以防止OCR磁盘的单点故障。OCR磁盘和Votedisk磁盘不一样,OCR磁盘最多只能有两个,一个Primary OCR和一个Mirror OCR。
[oracle@node1 bin]$ ./ocrconfig –help
Name:
ocrconfig - Configuration tool for Oracle Cluster Registry.
Synopsis:
ocrconfig [option]
option:
-export <filename> [-s online]
- Export cluster register contents to a file
-import <filename> - Import cluster registry contents from a file
-upgrade [<user> [<group>]]
- Upgrade cluster registry from previous version
-downgrade [-version <version string>]
- Downgrade cluster registry to the specified version
-backuploc <dirname> - Configure periodic backup location
-showbackup - Show backup information
-restore <filename> - Restore from physical backup
-replace ocr|ocrmirror [<filename>] - Add/replace/remove a OCR device/file
-overwrite - Overwrite OCR configuration on disk
-repair ocr|ocrmirror <filename> - Repair local OCR configuration
-help - Print out this help information
Note:
A log file will be created in
$ORACLE_HOME/log/<hostname>/client/ocrconfig_<pid>.log. Please ensure
you have file creation privileges in the above directory before
running this tool.
[oracle@node1 bin]$
查看自助备份:
[oracle@node1 bin]$ ./ocrconfig -showbackup
node1 2013/05/26 23:03:03 /opt/ora10g/product/10.2.0/crs_1/cdata/crs
node2 2013/03/24 16:19:28 /opt/ora10g/product/10.2.0/crs_1/cdata/crs
node1 2013/03/24 15:05:35 /opt/ora10g/product/10.2.0/crs_1/cdata/crs
node1 2013/05/26 23:03:03 /opt/ora10g/product/10.2.0/crs_1/cdata/crs
node1 2013/05/26 23:03:03 /opt/ora10g/product/10.2.0/crs_1/cdata/crs
[oracle@node1 bin]$
[oracle@node1 bin]$ ls -l /opt/ora10g/product/10.2.0/crs_1/cdata/crs
total 15304
-rw-r--r-- 1 root root 4493312 May 26 23:03 backup00.ocr
-rw-r--r-- 1 root root 2150400 Mar 24 15:05 backup01.ocr
-rw-r--r-- 1 root root 4493312 May 26 23:03 day.ocr
-rw-r--r-- 1 root root 4493312 May 26 23:03 week.ocr
[oracle@node1 bin]$
在缺省情况下,OCR自动备份在$CRS_HOME/CRS/CDATA/cluster_name目录下,可以通过ocrconfig -backuploc <directory_name>命令修改到新目录
使用导出,导入进行备份和恢复:
Oracle推荐在对集群做调整时,比如增加,删除节点之前,应该对OCR做一个备份,可以使用export备份到指定文件,如果做了replace或者restore等操作,Oracle建议使用cluvfy comp ocr -n all命令来做一次全面的检查。该命令在clusterware的安装软件里。以下操作具有一定破坏性,测试需谨慎!
1.首先关闭所有节点的CRS
[root@rac1 bin]#./crsctl stop crs
2.用root用户导出OCR内容
[root@rac1 bin]# ./ocrconfig -export /u01/ocr.exp
3.重启CRS
[root@rac1 bin]# ./crsctl start crs
4.检查CRS状态
[root@rac1 bin]# ./crsctl check crs
CSS appears healthy
CRS appears healthy
EVM appears healthy
5.破坏OCR内容
[root@rac1 bin]# dd if=/dev/zero of=/dev/raw/raw1 bs=1024 count=102400
102400+0 records in
102400+0 records out
6.检查OCR一致性
[root@rac1 bin]# ./ocrcheck
PROT-601: Failed to initialize ocrcheck
7.使用cluvfy工具检查一致性
[root@rac1 cluvfy]# ./runcluvfy.sh comp ocr -n all
Verifying OCR integrity
Unable to retrieve nodelist from Oracle clusterware.
Verification cannot proceed.
8.使用Import恢复OCR内容
[root@rac1 bin]# ./ocrconfig -import /u01/ocr.exp
9.再次检查OCR
[root@rac1 bin]# ./ocrcheck
10.使用cluvfy工具检查
[root@rac1 cluvfy]# ./runcluvfy.sh comp ocr -n all
移动ocr文件位置:
实例演示将OCR从/dev/raw/raw1移动到/dev/raw/raw3上。
1.查看是否有OCR备份
[root@rac1 bin]#./ocrconfig -showbackup
如果没有备份,可以立即执行一次导出作为备份:
[root@rac1 bin]#./ocrconfig -export /u01/ocrbackup -s online
2.查看当前OCR配置
[root@rac1 bin]# ./ocrcheck
3.添加一个Mirror OCR
[root@rac1 bin]#./ocrconfig -replace ocrmirror /dev/raw/raw4
4.确认添加成功
[root@rac1 bin]#./ocrcheck
5.改变primary OCR位置
[root@rac1 bin]#./ocrconfig -replace ocr /dev/raw/raw3
确认修改成功:
[root@rac1 bin]#./ocrcheck
6.使用ocrconfig命令修改后,所有RAC节点上的/etc/oracle/ocr.loc文件内容也会自动同步了,如果没有自动同步,可以手工的改成以下内容。
[root@rac1 bin]#more /etc/oracle/ocr.loc
ocrconfig_loc=/dev/raw/raw1
Ocrmirrorconfig_loc=/dev/raw/raw3
local_only=FALSE




