【RAC】如何让Oracle RAC crs_stat 命令显示完整
BLOG文档结构图
最近在研究rac,发现在Oracle 11g RAC中crs_stat命令较之前的版本多出了很多新的不同的资源类型,缺省情况下,使用crs_stat -t来查看资源是密密麻麻一大片,而且很多的name列显示不全,于是上网搜了一下这个问题的解决办法,大概有2个解决办法,现总结如下:
[root@node1 ~]# crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.ARCH.dg ora....up.type ONLINE ONLINE node1
ora.DATA.dg ora....up.type ONLINE ONLINE node1
ora....ER.lsnr ora....er.type ONLINE ONLINE node1
ora....N1.lsnr ora....er.type ONLINE ONLINE node1
ora.OVDISK.dg ora....up.type ONLINE ONLINE node1
ora.TEST.dg ora....up.type ONLINE ONLINE node1
ora.asm ora.asm.type ONLINE ONLINE node1
ora.db.db ora....se.type OFFLINE OFFLINE
ora.eons ora.eons.type ONLINE ONLINE node1
ora.gsd ora.gsd.type OFFLINE OFFLINE
ora.jmrac.db ora....se.type ONLINE ONLINE node1
ora....aha.svc ora....ce.type ONLINE ONLINE node1
ora....network ora....rk.type ONLINE ONLINE node1
ora....SM1.asm application ONLINE ONLINE node1
ora....E1.lsnr application ONLINE ONLINE node1
ora.node1.gsd application OFFLINE OFFLINE
ora.node1.ons application ONLINE ONLINE node1
ora.node1.vip ora....t1.type ONLINE ONLINE node1
ora....SM2.asm application ONLINE ONLINE node2
ora....E2.lsnr application ONLINE ONLINE node2
ora.node2.gsd application OFFLINE OFFLINE
ora.node2.ons application ONLINE ONLINE node2
ora.node2.vip ora....t1.type ONLINE ONLINE node2
ora.oc4j ora.oc4j.type OFFLINE OFFLINE
ora.ons ora.ons.type ONLINE ONLINE node1
ora....ry.acfs ora....fs.type ONLINE ONLINE node1
ora.scan1.vip ora....ip.type ONLINE ONLINE node1
[root@node1 ~]#
1 方法一:shell脚本
将如下脚本用vi编辑器编辑一个shell脚本,然后赋可执行权限后就可以使用了
## 无Type列
awk 'BEGIN {printf "%-30s %-10s %-10s %-10s \n","Name ","Target ","State ","Host "; printf "%-30s %-10s %-10s %-10s\n","------------------------------","----------", "---------","-------";}'
crs_stat | awk 'BEGIN { FS="=| ";state = 0;} $1~/NAME/ {appname = $2; state=1}; state == 0 {next;} $1~/TARGET/ && state == 1 {apptarget = $2; state=2;} $1~/STATE/ && state == 2 {appstate = $2; apphost = $4; state=3;} state == 3 {printf "%-30s %-10s %-10s %-10s\n", appname,apptarget,appstate,apphost; state=0;}'
##有type列
awk 'BEGIN {printf "%-26s %-26s %-10s %-10s %-10s \n","Name ","Type ","Target ","State ","Host "; printf "%-30s %-26s %-10s %-10s %-10s\n","------------------------------","--------------------------","----------", "---------","-------";}'
crs_stat | awk 'BEGIN { FS="=| ";state = 0;} $1~/NAME/ {appname = $2; state=1}; state == 0 {next;} $1~/TYPE/ && state == 1 {apptype = $2; state=2;} $1~/TARGET/ && state == 2 {apptarget = $2; state=3;} $1~/STATE/ && state == 3 {appstate = $2; apphost = $4; state=4;} state == 4 {printf "%-30s %-26s %-10s %-10s %-10s\n", appname,apptype,apptarget,appstate,apphost; state=0;}'
[root@node1 ~]# more crs_stat.sh
awk \
'BEGIN {printf "%-30s %-10s %-10s %-10s\n","Name ","Target ","State ","Host ";
printf "%-30s %-10s %-10s %-10s\n","------------------------------","----------", "---------","-------";}'
crs_stat | awk \
'BEGIN { FS="=| ";state = 0;}
$1~/NAME/ {appname = $2; state=1};
state == 0 {next;}
$1~/TARGET/ && state == 1 {apptarget = $2; state=2;}
$1~/STATE/ && state == 2 {appstate = $2; apphost = $4; state=3;}
state == 3 {printf "%-30s %-10s %-10s %-10s\n", appname,apptarget,appstate,apphost; state=0;}'
[root@node1 ~]# ./crs_stat.sh
Name Target State Host
------------------------------ ---------- --------- -------
ora.ARCH.dg ONLINE ONLINE node1
ora.DATA.dg ONLINE ONLINE node1
ora.LISTENER.lsnr ONLINE ONLINE node1
ora.LISTENER_SCAN1.lsnr ONLINE ONLINE node1
ora.OVDISK.dg ONLINE ONLINE node1
ora.TEST.dg ONLINE ONLINE node1
ora.asm ONLINE ONLINE node1
ora.db.db OFFLINE OFFLINE
ora.eons ONLINE ONLINE node1
ora.gsd OFFLINE OFFLINE
ora.jmrac.db ONLINE ONLINE node1
ora.jmrac.haha.svc ONLINE ONLINE node1
ora.net1.network ONLINE ONLINE node1
ora.node1.ASM1.asm ONLINE ONLINE node1
ora.node1.LISTENER_NODE1.lsnr ONLINE ONLINE node1
ora.node1.gsd OFFLINE OFFLINE
ora.node1.ons ONLINE ONLINE node1
ora.node1.vip ONLINE ONLINE node1
ora.node2.ASM2.asm ONLINE ONLINE node2
ora.node2.LISTENER_NODE2.lsnr ONLINE ONLINE node2
ora.node2.gsd OFFLINE OFFLINE
ora.node2.ons ONLINE ONLINE node2
ora.node2.vip ONLINE ONLINE node2
ora.oc4j OFFLINE OFFLINE
ora.ons ONLINE ONLINE node1
ora.registry.acfs ONLINE ONLINE node1
ora.scan1.vip ONLINE ONLINE node1
[root@node1 ~]#
[root@node1 ~]# more crs_stat1.sh
awk 'BEGIN {printf "%-30s %-26s %-10s %-10s %-10s \n","Name ","Type ","Target ","State ","Host "; printf "%-30s %-26s %-10s %-10s %-10s\n","--------------
----------------","--------------------------","----------", "---------","-------";}'
crs_stat | awk 'BEGIN { FS="=| ";state = 0;} $1~/NAME/ {appname = $2; state=1}; state == 0 {next;} $1~/TYPE/ && state == 1 {apptype = $2; state=2;} $1~/TARGET/ && state == 2 {apptarget = $2; state=3;} $1~/ST
ATE/ && state == 3 {appstate = $2; apphost = $4; state=4;} state == 4 {printf "%-30s %-26s %-10s %-10s %-10s\n", appname,apptype,apptarget,appstate,apphost; state=0;}'
[root@node1 ~]# ./crs_stat1.sh
Name Type Target State Host
------------------------------ -------------------------- ---------- --------- -------
ora.ARCH.dg ora.diskgroup.type ONLINE ONLINE node1
ora.DATA.dg ora.diskgroup.type ONLINE ONLINE node1
ora.LISTENER.lsnr ora.listener.type ONLINE ONLINE node1
ora.LISTENER_SCAN1.lsnr ora.scan_listener.type ONLINE ONLINE node1
ora.OVDISK.dg ora.diskgroup.type ONLINE ONLINE node1
ora.TEST.dg ora.diskgroup.type ONLINE ONLINE node1
ora.asm ora.asm.type ONLINE ONLINE node1
ora.db.db ora.database.type OFFLINE OFFLINE
ora.eons ora.eons.type ONLINE ONLINE node1
ora.gsd ora.gsd.type OFFLINE OFFLINE
ora.jmrac.db ora.database.type ONLINE ONLINE node1
ora.jmrac.haha.svc ora.service.type ONLINE ONLINE node1
ora.net1.network ora.network.type ONLINE ONLINE node1
ora.node1.ASM1.asm application ONLINE ONLINE node1
ora.node1.LISTENER_NODE1.lsnr application ONLINE ONLINE node1
ora.node1.gsd application OFFLINE OFFLINE
ora.node1.ons application ONLINE ONLINE node1
ora.node1.vip ora.cluster_vip_net1.type ONLINE ONLINE node1
ora.node2.ASM2.asm application ONLINE ONLINE node2
ora.node2.LISTENER_NODE2.lsnr application ONLINE ONLINE node2
ora.node2.gsd application OFFLINE OFFLINE
ora.node2.ons application ONLINE ONLINE node2
ora.node2.vip ora.cluster_vip_net1.type ONLINE ONLINE node2
ora.oc4j ora.oc4j.type OFFLINE OFFLINE
ora.ons ora.ons.type ONLINE ONLINE node1
ora.registry.acfs ora.registry.acfs.type ONLINE ONLINE node1
ora.scan1.vip ora.scan_vip.type ONLINE ONLINE node1
[root@node1 ~]#
或者直接在/usr/local/bin/目录下编辑也可以直接运行:
[root@node1 ~]# more /usr/local/bin/crsstat1
awk 'BEGIN {printf "%-30s %-26s %-10s %-10s %-10s \n","Name ","Type ","Target ","State ","Host "; printf "%-30s %-26s %-10s %-10s %-10s\n","--------------
----------------","--------------------------","----------", "---------","-------";}'
crs_stat | awk 'BEGIN { FS="=| ";state = 0;} $1~/NAME/ {appname = $2; state=1}; state == 0 {next;} $1~/TYPE/ && state == 1 {apptype = $2; state=2;} $1~/TARGET/ && state == 2 {apptarget = $2; state=3;} $1~/ST
ATE/ && state == 3 {appstate = $2; apphost = $4; state=4;} state == 4 {printf "%-30s %-26s %-10s %-10s %-10s\n", appname,apptype,apptarget,appstate,apphost; state=0;}'
[root@node1 ~]# crsstat1
Name Type Target State Host
------------------------------ -------------------------- ---------- --------- -------
ora.ARCH.dg ora.diskgroup.type ONLINE ONLINE node1
ora.DATA.dg ora.diskgroup.type ONLINE ONLINE node1
ora.LISTENER.lsnr ora.listener.type ONLINE ONLINE node1
ora.LISTENER_SCAN1.lsnr ora.scan_listener.type ONLINE ONLINE node1
ora.OVDISK.dg ora.diskgroup.type ONLINE ONLINE node1
ora.TEST.dg ora.diskgroup.type ONLINE ONLINE node1
ora.asm ora.asm.type ONLINE ONLINE node1
ora.db.db ora.database.type OFFLINE OFFLINE
ora.eons ora.eons.type ONLINE ONLINE node1
ora.gsd ora.gsd.type OFFLINE OFFLINE
ora.jmrac.db ora.database.type ONLINE ONLINE node1
ora.jmrac.haha.svc ora.service.type ONLINE ONLINE node1
ora.net1.network ora.network.type ONLINE ONLINE node1
ora.node1.ASM1.asm application ONLINE ONLINE node1
ora.node1.LISTENER_NODE1.lsnr application ONLINE ONLINE node1
ora.node1.gsd application OFFLINE OFFLINE
ora.node1.ons application ONLINE ONLINE node1
ora.node1.vip ora.cluster_vip_net1.type ONLINE ONLINE node1
ora.node2.ASM2.asm application ONLINE ONLINE node2
ora.node2.LISTENER_NODE2.lsnr application ONLINE ONLINE node2
ora.node2.gsd application OFFLINE OFFLINE
ora.node2.ons application ONLINE ONLINE node2
ora.node2.vip ora.cluster_vip_net1.type ONLINE ONLINE node2
ora.oc4j ora.oc4j.type OFFLINE OFFLINE
ora.ons ora.ons.type ONLINE ONLINE node1
ora.registry.acfs ora.registry.acfs.type ONLINE ONLINE node1
ora.scan1.vip ora.scan_vip.type ONLINE ONLINE node1
2 方法二:安装一个包
具体参考大师乐沙弥的世界的blog: http://blog.csdn.net/leshami/article/details/9411177
1、安装crsstat
通常情况下,建议使用root用户或者oracle用户来安装到 /usr/local/bin 目录
当脚本首次运行时,会在安装目录产生一个 crsstat.env 文件,该文件用于描述crs的位置信息
安装crsstat前,应启动crs,其次对于crsstat脚本所在的安装路径应当具有写的权限
源文件下载: http://blog.enkitec.com/wp-content/uploads/2012/07/crsstat.v1.2.2.zip
下面是安装步骤
# cd /usr/local/bin
# unzip crsstat.v1.2.1.zip
# mv crsstat.v1.2.2 crsstat
# chmod 755 crsstat
# ./crsstat
# chmod 644 crsstat.env
校验crsstat.env文件配置是否正确
# more crsstat.env
GRID_HOME=/u01/app/11.2.0/grid
GRID_VER=11.2
2、演示用法
crsstat用法比较简单,直接在提示符下执行crsstat命令即可,也可以使用crsstat -h 输出crsstat的帮助信息
a、crsstat的帮助信息
[grid@linux1 ~]$ crsstat -h
Usage: crsstat [-h] [-c] [search term]
-h => print this message
-c => output the resources by cluster or local
Examples:
crsstat # show all resources
crsstat listener # only show listener resources
crsstat database # only show database resources
crsstat -c listener # only show database resources sorted by cluster/local
Output Contains the following fields:
Resource Name
Resource Type, which includes an identifier C-Cluster and L-Local
Target State
Current State
Current Node (11gR2: or the last node in paraenthesis if the resource is Offline)
Failure Count (11gR2 only)
Restart Count (11gR2 only)
b、使用crsstat查看集群资源
#显示所有的资源 State Details (11gR2 only)
[root@node1 ~]# crsstat
Resource Name Resource Type Target State Node FC RC State Details
---------------------------------------- ---------------- ---------- ------------ --------------- -- -- ---------------
ora.ARCH.dg diskgroup L ONLINE ONLINE node1 0
ora.ARCH.dg diskgroup L ONLINE ONLINE node2 0
ora.DATA.dg diskgroup L ONLINE ONLINE node1 0
ora.DATA.dg diskgroup L ONLINE ONLINE node2 0
ora.LISTENER.lsnr Listener L ONLINE ONLINE node1 0
ora.LISTENER.lsnr Listener L ONLINE ONLINE node2 0
ora.LISTENER_SCAN1.lsnr SCAN Listener C ONLINE ONLINE node1 0
ora.OVDISK.dg diskgroup L ONLINE ONLINE node1 0
ora.OVDISK.dg diskgroup L ONLINE ONLINE node2 0
ora.TEST.dg diskgroup L ONLINE ONLINE node1 0
ora.TEST.dg diskgroup L ONLINE ONLINE node2 0
ora.asm ASM L ONLINE ONLINE node1 0 Started
ora.asm ASM L ONLINE ONLINE node2 0 Started
ora.db.db database C OFFLINE OFFLINE (node1) 0
ora.db.db database C OFFLINE OFFLINE (node2) 0
ora.eons eons L ONLINE ONLINE node1 0
ora.eons eons L ONLINE ONLINE node2 0
ora.gsd Gbl Svc Daemon L OFFLINE OFFLINE (node1) 0
ora.gsd Gbl Svc Daemon L OFFLINE OFFLINE (node2) 0
ora.jmrac.db database C ONLINE ONLINE node1 0 Open
ora.jmrac.db database C ONLINE ONLINE node2 0 Open
ora.jmrac.haha.svc service C ONLINE ONLINE node1 0
ora.jmrac.haha.svc service C ONLINE ONLINE node2 0
ora.net1.network Network (VIP) L ONLINE ONLINE node1 0
ora.net1.network Network (VIP) L ONLINE ONLINE node2 0
ora.node1.vip Cluster VIP C ONLINE ONLINE node1 0
ora.node2.vip Cluster VIP C ONLINE ONLINE node2 0
ora.oc4j OC4J C OFFLINE OFFLINE () 0
ora.ons Ora Notif Svc L ONLINE ONLINE node1 0
ora.ons Ora Notif Svc L ONLINE ONLINE node2 0
ora.registry.acfs registry L ONLINE ONLINE node1 0
ora.registry.acfs registry L ONLINE ONLINE node2 0
ora.scan1.vip SCAN VIP C ONLINE ONLINE node1 0
[root@node1 ~]#
c、其它用法
#显示service相关的信息
[root@node1 ~]# crsstat service
Resource Name Resource Type Target State Node FC RC State Details
---------------------------------------- ---------------- ---------- ------------ --------------- -- -- ---------------
ora.jmrac.haha.svc service C ONLINE ONLINE node1 0
ora.jmrac.haha.svc service C ONLINE ONLINE node2 0
#显示集群中已注册数据库的信息
[root@node1 ~]# crsstat database
Resource Name Resource Type Target State Node FC RC State Details
---------------------------------------- ---------------- ---------- ------------ --------------- -- -- ---------------
ora.db.db database C OFFLINE OFFLINE (node1) 0
ora.db.db database C OFFLINE OFFLINE (node2) 0
ora.jmrac.db database C ONLINE ONLINE node1 0 Open
ora.jmrac.db database C ONLINE ONLINE node2 0 Open
[root@node1 ~]#
#显示集群中监听器的信息
[root@node1 ~]# crsstat lsnr
Resource Name Resource Type Target State Node FC RC State Details
---------------------------------------- ---------------- ---------- ------------ --------------- -- -- ---------------
ora.LISTENER.lsnr Listener L ONLINE ONLINE node1 0
ora.LISTENER.lsnr Listener L ONLINE ONLINE node2 0
ora.LISTENER_SCAN1.lsnr SCAN Listener C ONLINE ONLINE node1 0
[root@node1 ~]#
#也可以结合grep命令来过滤
[root@node1 ~]# crsstat | grep -i offline
ora.db.db database C OFFLINE OFFLINE (node1) 0
ora.db.db database C OFFLINE OFFLINE (node2) 0
ora.gsd Gbl Svc Daemon L OFFLINE OFFLINE (node1) 0
ora.gsd Gbl Svc Daemon L OFFLINE OFFLINE (node2) 0
ora.oc4j OC4J C OFFLINE OFFLINE () 0
[root@node1 ~]#
[root@node1 ~]# crsstat -c listener
Resource Name Resource Type Target State Node FC RC State Details
---------------------------------------- ---------------- ---------- ------------ --------------- -- -- ---------------
Local Resources
--------------------------------------------------------------------------------
ora.LISTENER.lsnr Listener L ONLINE ONLINE node1 0
ora.LISTENER.lsnr Listener L ONLINE ONLINE node2 0
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr SCAN Listener C ONLINE ONLINE node1 0
[root@node1 ~]#
...........................................................................................................................................................................................
本文作者:小麦苗,只专注于数据库的技术,更注重技术的运用
ITPUB BLOG:http://blog.itpub.net/26736162
本文地址:http://blog.itpub.net/26736162/viewspace-1610957/
本文pdf版:http://yunpan.cn/QCwUAI9bn7g7w 提取码:af2d
QQ:642808185 注明:ITPUB的文章标题
...........................................................................................................................................................................................