1. 程式人生 > >Oracle資料庫教程RAC常用維護工具和命令

Oracle資料庫教程RAC常用維護工具和命令

           Oracle 資料庫教程  ——  rac 常用維護工具和命令  


注:本文整理自<大話 Oracle RAC>  注:



Oracle 的管理可以通過OEM 或者命令列介面。 Oracle Clusterware 的命令集可以分為以下4 種:  






節點層:osnodes  






網路層:oifcfg  






叢集層:crsctl, ocrcheck,ocrdump,ocrconfig  






應用層:srvctl,onsctl,crs_stat  






下面分別來介紹這些命令。    






    






一. 節點層  






只有一個命令:  osnodes, 這個命令用來顯示叢集點列表,可用的引數如下,這些引數可以混合使用。  






[[email protected]
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  






[
[email protected]
bin]# ./olsnodes -n -p -i  






raw1       1             raw1-priv             raw1-vip  






raw2       2             raw2-priv             raw2-vip    






    






二. 網路層  






  網路層由各個節點的網路元件組成,包括2 個物理網絡卡和3 個IP 地址。 也只有一個命令:oifcfg.  




----------------------- Page 2-----------------------


    






  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:刪除網口  






[
[email protected]
bin]# ./oifcfg --help  






PRIF-9: incorrect usage  






  






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 }  






[[email protected] bin]# ./oifcfg iflist  






eth0   10.85.10.0  




----------------------- Page 3-----------------------


    






eth1   192.168.1.0  






