转自:微点阅读 https://www.weidianyuedu.com/content/3117756287208.html
oracle RAc 常用维护工具和命令
oracle 的管理可以通过oEM或者命令行接口。 oracle clusterware的命令集可以分为以下4种:
节点层:osnodes
网络层:oifcfg
集群层:crsctl, ocrcheck,ocrdump,ocrconfig
应用层:srvctl,onsctl,crs_stat
下面分别来介绍这些命令。
一. 节点层
只有一个命令: osnodes, 这个命令用来显示集群点列表,可用的参数如下,这些参数可以混合使用。
[root@raw1 bin]# ./olsnodes --help
Usage: olsnodes [-n] [-p] [-i] [ | -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
print information for the specified node
-l print information for the local node
-g turn on logging
-v run in verbose mode
[root@raw1 bin]# ./olsnodes -n -p -i
raw1 1 raw1-priv raw1-vip
raw2 2 raw2-priv raw2-vip
二. 网络层
网络层由各个节点的网络组件组成,包括2个物理网卡和3个IP 地址。 也只有一个命令:oifcfg.
oifctg 命令用来定义和修改oracle 集群需要的网卡属性,这些属性包括网卡的网段地址,子网掩码,接口类型等。 要想正确的使用这个命令, 必须先知道oracle 是如何定义网络接口的,oracle的每个网络接口包括名称,网段地址,接口类型3个属性。
oifcfg 命令的格式如下: interface_name/subnet:interface_type
这些属性中没有IP地址,但接口类型有两种,public和private,前者说明接口用于外部通信,用于oracle net和VIP 地址,而后者说明接口用于Interconnect。
接口的配置方式分为两类: global 和node-specific。 前者说明集群所有节点的配置信息相同,也就是说所有节点的配置是对称的;而后者意味着这个节点的配置和其他节点配置不同,是非对称的。
Iflist:显示网口列表
Getif: 获得单个网口信息
Setif:配置单个网口
Delif:删除网口
[root@raw1 bin]# ./oifcfg --help
PRIF-9: incorrect usage
name:
oifcfg - oracle Interface configuration Tool.
Usage: oifcfg iflist [-p [-n]]
oifcfg setif {-node | -global} {/:}...
oifcfg getif [-node | -global] [ -if [/] [-type ] ]
oifcfg delif [-node | -global] [[/]]
oifcfg [-help]
- name of the host, as known to a communications network
- name by which the interface is configured in the system
- subnet address of the interface
- type of the interface { cluster_interconnect | public | storage }
[root@raw1 bin]# ./oifcfg iflist
eth0 10.85.10.0
eth1 192.168.1.0
[root@raw1 bin]# ./oifcfg getif
eth0 10.85.10.119 global public
eth0 10.85.10.121 global public
eth0 10.85.10.0 global public
eth1 192.168.1.119 global cluster_interconnect
eth1 192.168.1.121 global cluster_interconnect
eth1 192.168.1.0 global cluster_interconnect
-- 查看public 类型的网卡
[root@raw1 bin]# ./oifcfg getif -type public
eth0 10.85.10.119 global public
eth0 10.85.10.121 global public
eth0 10.85.10.0 global public
-- 删除接口配置
[root@raw1 bin]# ./oifcfg delif -global
-- 添加接口配置
[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
三. 集群层
集群层是指由clusterware组成的核心集群, 这一层负责维护集群内的共享设备,并为应用集群提供完整的集群状态视图,应用集群依据这个视图进行调整。 这一层共有4个命令: crsctl, ocrcheck,ocrdump,ocrconfig. 后三个是针对ocR 磁盘的。
3.1 cRScTL
crsctl 命令可以用来检查cRS 进程栈,每个crs 进程状态,管理Votedisk,跟踪cRS进程功能。
[root@raw1 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 - sets a parameter override
crsctl get css - gets the value of a cSS parameter
crsctl unset css - sets cSS parameter to its default
crsctl query css votedisk - lists the voting disks used by cSS
crsctl add css votedisk - adds a new voting disk
crsctl delete css votedisk - 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 turns on debugging for resources
crsctl query crs softwareversion [] - 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 \
Example: crsctl trace check css
3.1.1 检查cRS 状态
[root@raw1 bin]# ./crsctl check crs
cSS appears healthy
cRS appears healthy
EVM appears healthy
-- 检查单个状态
[root@raw1 bin]# ./crsctl check cssd
cSS appears healthy
[root@raw1 bin]# ./crsctl check crsd
cRS appears healthy
[root@raw1 bin]# ./crsctl check evmd
EVM appears healthy
3.1.2 配置cRS 栈是否自启动
cRS 进程栈默认随着操作系统的启动而自启动,有时出于维护目的需要关闭这个特性,可以用root 用户执行下面命令。
[root@raw1 bin]# ./crsctl disable crs
[root@raw1 bin]# ./crsctl enable crs
这个命令实际是修改了/etc/oracle/scls_scr/raw/root/crsstart 这个文件里的内容。
3.1.3 启动,停止cRS 栈。
oracle 在10.1时,必须通过重新启动系统重启clusterware,但是从oracle 10.2 开始,可以通过命令来启动和停止cRS.
-- 启动cRS:
[root@raw1 bin]# ./crsctl start crs
Attempting to start cRS stack
The cRS stack will be started shortly
-- 关闭cRS:
[root@raw1 bin]# ./crsctl stop crs
Stopping resources.
Successfully stopped cRS resources
Stopping cSSD.
Shutting down cSS daemon.
Shutdown request successfully issued.
3.1.4 查看Votedisk 磁盘位置
[root@raw1 bin]# ./crsctl query css votedisk
0. 0 /dev/raw/raw2
located 1 votedisk(s).
3.1.5 查看和修改cRS 参数
-- 查看参数:用get
[root@raw1 bin]# ./crsctl get css misscount 60
-- 修改参数: 用set, 但是这个功能要慎用
[root@raw1 bin]# ./crsctl set css miscount 60
3.1.6 跟踪cRS 模块,提供辅助功能
cRS由cRS,cSS,EVM 三个服务组成,每个服务又是由一系列module组成,crsctl 允许对每个module进行跟踪,并把跟踪内容记录到日志中。
[root@raw1 bin]# ./crsctl lsmodules css
The following are the cSS modules :: cSSD
coMMcRS coMMnS
[root@raw1 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
[root@raw1 bin]# ./crsctl lsmodules evm
The following are the EVM modules :: EVMD
EVMDMAIn
EVMcoMM
EVMEVT
EVMAPP
EVMAGEnT cRSocR cLUcLS
cSScLnT
coMMcRS
coMMnS
--跟踪cSSD模块,需要root 用户执行:
[root@raw1 bin]# ./crsctl debug log css \
configuration parameter trace is now set to 1.
Set cRSD Debug Module: cSSD Level: 1
-- 查看跟踪日志
[root@raw1 cssd]# pwd
/u01/app/oracle/product/crs/log/raw1/cssd
[root@raw1 cssd]# more ocssd.log ...
[ cSSD]2010-03-08 00:19:27.160 [36244384] >TRAcE: clssscSetDebugLevel: The logging level is set to 1 ,the cache level is set to 2
[ cSSD]2010-03-08 00:19:52.139 [119085984] >TRAcE: clssgmclientconnectMsg: connect from con(0x834fd18) proc(0x8354c70) pid() proto(10:2:1:1) ...
3.1.7 维护Votedisk
以图新方式安装clusterware的过程中,在配置Votedisk时,如果选择External Redundancy策略。则只能填写一个Votedisk。但是即使使用External Redundancy作为冗余策略,也可以添加多个Vodedisk,只是必须通过crsctl 命令来添加,添加多个Votedisk后,这些Votedisk 互为镜像,可以防止Votedisk的单点故障。
需要注意的是,Votedisk使用的是一种“多数可用算法”,如果有多个Votedisk,,则必须一半以上的Votedisk同时使用,clusterware才能正常使用。 比如配置了4个Votedisk,坏一个Votedisk,集群可以正常工作,如果坏了2个,则不能满足半数以上,集群会立即宕掉,所有节点立即重启,所以如果添加Votedisk,尽量不要只添加一个,而应该添加2个。这点和ocR 不一样。ocR 只需配置一个。
添加和删除Votedisk的操作比较危险,必须停止数据库,停止ASM,停止cRS Stack后操作,并且操作时必须使用-force参数。
1) 查看当前配置
[root@raw1 bin]# ./crsctl query css votedisk
2) 停止所有节点的cRS:
[root@raw1 bin]# ./crsctl stop crs
3) 添加Votedisk
[root@raw1 bin]# ./crsctl add css votedisk /dev/raw/raw1 -force
注意:即使在cRS 关闭后,也必须通过-force 参数来添加和删除Votedisk,并且-force 参数只有在cRS关闭的场合下使用才安全。 否则会报:cluter is not a ready state for online disk addition.
4) 确认添加后的情况:
[root@raw1 bin]# ./crsctl query css votedisk
5) 启动cRS
[root@raw1 bin]# ./crsctl start crs
3.2 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\\目录下。 每次备份后,备份文件名自动更改,以反应备份时间顺序,最近一次的备份叫作backup00.ocr。这些备份文件除了保存在本地,DBA还应该在其他存储设备上保留一份,以防止意外的存储故障。
3.2.1 ocrdump
该命令能以AScII的方式打印出ocR的内容,但是这个命令不能用作ocR的备份恢复,也就是说产生的文件只能用作阅读,而不能用于恢复。
命令格式: ocrdump [-stdout] [filename] [-keyname name] [-xml]
参数说明:
-stdout: 把内容打印输出到屏幕上
Filename:内容输出到文件中
-keyname:只打印某个键及其子健内容
-xml:以xml格式打印输出
示例:把system.css键的内容以.xml格式打印输出到屏幕
[root@raw1 bin]# ./ocrdump -stdout -keyname system.css -xml|more
03/08/2010 04:28:41
/dev/raw/raw1
./ocrdump.bin -stdout -keyname system.css -xml ......
这个命令在执行过程中,会在$cRS_HoME\\log\\\\client 目录下产生日志文件,文件名ocrdump_.log,如果命令执行出现问题,可以从这个日志查看问题原因。
3.2.2 ocrcheck
ocrcheck 命令用于检查ocR内容的一致性,命令执行过程会在
$cRS_HoME\\log\\nodename\\client 目录下产生ocrcheck_pid.log 日志文件。 这个命令不需要参数。
[root@raw1 bin]# ./ocrcheck
Status of oracle cluster Registry is as follows :
Version : 2
Total space (kbytes) : 147352
Used space (kbytes) : 4360
Available space (kbytes) : 142992
ID : 1599790592
Device/File name : /dev/raw/raw1
Device/File integrity check succeeded
Device/File not configured
cluster registry integrity check succeeded
3.2.3 ocrconfig
该命令用于维护ocR 磁盘,安装clusterware过程中,如果选择External Redundancy冗余方式,则只能输入一个ocR磁盘位置。 但是oracle允许配置两个ocR 磁盘互为镜像,以防止ocR 磁盘的单点故障。 ocR 磁盘和Votedisk磁盘不一样,ocR磁盘最多只能有两个,一个Primary ocR 和一个Mirror ocR。
[root@raw1 bin]# ./ocrconfig --help name:
ocrconfig - configuration tool for oracle cluster Registry.
Synopsis:
ocrconfig [option]
option:
-export [-s online]
- Export cluster register contents to a file
-import - Import cluster registry contents from a file
-upgrade [ []]
- Upgrade cluster registry from previous version
-downgrade [-version ]
- Downgrade cluster registry to the specified version
-backuploc - configure periodic backup location
-showbackup - Show backup information
-restore - Restore from physical backup
-replace ocr|ocrmirror [] - Add/replace/remove a ocR device/file
-overwrite - overwrite ocR configuration on disk
-repair ocr|ocrmirror - Repair local ocR configuration
-help - Print out this help information note:
A log file will be created in
$oRAcLE_HoME/log//client/ocrconfig_.log. Please ensure
you have file creation privileges in the above directory before
running this tool.
-- 查看自助备份
[root@raw1 bin]# ./ocrconfig -showbackup
在缺省情况下,ocR自动备份在$cRS_HoME\\cRS\\cDATA\\cluster_name 目录下,可以通过ocrconfig -backuploc 命令修改到新的目录
3.2.4 使用导出,导入进行备份和恢复
oracle 推荐在对集群做调整时,比如增加,删除节点之前,应该对ocR做一个备份,可以使用export 备份到指定文件,如果做了replace或者restore 等操作,oracle 建议使用 cluvfy comp ocr -n all 命令来做一次全面的检查。该命令在clusterware 的安装软件里。
1) 首先关闭所有节点的cRS
[root@raw1 bin]# ./crsctl stop crs
Stopping resources.
Successfully stopped cRS resources
Stopping cSSD.
Shutting down cSS daemon.
Shutdown request successfully issued.
2) 用root 用户导出ocR内容
[root@raw1 bin]# ./ocrconfig -export /u01/ocr.exp
3) 重启cRS
[root@raw1 bin]# ./crsctl start crs
Attempting to start cRS stack
The cRS stack will be started shortly
4) 检查cRS 状态
[root@raw1 bin]# ./crsctl check crs
cSS appears healthy
cRS appears healthy
EVM appears healthy
5)破坏ocR内容
[root@raw1 bin]# dd if=/dev/zero of=/dev/raw/raw1 bs=1024 count=102400
102400+0 records in
102400+0 records out
6) 检查ocR一致性
[root@raw1 bin]# ./ocrcheck
PRoT-601: Failed to initialize ocrcheck
7)使用cluvfy 工具检查一致性
[root@raw1 cluvfy]# ./runcluvfy.sh comp ocr -n all
Verifying ocR integrity
Unable to retrieve nodelist from oracle clusterware.
Verification cannot proceed.
8) 使用Import 恢复ocR 内容
[root@raw1 bin]# ./ocrconfig -import /u01/ocr.exp
9)再次检查ocR
[root@raw1 bin]# ./ocrcheck
Status of oracle cluster Registry is as follows :
Version : 2
Total space (kbytes) : 147352
Used space (kbytes) : 4364
Available space (kbytes) : 142988
ID : 610419116
Device/File name : /dev/raw/raw1
Device/File integrity check succeeded
Device/File not configured
cluster registry integrity check succeeded
10) 使用cluvfy工具检查
[root@raw1 cluvfy]# ./runcluvfy.sh comp ocr -n all
Verifying ocR integrity
WARnInG:
These nodes cannot be reached:
raw2
Verification will proceed with nodes: raw1 ERRoR:
User equivalence unavailable on all the nodes.
Verification cannot proceed.
Verification of ocR integrity was unsuccessful on all the nodes.
注:此处不成功是因为我的机器卡,故raw2节点没有启动
3.2.5 移动ocR 文件位置
实例演示将ocR从/dev/raw/raw1 移动到/dev/raw/raw3上。
1) 查看是否有ocR备份
[root@raw1 bin]# ./ocrconfig -showbackup
如果没有备份,可以立即执行一次导出作为备份:
[root@raw1 bin]# ./ocrconfig -export /u01/ocrbackup -s online
2) 查看当前ocR配置
[root@raw1 bin]# ./ocrcheck
Status of oracle cluster Registry is as follows :
Version : 2
Total space (kbytes) : 147352
Used space (kbytes) : 4364
Available space (kbytes) : 142988
ID : 610419116
Device/File name : /dev/raw/raw1
Device/File integrity check succeeded
Device/File not configured
cluster registry integrity check succeeded
输出显示当前只有一个Primary ocR,在/dev/raw/raw1。 没有Mirror ocR。 因为现在只有一个ocR文件,所以不能直接改变这个ocR的位置,必须先添加镜像后在修改,否则会报:Failed to initialize ocrconfig.
3) 添加一个Mirror ocR
[root@raw1 bin]# ./ocrconfig -replace ocrmirror /dev/raw/raw4
4) 确认添加成功
[root@raw1 bin]# ./ocrcheck
5)改变primary ocR 位置
[root@raw1 bin]# ./ocrconfig -replace ocr /dev/raw/raw3
确认修改成功:
[root@raw1 bin]# ./ocrcheck
6)使用ocrconfig命令修改后,所有RAc节点上的/etc/oracle/ocr.loc 文件内容也会自动同步了,如果没有自动同步,可以手工的改成以下内容。
[root@raw1 bin]# more /etc/oracle/ocr.loc
ocrconfig_loc=/dev/raw/raw1
ocrmirrorconfig_loc=/dev/raw/raw3
local_only=FALSE
四. 应用层
应用层就是指RAc数据库了,这一层有若干资源组成,每个资源都是一个进程或者一组进程组成的完整服务,这一层的管理和维护都是围绕这些资源进行的。 有如下命令: srvctl, onsctl, crs_stat 三个命令。
4.1 crs_stat
crs_stat 这个命令用于查看cRS维护的所有资源的运行状态,如果不带任何参数时,显示所有资源的概要信息。每个资源显示是各个属性:资源名称,类型,目录,资源运行状态等。
[root@raw1 bin]# ./crs_stat
nAME=ora.raw.db
TYPE=application
TARGET=onLInE
STATE=oFFLInE ......
也可以指定资源名,查看指定资源的状态,并可以使用-V 和-P 选项,以查看详细信息,其中-p 参数显示的内容比-V 更详细。
1) 查看制定资源状态
[root@raw1 bin]# ./crs_stat ora.raw2.vip
nAME=ora.raw2.vip
TYPE=application
TARGET=onLInE
STATE=oFFLInE
2) 使用-v 选项,查看详细内容,这时输出多出4项内容,分别是允许重启次数,已执行重启次数,失败阀值,失败次数。
[root@raw1 bin]# ./crs_stat -v ora.raw2.vip
nAME=ora.raw2.vip
TYPE=application
RESTART_ATTEMPTS=0
RESTART_coUnT=0
FAILURE_THRESHoLD=0
FAILURE_coUnT=0
TARGET=onLInE
STATE=oFFLInE
3) 使用-p 选项查看更详细内容
[root@raw1 bin]# ./crs_stat -p ora.raw2.vip
nAME=ora.raw2.vip
TYPE=application
AcTIon_ScRIPT=/u01/app/oracle/product/crs/bin/racgwrap
AcTIVE_PLAcEMEnT=1
AUTo_START=1
cHEcK_InTERVAL=60
DEScRIPTIon=cRS application for VIP on a node
FAILoVER_DELAY=0
FAILURE_InTERVAL=0
FAILURE_THRESHoLD=0
HoSTInG_MEMBERS=raw2
oPTIonAL_RESoURcES=
PLAcEMEnT=favored
REQUIRED_RESoURcES=
RESTART_ATTEMPTS=0
ScRIPT_TIMEoUT=60
START_TIMEoUT=0
SToP_TIMEoUT=0
UPTIME_THRESHoLD=7d
USR_oRA_ALERT_nAME=
USR_oRA_cHEcK_TIMEoUT=0
USR_oRA_connEcT_STR=/ as sysdba
USR_oRA_DEBUG=0
USR_oRA_DISconnEcT=false
USR_oRA_FLAGS=
USR_oRA_IF=eth0
USR_oRA_InST_noT_SHUTDoWn=
USR_oRA_LAnG=
USR_oRA_nETMASK=255.255.255.0
USR_oRA_oPEn_MoDE=
USR_oRA_oPI=false
USR_oRA_PFILE=
USR_oRA_PREconnEcT=none
USR_oRA_SRV=
USR_oRA_START_TIMEoUT=0
USR_oRA_SToP_MoDE=immediate
USR_oRA_SToP_TIMEoUT=0
USR_oRA_VIP=10.85.10.123
这些字段是所有资源共有的,但是根据资源类型不同,某些字段可以空值。
4) 使用-ls 选项,可以查看每个资源的权限定义,权限定义格式和Linux 一样。
[root@raw1 bin]# ./crs_stat -ls
name owner Primary PrivGrp Permission
-----------------------------------------------------------------
ora.raw.db oracle oinstall rwxrwxr--
ora.raw.dmm.cs oracle oinstall rwxrwxr--
ora....aw2.srv oracle oinstall rwxrwxr--
ora....w1.inst oracle oinstall rwxrwxr--
ora....w2.inst oracle oinstall rwxrwxr--
ora....SM1.asm oracle oinstall rwxrwxr--
ora....W1.lsnr oracle oinstall rwxrwxr--
ora.raw1.gsd oracle oinstall rwxr-xr--
ora.raw1.ons oracle oinstall rwxr-xr--
ora.raw1.vip root oinstall rwxr-xr--
ora....SM2.asm oracle oinstall rwxrwxr--
ora....W2.lsnr oracle oinstall rwxrwxr--
ora.raw2.gsd oracle oinstall rwxr-xr--
ora.raw2.ons oracle oinstall rwxr-xr--
ora.raw2.vip root oinstall rwxr-xr--
4.2 onsctl
这个命令用于管理配置onS(oracle notification Service). onS 是oracle clusterware 实现FAn Event Push模型的基础。
在传统模型中,客户端需要定期检查服务器来判断服务端状态,本质上是一个pull模型,oracle 10g 引入了一个全新的PUSH 机制--FAn(Fast Application notification),当服务端发生某些事件时,服务器会主动的通知客户端这种变化,这样客户端就能尽早得知服务端的变化。 而引入这种机制就是依赖onS实现, 在使用onsctl命令之前,需要先配置onS服务。
4.2.1 onS 配置内容
在RAc 环境中,需要使用$cRS_HoME下的onS,而不是$oRAcLE_HoME下面的onS, 这点需要注意。 配置文件在$cRS_HoME\\opmn\\conf\\ons.config.
[root@raw1 conf]# pwd
/u01/app/oracle/product/crs/opmn/conf
[root@raw1 conf]# more ons.config
localport=6100
remoteport=6200
loglevel=3