srvctl命令是RAC维护中最常用到的命令,也最为复杂,使用这个命令可以操作CRS上的Database,Instance,
ASM,Service、Listener和Node Application资源,其中Node Application资源又包括了GSD、ONS、VIP。这些
资源还有独立的管理工具,比如
ONS可以使用onsctl命令进行管理: http://www.cnblogs.com/myrunning/p/4265522.html
listener还可以通过lsnrctl命令进行管理:http://www.cnblogs.com/myrunning/p/3977931.html
[[email protected] ~]$ srvctl -help 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
1.使用config查看配置
<1>查看数据库配置
srvctl config database --查看在ocr注册的所有数据库
srvctl config database -d racdb --使用-d选项查看某个具体的数据库配置
srvctl config database -d racdb -a --使用-a选项查看更详细的配置
[[email protected] ~]$ srvctl config database racdb [[email protected] ~]$ srvctl config database -d racdb rac4 racdb2 /opt/ora10g/product/10.2.0/db_1 rac3 racdb1 /opt/ora10g/product/10.2.0/db_1 [[email protected] ~]$ srvctl config database -d racdb -a rac4 racdb2 /opt/ora10g/product/10.2.0/db_1 rac3 racdb1 /opt/ora10g/product/10.2.0/db_1 DB_NAME: racdb ORACLE_HOME: /opt/ora10g/product/10.2.0/db_1 SPFILE: +DATA/racdb/spfileracdb.ora DOMAIN: null DB_ROLE: null START_OPTIONS: null POLICY: AUTOMATIC ENABLE FLAG: DB ENABLED
<2>查看Node Application的配置
--srvctl config nodeapps -n rac3 不带任何参数返回节点实例的$ORACLE_HOME
[[email protected] ~]$ srvctl config nodeapps -n rac3 rac3 racdb1 /opt/ora10g/product/10.2.0/db_1
--使用-a选项,查看vip配置
[[email protected] ~]$ srvctl config nodeapps -n rac3 -a VIP exists.: /rac3-vip/192.168.1.203/255.255.255.0/eth0:eth1
--使用-g选项,查看gsd:
[[email protected] ~]$ srvctl config nodeapps -n rac3 -g GSD exists.
--使用-s选项,查看ons:
[[email protected] ~]$ srvctl config nodeapps -n rac3 -s ONS daemon exists.
--使用-l选项,查看listener:
[[email protected] ~]$ srvctl config nodeapps -n rac3 -l Listener exists.
<3>查看Listener的配置
[[email protected] ~]$ srvctl config listener -n rac3 rac3 LISTENER_RAC3 [[email protected] ~]$ srvctl config listener -n rac4 rac4 LISTENER_RAC4
显示出了节点上Listener的名称
<4>查看asm
[[email protected] ~]$ srvctl config asm -n rac3 +ASM1 /opt/ora10g/product/10.2.0/db_1 [[email protected] ~]$ srvctl config asm -n rac4 +ASM2 /opt/ora10g/product/10.2.0/db_1
显示出了每个节点上的ASM实例名和$ORACLE_HOME
<5>查看Service
--查看数据库的所有Service配置:
[[email protected] ~]$ srvctl config service -d racdb -a racdbserver PREF: racdb2 AVAIL: racdb1 TAF: basic
--查看那某个Service配置:
[[email protected] ~]$ srvctl config service -d racdb -s racdbserver racdbserver PREF: racdb2 AVAIL: racdb1 [[email protected] ~]$ srvctl config service -d racdb -s racdbserver -a --增加-a选项可以查看TAF策略 racdbserver PREF: racdb2 AVAIL: racdb1 TAF: basic
输出racdbserver这个服务,racdb2是首选实例,racdb1是可选实例 TAF策略是basic
2.使用remove删除对象
注意:使用remove命令删除的只是对象在OCR中的定义信息,对象本身比如数据库的数据文件等不会被删除,以后可以随时使用add命令重新添加到ocr中.
<1>删除Service
在删除之前,命令会给出确认提示,最后两行就是我们的service信息
[[email protected] ~]$ crs_stat -t Name Type Target State Host ------------------------------------------------------------ ora....SM1.asm application ONLINE ONLINE rac3 ora....C3.lsnr application ONLINE ONLINE rac3 ora.rac3.gsd application ONLINE ONLINE rac3 ora.rac3.ons application ONLINE OFFLINE ora.rac3.vip application ONLINE ONLINE rac3 ora....SM2.asm application ONLINE ONLINE rac4 ora....C4.lsnr application ONLINE ONLINE rac4 ora.rac4.gsd application ONLINE ONLINE rac4 ora.rac4.ons application ONLINE ONLINE rac4 ora.rac4.vip application ONLINE ONLINE rac4 ora.racdb.db application ONLINE ONLINE rac4 ora....b1.inst application ONLINE ONLINE rac3 ora....b2.inst application ONLINE ONLINE rac4 ora....rver.cs application ONLINE ONLINE rac3 ora....db2.srv application ONLINE ONLINE rac4
--删除失败,提示我们service正在运行
[[email protected] ~]$ srvctl remove service -d racdb -s racdbserver racdbserver PREF: racdb2 AVAIL: racdb1 Remove service racdbserver from the database racdb? (y/[n]) y PRKP-1024 : The service racdbserver is still running.
[[email protected] ~]$ srvctl stop service -d racdb -s racdbserver [[email protected] ~]$ crs_stat -t Name Type Target State Host ------------------------------------------------------------ ora....SM1.asm application ONLINE ONLINE rac3 ora....C3.lsnr application ONLINE ONLINE rac3 ora.rac3.gsd application ONLINE ONLINE rac3 ora.rac3.ons application ONLINE OFFLINE ora.rac3.vip application ONLINE ONLINE rac3 ora....SM2.asm application ONLINE ONLINE rac4 ora....C4.lsnr application ONLINE ONLINE rac4 ora.rac4.gsd application ONLINE ONLINE rac4 ora.rac4.ons application ONLINE ONLINE rac4 ora.rac4.vip application ONLINE ONLINE rac4 ora.racdb.db application ONLINE ONLINE rac4 ora....b1.inst application ONLINE ONLINE rac3 ora....b2.inst application ONLINE ONLINE rac4 ora....rver.cs application OFFLINE OFFLINE ora....db2.srv application OFFLINE OFFLINE
[[email protected] ~]$ srvctl remove service -d racdb -s racdbserver racdbserver PREF: racdb2 AVAIL: racdb1 Remove service racdbserver from the database racdb? (y/[n]) y [[email protected] ~]$ crs_stat -t Name Type Target State Host ------------------------------------------------------------ ora....SM1.asm application ONLINE ONLINE rac3 ora....C3.lsnr application ONLINE ONLINE rac3 ora.rac3.gsd application ONLINE ONLINE rac3 ora.rac3.ons application ONLINE OFFLINE ora.rac3.vip application ONLINE ONLINE rac3 ora....SM2.asm application ONLINE ONLINE rac4 ora....C4.lsnr application ONLINE ONLINE rac4 ora.rac4.gsd application ONLINE ONLINE rac4 ora.rac4.ons application ONLINE ONLINE rac4 ora.rac4.vip application ONLINE ONLINE rac4 ora.racdb.db application ONLINE ONLINE rac4 ora....b1.inst application ONLINE ONLINE rac3 ora....b2.inst application ONLINE ONLINE rac4
可以看到通过crs_stat -t命令已经看不到service信息了
<2>删除实例
删除两个实例,命令会给出确认提示:
[[email protected] ~]$ srvctl remove instance -d racdb -i racdb1 Remove instance racdb1 from the database racdb? (y/[n]) y PRKP-1023 : The instance {0} is still running.racdb [[email protected] ~]$ srvctl stop instance -d racdb -i racdb1 [[email protected] ~]$ srvctl stop instance -d racdb -i racdb2 [[email protected] ~]$ srvctl remove instance -d racdb -i racdb1 Remove instance racdb1 from the database racdb? (y/[n]) y [[email protected] ~]$ srvctl remove instance -d racdb -i racdb2 Remove instance racdb2 from the database racdb? (y/[n]) y [[email protected] ~]$ crs_stat -t Name Type Target State Host ------------------------------------------------------------ ora....SM1.asm application ONLINE ONLINE rac3 ora....C3.lsnr application ONLINE ONLINE rac3 ora.rac3.gsd application ONLINE ONLINE rac3 ora.rac3.ons application ONLINE ONLINE rac3 ora.rac3.vip application ONLINE ONLINE rac3 ora....SM2.asm application ONLINE ONLINE rac4 ora....C4.lsnr application ONLINE ONLINE rac4 ora.rac4.gsd application ONLINE ONLINE rac4 ora.rac4.ons application ONLINE ONLINE rac4 ora.rac4.vip application ONLINE ONLINE rac4 ora.racdb.db application OFFLINE OFFLINE
可以看到通过crs_stat -t 命令已经看不到实例的信息了
<3>删除数据库
[[email protected] ~]$ srvctl remove database -d racdb Remove the database racdb? (y/[n]) y [[email protected] ~]$ crs_stat -t Name Type Target State Host ------------------------------------------------------------ ora....SM1.asm application ONLINE ONLINE rac3 ora....C3.lsnr application ONLINE ONLINE rac3 ora.rac3.gsd application ONLINE ONLINE rac3 ora.rac3.ons application ONLINE ONLINE rac3 ora.rac3.vip application ONLINE ONLINE rac3 ora....SM2.asm application ONLINE ONLINE rac4 ora....C4.lsnr application ONLINE ONLINE rac4 ora.rac4.gsd application ONLINE ONLINE rac4 ora.rac4.ons application ONLINE ONLINE rac4 ora.rac4.vip application ONLINE ONLINE rac4
可以看到crs_stat -t 已经看不到数据库在ocr的注册信息了
3.使用add添加对象
一般情况下,应用层的资源都是在图形界面的帮组下注册到OCR中的,比如vip、ons是在安装最后的阶段创建的(这些资源也是集群中必须有的,为集群机制服务的), 而数据库、ASM是在执行DBCA的过程中自动注册到OCR中的,Listener是通过NETCA工具自动注册到OCR中的。 有时候我们需要通过手工的方式把资源注册到OCR中,这时就用到了add命令。
通过上面的说明,我们可以想到假如OCR损坏且没有备份的情况下,我们可以手动的方式重建OCR。
<1>添加数据库
[[email protected] ~]$ crs_stat -t Name Type Target State Host ------------------------------------------------------------ ora....SM1.asm application ONLINE ONLINE rac3 ora....C3.lsnr application ONLINE ONLINE rac3 ora.rac3.gsd application ONLINE ONLINE rac3 ora.rac3.ons application ONLINE ONLINE rac3 ora.rac3.vip application ONLINE ONLINE rac3 ora....SM2.asm application ONLINE ONLINE rac4 ora....C4.lsnr application ONLINE ONLINE rac4 ora.rac4.gsd application ONLINE ONLINE rac4 ora.rac4.ons application ONLINE ONLINE rac4 ora.rac4.vip application ONLINE ONLINE rac4 [[email protected] ~]$ [[email protected] ~]$ srvctl add database -d racdb -o $ORACLE_HOME [[email protected] ~]$ [[email protected] ~]$ crs_stat -t Name Type Target State Host ------------------------------------------------------------ ora....SM1.asm application ONLINE ONLINE rac3 ora....C3.lsnr application ONLINE ONLINE rac3 ora.rac3.gsd application ONLINE ONLINE rac3 ora.rac3.ons application ONLINE ONLINE rac3 ora.rac3.vip application ONLINE ONLINE rac3 ora....SM2.asm application ONLINE ONLINE rac4 ora....C4.lsnr application ONLINE ONLINE rac4 ora.rac4.gsd application ONLINE ONLINE rac4 ora.rac4.ons application ONLINE ONLINE rac4 ora.rac4.vip application ONLINE ONLINE rac4 ora.racdb.db application OFFLINE OFFLINE
通过上面的信息可以看到数据已经被成功注册到OCR中.
<2>添加实例
[[email protected] ~]$ srvctl add instance -d racdb -n rac3 -i racdb1 [[email protected] ~]$ srvctl add instance -d racdb -n rac4 -i racdb2 [[email protected] ~]$ [[email protected] ~]$ crs_stat -t Name Type Target State Host ------------------------------------------------------------ ora....SM1.asm application ONLINE ONLINE rac3 ora....C3.lsnr application ONLINE ONLINE rac3 ora.rac3.gsd application ONLINE ONLINE rac3 ora.rac3.ons application ONLINE ONLINE rac3 ora.rac3.vip application ONLINE ONLINE rac3 ora....SM2.asm application ONLINE ONLINE rac4 ora....C4.lsnr application ONLINE ONLINE rac4 ora.rac4.gsd application ONLINE ONLINE rac4 ora.rac4.ons application ONLINE ONLINE rac4 ora.rac4.vip application ONLINE ONLINE rac4 ora.racdb.db application OFFLINE OFFLINE ora....b1.inst application OFFLINE OFFLINE ora....b2.inst application OFFLINE OFFLINE
通过上面的信息可以看到实例已经被成功注册到OCR中
<3>添加服务
添加服务需要使用4个参数 -s 服务名 -r 首选实例 -a 备选实例 -P TAF策略,可选值为NONE(缺省值)、BASIC、PRECONNECT
[[email protected] ~]$ srvctl add service -d racdb -s racdbservice -r racdb1 -a racdb2 -P BASIC [[email protected] ~]$ [[email protected] ~]$ crs_stat -t Name Type Target State Host ------------------------------------------------------------ ora....SM1.asm application ONLINE ONLINE rac3 ora....C3.lsnr application ONLINE ONLINE rac3 ora.rac3.gsd application ONLINE ONLINE rac3 ora.rac3.ons application ONLINE ONLINE rac3 ora.rac3.vip application ONLINE ONLINE rac3 ora....SM2.asm application ONLINE ONLINE rac4 ora....C4.lsnr application ONLINE ONLINE rac4 ora.rac4.gsd application ONLINE ONLINE rac4 ora.rac4.ons application ONLINE ONLINE rac4 ora.rac4.vip application ONLINE ONLINE rac4 ora.racdb.db application OFFLINE OFFLINE ora....b1.inst application OFFLINE OFFLINE ora....b2.inst application OFFLINE OFFLINE ora....vice.cs application OFFLINE OFFLINE ora....db1.srv application OFFLINE OFFLINE [[email protected] ~]$ [[email protected] ~]$ srvctl config service -d racdb -s racdbservice -a racdbservice PREF: racdb1 AVAIL: racdb2 TAF: BASIC
通过上面的信息可以看到服务已经被成功注册到OCR中,而且通过命令srvctl config service -d racdb -s racdbservice -a
确认能够得到正确的添加信息.
4.使用enable/disable启动、禁用对象
<1>配置数据库随crs的启动而自动自动
--关闭数据库自动启动特性:
[[email protected] ~]$ srvctl config database -d racdb -a rac3 racdb1 /opt/ora10g/product/10.2.0/db_1 rac4 racdb2 /opt/ora10g/product/10.2.0/db_1 DB_NAME: null ORACLE_HOME: /opt/ora10g/product/10.2.0/db_1 SPFILE: null DOMAIN: null DB_ROLE: null START_OPTIONS: null POLICY: AUTOMATIC ENABLE FLAG: DB ENABLED [[email protected] ~]$ srvctl disable database -d racdb [[email protected] ~]$ [[email protected] ~]$ srvctl config database -d racdb -a rac3 racdb1 /opt/ora10g/product/10.2.0/db_1 rac4 racdb2 /opt/ora10g/product/10.2.0/db_1 DB_NAME: null ORACLE_HOME: /opt/ora10g/product/10.2.0/db_1 SPFILE: null DOMAIN: null DB_ROLE: null START_OPTIONS: null POLICY: MANUAL ENABLE FLAG: DB DISABLED, INST DISABLED ON racdb1 racdb2
通过最后一行的输出可以数据库和两个实例都被设置成了disable
--启用数据库自动启动特性:
[[email protected] ~]$ srvctl enable database -d racdb [[email protected] ~]$ [[email protected] ~]$ srvctl config database -d racdb -a rac3 racdb1 /opt/ora10g/product/10.2.0/db_1 rac4 racdb2 /opt/ora10g/product/10.2.0/db_1 DB_NAME: null ORACLE_HOME: /opt/ora10g/product/10.2.0/db_1 SPFILE: null DOMAIN: null DB_ROLE: null START_OPTIONS: null POLICY: AUTOMATIC ENABLE FLAG: DB ENABLED
<2>关闭某个实例的自动启动
注意:却省时实例都是自动启动的
[[email protected] ~]$ srvctl disable instance -d racdb -i racdb1 [[email protected] ~]$ [[email protected] ~]$ srvctl config database -d racdb -a rac3 racdb1 /opt/ora10g/product/10.2.0/db_1 rac4 racdb2 /opt/ora10g/product/10.2.0/db_1 DB_NAME: null ORACLE_HOME: /opt/ora10g/product/10.2.0/db_1 SPFILE: null DOMAIN: null DB_ROLE: null START_OPTIONS: null POLICY: AUTOMATIC ENABLE FLAG: DB ENABLED, INST DISABLED ON racdb
最后一行可以看到有提示racdb1实例被关闭
启动:srvctl enable instance -d racdb -i racdb1
<3>禁止服务在某个实例上运行
禁止服务在racdb1上运行:
[[email protected] ~]$ srvctl disable service -d racdb -s racdbservice -i racdb1 [[email protected] ~]$ [[email protected] ~]$ srvctl config service -d racdb -a racdbservice PREF: racdb1 AVAIL: racdb2 TAF: BASIC Service racdbservice is disabled on instance(s) racdb1.
最后一行提示了racdbservice在实例racdb1上被禁止了
启用:srvctl enable service -d racdb -s racdbservice -i racdb1
5.启动/停止对象与查看对象
在RAC环境下启动、关闭数据库虽然仍然可以使用SQL*Plus方法,但是更推荐使用srvctl命令来做这些工作, 这可以保证及时更新crs中的运行信息。
可以使用start/stop命令启动、停止对象,然后使用status命令查看对象状态。
<1>启动数据库,缺省是启动到open状态
[[email protected] ~]$ srvctl start database -d racdb [[email protected] ~]$ [[email protected] ~]$ sqlplus ‘/as sysdba‘ SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jan 28 15:35:15 2015 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production With the Partitioning, Real Application Clusters, OLAP and Data Mining options SQL> select status from v$instance; STATUS ------------ OPEN SQL>
<2>启动实例到指定状态
--启动实例1到mount状态
[[email protected] ~]$ srvctl start instance -d racdb -i racdb1 -o mount [[email protected] ~]$ [[email protected] ~]$ sqlplus ‘/as sysdba‘ SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jan 28 15:39:53 2015 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production With the Partitioning, Real Application Clusters, OLAP and Data Mining options SQL> select status from v$instance; STATUS ------------ MOUNTED
--启动实例2到nomount状态
[[email protected] ~]$ srvctl start instance -d racdb -i racdb2 -o nomount [[email protected] ~]$ [[email protected] ~]$ sqlplus ‘/as sysdba‘ SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jan 28 15:45:18 2015 Copyright (c) 1982, 2005, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production With the Partitioning, Real Application Clusters, OLAP and Data Mining options SQL> select status from v$instance; STATUS ------------ STARTED SQL>
<3>关闭对象并指定关闭方式
--以immediate方式关闭racdb1实例
[[email protected] ~]$ srvctl stop instance -d racdb -i racdb1 -o immediate
--以abort方式关闭racdb2实例
[[email protected] ~]$ srvctl stop instance -d racdb -i racdb2 -o abort
<4>在指定的实例上启动服务
[[email protected] ~]$ srvctl start service -d racdb -s racdbservice -i racdb1 [[email protected] ~]$ [[email protected] ~]$ srvctl status service -d racdb -v Service racdbservice is running on instance(s) racdb1
最后一行提示racdbservice服务运行在racdb1上
--查看帮助
[[email protected] ~]$ srvctl status service -d racdb -h Usage: srvctl status service -d <name> [-s "<service_name_list>"] [-f] [-v] [-S <level>] -d <name> Unique name for the database -s "<serv,...>" Comma separated service names -f Include disabled applications -v Verbose output -S <level> Additional information for EM Console -h Print usage
<5>关闭指定的实例上的服务
[[email protected] ~]$ srvctl stop service -d racdb -s racdbservice -i racdb1
[[email protected] ~]$ srvctl status service -d racdb -v
Service racdbservice is running on instance(s)
6.跟踪srvctl
在ORACLE10g 中要跟踪srvctl非常简单,只需要设置SRVM_TRACE=true 这个OS环境变量即可。
设置完后这个命令的所有函数调用就会输出到屏幕上,可以帮组用户进行诊断。
[[email protected] ~]$ export SRVM_TRACE=true [[email protected] ~]$ srvctl stop database -d racdb /opt/ora10g/product/10.2.0/db_1/jdk/jre/bin/java -classpath /opt/ora10g/product/10.2.0/db_1/jlib/netcfg.jar:/opt/ora10g/product/10.2.0/db_1/jdk/jre/lib/rt.jar:/opt/ora10g/product/10.2.0/db_1/jdk/jre/lib/i18n.jar:/opt/ora10g/product/10.2.0/db_1/jlib/srvm.jar:/opt/ora10g/product/10.2.0/db_1/jlib/srvmhas.jar:/opt/ora10g/product/10.2.0/db_1/jlib/srvmasm.jar:/opt/ora10g/product/10.2.0/db_1/srvm/jlib/srvctl.jar -DTRACING.ENABLED=true -DTRACING.LEVEL=2 oracle.ops.opsctl.OPSCTLDriver stop database -d racdb [main] [16:2:1:17] [OPSCTLDriver.setInternalDebugLevel:165] tracing is true at level 2 to file null [main] [16:2:1:60] [OPSCTLDriver.<init>:95] Security manager is set [main] [16:2:1:77] [CommandLineParser.parse:173] parsing cmdline args [main] [16:2:1:78] [CommandLineParser.parse2WordCommandOptions:940] parsing 2-word cmdline [main] [16:2:1:78] [OPSCTLDriver.execute:174] executing srvctl command [main] [16:2:1:78] [OPSCTLDriver.execute:199] executing 2-word command verb=4 noun=101 [main] [16:2:1:96] [CommandLineParser.obtainOPS:1352] srvctl: get reference to : racdb [main] [16:2:1:118] [GetActiveNodes.create:213] Going into GetActiveNodes constructor... ....................
致谢:本文章参考了张晓明<<大话Oracle RAC>>