[[email protected] 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 型別的網絡卡  






[[email protected] 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  






-- 刪除介面配置  






[[email protected] bin]# ./oifcfg delif -global  






-- 新增介面配置  






[[email protected] bin]# ./oifcfg setif -global eth0/192.168.1.119:public  






[[email protected] 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 程序功能。  






[[email protected] 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  




----------------------- Page 4-----------------------


    






             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  




----------------------- Page 5-----------------------


    






    






  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  






3.1.1 檢查CRS 狀態  






[[email protected] bin]# ./crsctl check crs  






CSS appears healthy  






CRS appears healthy  






EVM appears healthy  






  -- 檢查單個狀態  






[[email protected] bin]# ./crsctl check cssd  






CSS appears healthy  






[[email protected] bin]# ./crsctl check crsd  






CRS appears healthy  






[[email protected] bin]# ./crsctl check evmd  






EVM appears healthy  






    






3.1.2 配置CRS 棧是否自啟動  






     CRS 程序棧預設隨著作業系統的啟動而自啟動,有時出於維護目的需要關閉這個特性,可以用root 用 






戶執行下面命令。    






[[email protected] bin]# ./crsctl disable crs  






[[email protected] bin]# ./crsctl enable crs  






這個命令實際是修改了/etc/oracle/scls_scr/raw/root/crsstart 這個檔案裡的內容。  






    






3.1.3 啟動,停止CRS 棧。  






    






Oracle 在10.1 時,必須通過重新啟動系統重啟Clusterware,但是從Oracle 10.2 開始,可以通過命令 






來啟動和停止CRS.  






-- 啟動CRS:  






[[email protected] bin]# ./crsctl start crs  




----------------------- Page 6-----------------------


    






Attempting to start CRS stack  






The CRS stack will be started shortly  






-- 關閉CRS:  






[[email protected] bin]# ./crsctl stop crs  






Stopping resources.  






Successfully stopped CRS resources  






Stopping CSSD.  






Shutting down CSS daemon.  






Shutdown request successfully issued.  






    






3.1.4 檢視Votedisk 磁碟位置  






[[email protected] bin]# ./crsctl query css votedisk  






  0.         0       /dev/raw/raw2  






located 1 votedisk(s).  






    






3.1.5 檢視和修改CRS 引數  






-- 檢視引數:用get  






[[email protected] bin]# ./crsctl get css misscount  






60  






-- 修改引數: 用set, 但是這個功能要慎用  






[[email protected] bin]# ./crsctl set css miscount 60  






    






3.1.6 跟蹤CRS 模組,提供輔助功能  






CRS 由CRS,CSS,EVM 三個服務組成,每個服務又是由一系列module 組成,crsctl 允許對每個module 進 






行跟蹤,並把跟蹤內容記錄到日誌中。  






[[email protected] bin]# ./crsctl lsmodules css  






The following are the CSS modules ::  






       CSSD  






       COMMCRS  






COMMNS  




----------------------- Page 7-----------------------


    






 [[email protected] 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  






 [[email protected] bin]# ./crsctl lsmodules evm  






The following are the EVM modules ::  






     EVMD  






     EVMDMAIN  






     EVMCOMM  






     EVMEVT  






     EVMAPP  






     EVMAGENT  






     CRSOCR  






     CLUCLS  






     CSSCLNT  






     COMMCRS  




----------------------- Page 8-----------------------


    






     COMMNS  






    






--跟蹤CSSD 模組,需要root 使用者執行:  






[[email protected] bin]# ./crsctl debug log css "CSSD:1"  






Configuration parameter trace is now set to 1.  






Set CRSD Debug Module: CSSD   Level: 1  






    






-- 檢視跟蹤日誌  






[[email protected] cssd]# pwd  






/u01/app/oracle/product/crs/log/raw1/cssd  






[[email protected] 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) 檢視當前配置  






[[email protected] bin]# ./crsctl query css votedisk  




----------------------- Page 9-----------------------


    






2)   停止所有節點的CRS:  






[[email protected] bin]# ./crsctl stop crs  






3) 新增Votedisk  






          [[email protected] 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)   確認新增後的情況:  






[[email protected] bin]# ./crsctl query css votedisk  






5) 啟動CRS  






[[email protected] 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/<cluster_name> 目錄下。 每次備份後,備份檔名自動更改,以反應備份時間順序, 






最近一次的備份叫作backup00.ocr。這些備份檔案除了儲存在本地,DBA 還應該在其他儲存裝置上保留一 






份,以防止意外的儲存故障。  






    






3.2.1 ocrdump  






該命令能以ASCII 的方式打印出OCR 的內容,但是這個命令不能用作OCR 的備份恢復,也就是說產生的文 






件只能用作閱讀,而不能用於恢復。    






命令格式: ocrdump [-stdout] [filename] [-keyname name] [-xml]  






引數說明:  






               -stdout: 把內容列印輸出到螢幕上  






Filename:內容輸出到檔案中  






-keyname:只打印某個鍵及其子健內容  






-xml:以xml 格式列印輸出  




----------------------- Page 10-----------------------


    






     示例:把system.css 鍵的內容以.xml 格式列印輸出到螢幕  






[[email protected] bin]# ./ocrdump -stdout -keyname system.css -xml|more  






<OCRDUMP>  






    






<TIMESTAMP>03/08/2010 04:28:41</TIMESTAMP>  






<DEVICE>/dev/raw/raw1</DEVICE>  






<COMMAND>./ocrdump.bin -stdout -keyname system.css -xml </COMMAND>  






......  






    






這個命令在執行過程中,會在$CRS_HOME/log/<node_name>/client  目錄下產生日誌檔案,檔名 






ocrdump_<pid>.log,如果命令執行出現問題,可以從這個日誌檢視問題原因。  






    






3.2.2 ocrcheck  






Ocrcheck 命令用於檢查OCR 內容的一致性,命令執行過程會在$CRS_HOME/log/nodename/client  目錄下產 






生ocrcheck_pid.log  日誌檔案。 這個命令不需要引數。  






[[email protected] 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  




----------------------- Page 11-----------------------


    






該命令用於維護OCR 磁碟,安裝clusterware 過程中,如果選擇External Redundancy 冗餘方式,則只能 






輸入一個OCR 磁碟位置。 但是Oracle 允許配置兩個OCR 磁碟互為映象,以防止OCR 磁碟的單點故障。 OCR  






磁碟和Votedisk 磁碟不一樣,OCR 磁碟最多隻能有兩個,一個Primary OCR 和一個Mirror OCR。  






[[email protected] 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  




----------------------- Page 12-----------------------


    






                               -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.  






    






-- 檢視自助備份  






[[email protected] bin]# ./ocrconfig -showbackup  






    






在預設情況下,OCR 自動備份在$CRS_HOME/CRS/CDATA/cluster_name  目錄下,可以通過ocrconfig  






-backuploc <directory_name> 命令修改到新的目錄  






    






3.2.4 使用匯出,匯入進行備份和恢復  






Oracle 推薦在對叢集做調整時,比如增加,刪除節點之前,應該對OCR 做一個備份,可以使用export 備 






份到指定檔案,如果做了replace 或者restore 等操作,Oracle 建議使用 cluvfy comp ocr -n all 命 






令來做一次全面的檢查。該命令在clusterware 的安裝軟體裡。  






1) 首先關閉所有節點的CRS  






[[email protected] bin]# ./crsctl stop crs  






Stopping resources.  






Successfully stopped CRS resources  






Stopping CSSD.  






Shutting down CSS daemon.  






Shutdown request successfully issued.  






         2) 用root 使用者匯出OCR 內容  






[[email protected] bin]# ./ocrconfig -export /u01/ocr.exp  






         3) 重啟CRS  






[[email protected] bin]# ./crsctl start crs  






Attempting to start CRS stack  




----------------------- Page 13-----------------------


    






The CRS stack will be started shortly  






         4) 檢查CRS 狀態  






[[email protected] bin]# ./crsctl check crs  






CSS appears healthy  






CRS appears healthy  






EVM appears healthy  






       5)破壞OCR 內容  






