RAC操作命令大全

lusklusklusk發表於2016-08-12

節點層:olsnodes 
網路層:oifcfg 
叢集層:crsctl(平時使用最多的兩個命令之一), ocrcheck,ocrdump,ocrconfig 
應用層:srvctl(平時使用最多的兩個命令之一),onsctl,crs_XX(crs_start、crs_stat、crs_stop這些命令在11G中已經廢棄不推薦使用了,但是crs_stat -t看叢集資源狀態比較方便,顯示格式比crsctl stat res -t要好很多
這些命令都可以透過加-h字尾來檢視到具體應該匹配的commands和objects

Rac每個節點,有單獨的DATABASE例項、監聽、ASM例項,每個節點下面的監聽包含資料庫和ASM的例項資訊,一套ASM可以對應多套DB
Asmca只在grid的bin下面
Dbca只在oracle的bin下面
Netca在grid和oracle的bin下面都有,建議使用grid操作netca
lsnrctl在grid和oracle目錄下都有,oracle使用者下沒有許可權執行lsnrctl啟動和關閉命令,只能檢視lsnrctl status
Srvctl在grid和oracle目錄下都有,目前瞭解grid和oracle下的srvctl都可以執行srvctl start/stop/config/enable/disable/status/add/remove database/listener的操作,但是建議使用oracle運算元據庫,grid操作監聽和ASM
Crsctl命令只在grid目錄中有,但是隻能使用root使用者執行crsctl start/stop crs、crsctl config crs、crsctl enable/disable crs等操作


RAC啟動操作(ASM、監聽、DB都會啟動,當然前提是DB會隨著叢集的啟動而自動啟動)
root>crsctl start crs (must be run on each node)
Oracle>srvctl status database -d db_name
grid>srvctl status  listener_name
資料庫是否自動啟動,srvctl config database -d orcl -a顯示的結果必須是Management policy: AUTOMATIC和Database is enabled

RAC關閉操作(ASM、監聽、DB都會關閉)
root> crsctl stop crs       (must be run on each node)
Oracle>srvctl status database -d db_name
grid>srvctl status  listener_name

單獨啟動關閉資料庫操作(推薦使用oracle使用者,雖然grid、oracle使用者都可以)
Oracle>srvctl start/stop database -d db_name

單獨啟動關閉某個例項操作(推薦使用oracle使用者,雖然grid、oracle使用者都可以, -n其實就是節點名稱就是伺服器名稱了)
Oracle>srvctl start/stop instance -d db_name -i instance_name

Oracle>srvctl start/stop instance -d db_name -n node_name
 
單獨啟動監聽操作(推薦使用grid使用者,雖然grid、oracle使用者都可以,-n其實就是節點名稱就是伺服器名稱了)
grid>srvctl start/stop  listener_name -n node_name



節點層olsnodes 
The olsnodes command provides the list of nodes and other information for all nodes participating in the cluster.
This command utility is located in the $ORA_CRS_HOME/bin directory. You can only use this command if the CRS daemon is started.
You can run this command as either the root user, the user that installed Oracle Clusterware, or the user that installed Oracle Database.
olsnodes命令顯示叢集內所有節點列表資訊。olsnodes只在grid的bin下面,root、grid、oracle使用者都可以執行
[root@node1 ~]# olsnodes
node1
node2
[root@node1 ~]# olsnodes -c
node-scan
[root@node1 ~]# olsnodes -n -i -s -t
node1   1       node1-vip       Active  Unpinned
node2   2       node2-vip       Active  Unpinned



網路層oifcfg
The Oracle Interface Configuration Tool (OIFCFG) command-line interface helps you to define and administer network interfaces. You can use OIFCFG commands Oracle Clusterware environments to:
Allocate and deallocate network interfaces to components
Direct components to use specific network interfaces
Retrieve component configuration information
OIFCFG命令可以定義和管理網路介面:分配和釋放網路介面到元件、直接元件使用特定的網路介面、檢索元件配置資訊
OIFCFG主要顯示一些網段資訊,只存放在grid的bin下面,較少使用,root、grid、oracle使用者都可以執行
[root@node1 ~]# oifcfg iflist
eth0  192.168.92.0
eth1  191.2.10.0
eth1  169.254.0.0
eth2  191.2.11.0
eth2  169.254.128.0
[root@node1 ~]# oifcfg iflist -p -n
eth0  192.168.92.0  PRIVATE  255.255.255.0
eth1  191.2.10.0  UNKNOWN  255.255.255.0
eth1  169.254.0.0  UNKNOWN  255.255.128.0
eth2  191.2.11.0  UNKNOWN  255.255.255.0
eth2  169.254.128.0  UNKNOWN  255.255.128.0



叢集層crsctl
CRSCTL is an interface between you and Oracle Clusterware, parsing and calling Oracle Clusterware APIs for Oracle Clusterware objects.
CRSCTL是您與Oracle Clusterware之間的介面,用於解析和呼叫Oracle Clusterware物件的Oracle Clusterware API
Crsctl只在grid的bin下面,用於管理叢集件,使用root賬號操作
檢查叢集件各個元件狀態
crsctl stat res -t
配置叢集自動啟動
crsctl config crs
crsctl disable crs  --取消叢集自動啟動
crsctl enable crs   --設定叢集自動啟動
針對當前節點啟、停、檢查叢集件(crs只能是當前節點,加-all會報錯),下面的命令會啟停ohasd程式。
crsctl start crs
crsctl stop crs
crsctl check crs
針對整個叢集裡所有節點啟、停、檢查叢集件(不加-all表示只是當前節點),下面的命令不會啟停ohasd程式。
crsctl start cluster -all
crsctl stop cluster -all
crsctl check cluster -all
檢查當前節點的時間同步
crsctl check ctss
檢查、新增、替換votedisk資訊
crsctl query css votedisk
crsctl add css votedisk /sharednfs/vote2
crsctl replace votedisk +DATA
檢視grid版本
crsctl query crs activeversion
crsctl query crs releaseversion
crsctl query crs softwareversion
修改心跳超時
crsctl set css misscount 60
檢視server資訊
crsctl status server -f
檢視serverpool資訊
crsctl status serverpool
新增一個serverpool
crsctl add serverpool serverpoolname(crsctl建立的serverpool不能給資料庫使用,只能給第三方的應用使用)


crs_start -all和crsctl start crs的區別
crs_stop -all和crsctl stop crs的區別
必須先啟動了crsctl start crs才能執行crs_start -all、crs_stop -all、crs_stat -t、crsctl check crs
如果執行了crsctl stop crs,則不能再執行crs_start –all、crs_stop –all、crs_stat –t、crsctl check crs

crsctl check cssd被crsctl check css取代了
[root@node1 ~]# crsctl check cssd
CRS-272: This command remains for backward compatibility only
Cluster Synchronization Services is online

crsctl check crsd被crsctl check crs取代了
[root@node1 grid]# crsctl check crsd
CRS-272: This command remains for backward compatibility only
Cluster Ready Services is online

[root@node1 grid]# crsctl check crs
CRS-4638: Oracle High Availability Services is online
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online

[root@node1 grid]# crsctl check cluster
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online

[root@node1 grid]# crsctl check css
CRS-4529: Cluster Synchronization Services is online

crsctl start CRS不單單啟動CRSD了,等於啟動OHASD、CRSD、CSSD三者了
crsctl start css只啟動了CSSD



叢集層ocrcheck、ocrdump、ocrconfig(三者都只存放在grid的bin下面,操作的話建議使用root使用者)
Oracle Clusterware includes two important components that manage configuration and node membership: Oracle Cluster Registry (OCR), which also includes the local component Oracle Local Registry (OLR), and voting disks.
Oracle Clusterware包括管理配置和節點成員資格的兩個重要元件:OCR和voting disks,其中OCR包含OLR

Oracle Cluster Registry (OCR)
The Oracle RAC configuration information repository that manages information about the cluster node list and instance-to-node mapping information. OCR also manages information about Oracle Clusterware resource profiles for customized applications.
OCR contains information about all Oracle resources in the cluster.
OCR manages Oracle Clusterware and Oracle RAC database configuration information
Oracle RAC配置資訊儲存庫,用於管理有關群集節點列表和例項到節點對映資訊的資訊。 OCR還管理有關用於定製應用程式的Oracle Clusterware資源配置檔案的資訊。
OCR包含有關叢集中所有Oracle資源的資訊。
OCR管理Oracle Clusterware和Oracle RAC資料庫配置資訊

Oracle Local Registry (OLR)
OLR is a registry similar to OCR located on each node in a cluster, but contains information specific to each node. It contains manageability information about Oracle Clusterware, including dependencies between various services. Oracle High Availability Services uses this information. OLR is located on local storage on each node in a cluster. Its default location is in the path Grid_home/cdata/host_name.olr, where Grid_home is the Oracle Grid Infrastructure home, and host_name is the host name of the node.
OLR resides on every node in the cluster and manages Oracle Clusterware configuration information for each particular node
OLR是類似於OCR的登錄檔,位於叢集中的每個節點上,但包含每個節點特有的資訊。 它包含有關Oracle Clusterware的可管理性資訊,包括各種服務之間的依賴關係。 Oracle高可用**使用此資訊。 OLR位於叢集中每個節點上的本地儲存上。 其預設位置在Grid_home/cdata/host_name.olr路徑中,其中Grid_home是Oracle Grid Infrastructure home,host_name是節點的主機名。
OLR駐留在叢集中的每個節點上,並管理每個特定節點的Oracle Clusterware配置資訊

Voting disks
Voting disks manage information about node membership. Each voting disk must be accessible by all nodes in the cluster for nodes to be members of the cluster
投票磁碟管理有關節點成員資格的資訊。 每個投票磁碟必須可以由叢集中的所有節點訪問,以使節點成為叢集的成員

OCRCHECK
The OCRCHECK utility displays the version of the OCR's block format, total space available and used space, OCRID, and the OCR locations that you have configured. OCRCHECK performs a block-by-block checksum operation for all of the blocks in all of the OCRs that you have configured. It also returns an individual status for each file and a result for the overall OCR integrity check.
OCRCHECK實用程式顯示OCR的塊格式版本,可用空間總數和使用空間,OCRID和您配置的OCR位置。
ocrcheck
ocrcheck -config
ocrcheck -local
ocrcheck -config -local
如下顯示存放在本地的OCR,其實就是OLR了
[root@node1 ~]# ocrcheck -config -local
Oracle Local Registry configuration is :
         Device/File Name         : /u01/app/11.2.0/grid/cdata/node1.olr

OCRCONFIG
Use the ocrconfig command to manage OCR. Using this utility you can import, export, add, delete, restore, overwrite, backup, repair, replace, move, upgrade, or downgrade OCR.
使用ocrconfig命令來管理OCR。 使用此實用程式,您可以匯入,匯出,新增,刪除,恢復,覆蓋,備份,修復,替換,移動,升級或降級OCR。
手工備份OCR
ocrconfig -manualbackup
配置OCR備份路徑
ocrconfig -backuploc /nfsfolder/
檢視OCR的手工備份
ocrconfig -showbackup manual
檢視OCR的自動備份
ocrconfig -showbackup auto
邏輯備份OCR
ocrconfig -export /home/oracle/ocr.dump
邏輯備份OLR
ocrconfig -local -export /home/oracle/olr.dump

新增一個新的ocr檔案到磁碟組
ocrconfig -add +DATA
從磁碟組裡刪除一個OCR檔案
ocrconfig -delete +DATA

OCRDUMP
The OCRDUMP utility enables you to view OCR and OLR contents by writing the content to a file or stdout in a readable format.
OCRDUMP實用程式使您能夠將內容寫入可讀取格式的檔案或stdout來檢視OCR和OLR內容。
ocrconfig -export邏輯匯出的dump開啟是亂碼,所以如果要檢視OCR的內容,只能使用ocrdump
將OCR檔案內容寫入/home/grid/FILE1檔案
ocrdump /home/grid/FILE1



應用層SRVCTL
Use SRVCTL to manage configuration information. You can use SRVCTL commands to add, remove, start, stop, modify, enable, and disable a number of entities, such as databases, instances, listeners, SCAN listeners, services, grid naming service (GNS), and Oracle ASM.
使用SRVCTL來管理配置資訊。 您可以使用SRVCTL命令新增,刪除,啟動,停止,修改,啟用和禁用許多實體,如資料庫,例項,偵聽器,SCAN偵聽器,服務,網格命名服務(GNS)和Oracle ASM。
SRVCTL管理叢集上的各個資源,啟停各個應用,註冊各個應用,在oracle和grid的bin下面都有這個命令

檢視nodeapps節點配置(含VIP、GSD、ONS)
srvctl config nodeapps
檢視nodeapps節點狀態(含VIP、GSD、ONS)
srvctl status nodeapps

檢視DB配置

srvctl config database(檢視在叢集中註冊的所有資料庫)
srvctl config database -d db_name
srvctl config database -d db_name -a(加了-a可以看到DB是否隨叢集自動啟動)
檢視DB狀態
srvctl status database -d db_name

檢視listener配置、狀態
srvctl config listener
srvctl status listener
檢視scan_listener配置、狀態(不能透過lsnrctl來看scan的監聽,所以只能以下兩者結合srvctl config scan)
srvctl config scan_listener
srvctl status scan_listener

檢視asm配置、狀態
srvctl config asm
srvctl status asm
檢視SCAN IP配置(IP地址具體是多少)
srvctl config scan
檢視SCAN IP狀態(具體落在哪個節點)
srvctl status scan

檢視VIP的配置、狀態
srvctl config vip -n node_name
srvctl config nodeapps -a
srvctl status vip -n node_name
srvctl status nodeapps
DB註冊到叢集
srvctl add database -d db_name -o $ORACLE_HOME
或加上-p固化引數檔案
srvctl add database -d db_name -o $ORACLE_HOME -p +XX/spfilevm72.ora
DB從叢集中取消
srvctl remove database -d db_name
新增一個serverpool
srvctl add srvpool -g serverpoolname -n "node1, node2"(srvctl建立的serverpool只能給資料庫使用,不能給第三方的應用使用)


配置DB是否隨叢集啟動而自動啟動(必須同時Management policy: AUTOMATIC和Database is enabled)
srvctl modify database -d db_name -y AUTOMATIC  
srvctl enable database -d db_name  
srvctl modify database -d db_name -y MANUAL --只要設定則資料庫不自動啟動
srvctl disable database -d db_name --只要設定則資料庫不自動啟動
srvctl enable instance -d db_name –i instance_name --某個例項自動啟動
srvctl disable instance -d db_name –i instance_name --某個例項不自動啟動
srvctl config database -d db_name -a(加了-a可以看到DB是否隨叢集自動啟動)

Management policy
SRVCTL只有database和service才有-y Management policy的選項
Management policy for the database. If AUTOMATIC (the default), the database is automatically restored to its previous running condition (started or stopped) upon restart of the database host computer. If MANUAL, the database is never automatically restarted upon restart of the database host computer. 
The management policy for a service controls whether the service starts automatically when the database is restarted. If the management policy for a service is set to AUTOMATIC, then it restarts automatically. If the management policy for a service is set to MANUAL, then it must be started manually.

Enable
The srvctl enable command reenables the specified disabled component so that:
Oracle Restart can automatically restart it.
It can be automatically started through a dependency.



應用層ONSCTL
Oracle Notification Service (ONS). ONS (ons.jar) is included as part of the Oracle Client software. ONS can be configured using either remote configuration or client-side ONS daemon configuration. Remote configuration is the preferred configuration for standalone client applications.
ONS(ons.jar)作為Oracle Client軟體的一部分。可以使用遠端配置或客戶端ONS守護程式配置來配置ONS。
[root@node1 ~]# onsctl -h
onsctl: unknown command: -h
usage: onsctl [verbose] []
The verbose option enables debug tracing and logging (for the server start).
Permitted / combinations are:
command   options
-------   ---------
start                       - Start ons
shutdown                    - Shutdown ons
reload                      - Trigger ons to reread its configuration file
debug     [= ..] - Display ons server debug information
set       [= ..] - Set ons log parameters
query     [=]    - Query ons log parameters
ping      []     - Ping local ons
help                        - Print brief usage description (this)
usage     []       - Print detailed usage description
[root@node1 ~]# onsctl start
CRS-5702: Resource 'ora.ons' is already running on 'node1'
CRS-4000: Command Start failed, or completed with errors.
[root@node1 ~]# onsctl ping
ons is running ...

 

srvctl操作監聽或例項時不論startstopcrs中會自動onlineoffline

lsnrctl操作監聽時startcrs不一定online,但是stop時,crs一定會offline

sqlplus 操作例項時startcrs不一定online,但是stop時,crs一定會offline

如下系列圖1-2張在mdsdb02中,監聽是透過lsnrctl start啟動,可以看到在srvctl的命令中看不到節點mdsdb02的資訊,只有mdsdb01

 

一套ASM可以對應多套DB

20160811,把db_namedb521102異地恢復到原來db_namedbracRAC伺服器上,發現在同一套ASM下原來db_namedbrac也可以啟動,說明一套ASM可以對應多套DB,把原來的db_namedbrac透過srvctl remove database -d dbrac取消後就可以了,如下系列3-5














來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2123397/,如需轉載,請註明出處,否則將追究法律責任。

相關文章