[[email protected] bin]# dd if=/dev/zero of=/dev/raw/raw1 bs=1024 count=102400  






102400+0 records in  






102400+0 records out  






6) 檢查OCR 一致性  






[[email protected] bin]# ./ocrcheck  






PROT-601: Failed to initialize ocrcheck  






       7)使用cluvfy 工具檢查一致性  






[[email protected] cluvfy]# ./runcluvfy.sh comp ocr -n all  






Verifying OCR integrity  






Unable to retrieve nodelist from Oracle clusterware.  






Verification cannot proceed.  






8) 使用Import 恢復OCR 內容  






[[email protected] bin]# ./ocrconfig -import /u01/ocr.exp  






9)再次檢查OCR  






[[email protected] 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  




----------------------- Page 14-----------------------


    






                                                                       Device/File integrity  






check succeeded  






                                                                       Device/File not  






configured  






                 Cluster registry integrity check succeeded  






10) 使用cluvfy 工具檢查  






[[email protected] 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 備份  






[[email protected] bin]# ./ocrconfig -showbackup  






如果沒有備份,可以立即執行一次匯出作為備份:  






[[email protected] bin]# ./ocrconfig -export /u01/ocrbackup -s online  






2) 檢視當前OCR 配置  






[[email protected] bin]# ./ocrcheck  






Status of Oracle Cluster Registry is as follows :  






                 Version                                    :                   2  




----------------------- Page 15-----------------------


    






                 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  






[[email protected] bin]# ./ocrconfig -replace ocrmirror /dev/raw/raw4  






4) 確認新增成功  






[[email protected] bin]# ./ocrcheck  






5)改變primary OCR 位置  






[[email protected] bin]# ./ocrconfig -replace ocr /dev/raw/raw3  






確認修改成功:  






[[email protected] bin]# ./ocrcheck  






       6)使用ocrconfig 命令修改後,所有RAC 節點上的/etc/oracle/ocr.loc 檔案內容也會自動同步 






了,如果沒有自動同步,可以手工的改成以下內容。  






[[email protected] 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    




----------------------- Page 16-----------------------


    






    






Crs_stat 這個命令用於檢視CRS 維護的所有資源的執行狀態,如果不帶任何引數時,顯示所有資源的概要 






資訊。每個資源顯示是各個屬性:資源名稱,型別,目錄,資源執行狀態等。    






[[email protected] bin]# ./crs_stat  






NAME=ora.raw.db  






TYPE=application  






TARGET=ONLINE  






STATE=OFFLINE  






......  






    






也可以指定資源名,檢視指定資源的狀態,並可以使用-V 和-P 選項,以檢視詳細資訊,其中-p 引數顯示 






的內容比-V 更詳細。  






1) 檢視制定資源狀態  






[[email protected] bin]# ./crs_stat ora.raw2.vip  






NAME=ora.raw2.vip  






TYPE=application  






TARGET=ONLINE  






STATE=OFFLINE  






2) 使用-v 選項,檢視詳細內容,這時輸出多出4 項內容,分別是允許重啟次數,已執行重啟次數,失敗 






閥值,失敗次數。  






[[email protected] 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 選項檢視更詳細內容  




----------------------- Page 17-----------------------


    






 [[email protected] 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  




----------------------- Page 18-----------------------


    






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 一樣。  






[[email protected] 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--  




----------------------- Page 19-----------------------


    






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.    






[[email protected] conf]# pwd  






/u01/app/oracle/product/crs/opmn/conf  






[[email protected] conf]# more ons.config  






localport=6100  






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 進行通 






信。  




----------------------- Page 20-----------------------


    






Nodes 引數值格式如下:Hostname/IP:port[hostname/ip:port]  






如:useoce=off  






Nodes=rac1:6200,rac2:6200  






而useocr 引數值為on/off, 如果useocr 是ON, 說明資訊儲存在OCR 中,如果是OFF,說明資訊取nodes 






中的配置。對於單例項而言,要把useocr 設定為off。  






    






4.2.2 配置ONS  






可以直接編譯ONS 的配置檔案來修改配置,如果使用了OCR,則可以通過racgons 命令進行配置,但必須 






以root 使用者來執行,如果用oracle 使用者來執行,不會提示任何錯誤,但也不會更改任何配置。  






若要新增配置,可以使用下面命令:  






Racgons add_config rac1:6200 rac2:6200  






若要刪除配置,可以用下面命令:  






Racgons remove_config rac1:6200 rac2:6200  






    






4.2.3 onsctl 命令  






使用onsctl 命令可以啟動,停止,除錯ONS,並重新載入配置檔案,其命令格式如下:  






[[email protected] 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.  






    






   ONS 程序執行,並不一定代表ONS 正常工作,需要使用ping 命令來確認。    




----------------------- Page 21-----------------------


    






    






1) 在OS 級別檢視程序狀態。    






[[email protected] bin]# ps -aef|grep ons  






root           1924   6953   0 03:17 pts/1       00:00:00 grep ons  






oracle     30723         1   0 Mar08 ?               00:00:00  






/u01/app/oracle/product/crs/opmn/bin/ons -d  






oracle     30724 30723   0 Mar08 ?               00:00:04  






/u01/app/oracle/product/crs/opmn/bin/ons -d  






2) 確認ONS 服務的狀態  






[[email protected] bin]# ./onsctl ping  






Number of onsconfiguration retrieved, numcfg = 2  






onscfg[0]  






      {node = raw1, port = 6200}  






Adding remote host raw1:6200  






onscfg[1]  






      {node = raw2, port = 6200}  






Adding remote host raw2:6200  






ons is running ...  






3) 啟動ONS 服務  






[[email protected] bin]# ./onsctl start  






4) 使用debug 選項,可以檢視詳細資訊,其中最有意義的就是能顯示所有連線。  






[[email protected] bin]# ./onsctl debug  






Number of onsconfiguration retrieved, numcfg = 2  






onscfg[0]  






      {node = raw1, port = 6200}  






Adding remote host raw1:6200  






onscfg[1]  






      {node = raw2, port = 6200}  






Adding remote host raw2:6200  






HTTP/1.1 200 OK  




----------------------- Page 22-----------------------


    






Content-Length: 1357  






Content-Type: text/html  






Response :  






======== ONS ========  






Listeners:  






  NAME       BIND ADDRESS     PORT     FLAGS     SOCKET  






------- --------------- ----- -------- ------  






Local     127.000.000.001   6100 00000142           7  






Remote   010.085.010.119   6200 00000101           8  






Request         No listener  






Server connections:  






       ID                     IP               PORT       FLAGS       SENDQ         WORKER  






   BUSY   SUBS  






---------- --------------- ----- -------- ---------- -------- ------ -----  






                 1 010.085.010.121   6200  






00104205                   0                             1         0  






Client connections:  






    






       ID                     IP               PORT       FLAGS       SENDQ         WORKER  






   BUSY   SUBS  






---------- --------------- ----- -------- ---------- -------- ------ -----  






                 3 127.000.000.001   6100  






0001001a                   0                             1         0  






                 4 127.000.000.001   6100  






0001001a                   0                             1         1  






Pending connections:  






       ID                     IP               PORT       FLAGS       SENDQ         WORKER  






   BUSY   SUBS  






---------- --------------- ----- -------- ---------- -------- ------ -----  






                 0 127.000.000.001   6100  






00020812                   0                             1         0  




----------------------- Page 23-----------------------


    






Worker Ticket: 3/3, Idle: 180  






     THREAD     FLAGS  






   -------- --------  






     17faba0 00000012  






     67f6ba0 00000012