直接執(zhí)行OS命令shutdown -h now ,后來發(fā)現(xiàn)啟動OS之后很多服務(wù)都是UNKNOW狀態(tài),想想自己那樣關(guān)閉數(shù)據(jù)庫太過于"暴力",決定還是按照"溫和"的方式去關(guān)閉集群數(shù)據(jù)庫比較好。
創(chuàng)新互聯(lián)建站主營柳北網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app軟件開發(fā)公司,柳北h5小程序開發(fā)搭建,柳北網(wǎng)站營銷推廣歡迎柳北等地區(qū)企業(yè)咨詢
一名學(xué)生最近在公司搭建RAC集群,但對其啟動與關(guān)閉的順序和原理不是特別清晰,我在教學(xué)工作中也發(fā)現(xiàn)了很多學(xué)員對RAC知識了解甚少,因此我在這里就把RAC里面涉及到的最常用的啟動與關(guān)閉順序和命令逐一列舉出來,由于RAC的后臺資源較多,因此涉及到的命令也很多,最后附上幫助手冊讓在工作中臨時使用時也可以迅速查到,如果這篇文章能夠幫到大家就是我今后繼續(xù)努力撰寫的動力,感謝大家對我文章的瀏覽多提寶貴意見。
關(guān)閉過程(CRS集群關(guān)閉-關(guān)閉數(shù)據(jù)庫)
1.關(guān)閉數(shù)據(jù)庫:
用oracl用戶執(zhí)行srvctl命令
語法:srvctl stop database -d dbname [-o immediate]
作用:可以一次性關(guān)閉dbname的所有實(shí)例
[oracle@rac1 ~]$ srvctl stop database -d racdb -停止所有節(jié)點(diǎn)上的實(shí)例
然后查看狀態(tài):
[oracle@rac1 ~]$ srvctl status database -d racdb
Instance rac1 is not running on node rac1
Instance rac2 is not running on node race
2.停止HAS(High Availability Services),必須以root用戶操作
[root@rac1 oracle]# cd /u01/grid/11.2.0/grid/bin
[root@rac1 bin]# ./crsctl stop has -f
[root@rac1 bin]# ./crsctl stop crs -f
本命令只能關(guān)閉當(dāng)前節(jié)點(diǎn)的CRS服務(wù),因此需要在RAC的所有節(jié)點(diǎn)上執(zhí)行,啟動也一樣。has與crs等同
3.停止節(jié)點(diǎn)集群服務(wù),必須以root用戶:
[root@rac1 oracle]# cd /u01/grid/11.2.0/grid/bin
[root@rac1 bin]# ./crsctl stop cluster ----停止本節(jié)點(diǎn)集群服務(wù)
[root@rac1 bin]# ./crsctl stop cluster -all ---停止所有節(jié)點(diǎn)服務(wù)
也可以如下控制所停節(jié)點(diǎn):
[root@rac1 bin]# crsctl stop cluster -n rac1 rac2
CRS-2677: Stop of 'ora.cssd' on 'rac1' succeeded
CRS-2677: Stop of 'ora.cssd' on 'rac2' succeeded
。。。。。。。。。。。省略日志輸出。。。。。。。。。。。。。。
你如果想一條命令把所有的進(jìn)程全部停止可以使用上述命令。如果不指定參數(shù)的話對當(dāng)前節(jié)點(diǎn)有效,如果指定參數(shù)的話對相關(guān)參數(shù)節(jié)點(diǎn)有效。
4.檢查集群進(jìn)程狀態(tài)
[root@rac1 bin]# crsctl check cluster
詳細(xì)輸出
[root@rac1 bin]# crs_stat -t -v
只檢查本節(jié)點(diǎn)的集群狀態(tài)
[root@rac1 bin]# crsctl check crs
啟動過程(CRS集群啟動-啟動數(shù)據(jù)庫)
1.啟動HAS
單一節(jié)點(diǎn)啟動
[root@rac2 ~]# crsctl start has
[root@rac2 ~]# crsctl start crs
[root@rac2 ~]# 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
所有節(jié)點(diǎn)啟動
[root@rac1 bin]# crsctl start cluster -n rac1 rac2
CRS-4123: Oracle High Availability Services has been started.
[root@rac1 bin]# crsctl start cluster -all
[root@rac2 ~]# crsctl check cluster
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
此命令會在后臺啟動所有RAC CRS相關(guān)進(jìn)程
[root@rac2 ~]# crs_stat -t -v
CRS-0184: Cannot communicate with the CRS daemon.
因?yàn)閟tart has啟動的crs進(jìn)程比較多因此會啟動的比較慢,我的機(jī)器等待了5分鐘,在沒有完全啟動成功之前會報(bào)上述錯誤,需要耐心等待一段時間后執(zhí)行下面命令即可查看到所有CRS相關(guān)進(jìn)程服務(wù)已經(jīng)啟動。
[root@rac2 ~]# crs_stat -t -v
Name Type R/RA F/FT Target State Host
----------------------------------------------------------------------
ora.DATA.dg ora....up.type 0/5 0/ ONLINE ONLINE rac1
ora....ER.lsnr ora....er.type 0/5 0/ ONLINE ONLINE rac1
ora....N1.lsnr ora....er.type 0/5 0/0 ONLINE ONLINE rac2
ora....N2.lsnr ora....er.type 0/5 0/0 ONLINE ONLINE rac1
ora....N3.lsnr ora....er.type 0/5 0/0 ONLINE ONLINE rac1
ora.asm ora.asm.type 0/5 0/ ONLINE ONLINE rac1
ora.cvu ora.cvu.type 0/5 0/0 ONLINE ONLINE rac1
ora.gsd ora.gsd.type 0/5 0/ OFFLINE OFFLINE
ora....network ora....rk.type 0/5 0/ ONLINE ONLINE rac1
ora.oc4j ora.oc4j.type 0/1 0/2 ONLINE ONLINE rac1
ora.ons ora.ons.type 0/3 0/ ONLINE ONLINE rac1
ora....SM1.asm application 0/5 0/0 ONLINE ONLINE rac1
ora....C1.lsnr application 0/5 0/0 ONLINE ONLINE rac1
ora.rac1.gsd application 0/5 0/0 OFFLINE OFFLINE
ora.rac1.ons application 0/3 0/0 ONLINE ONLINE rac1
ora.rac1.vip ora....t1.type 0/0 0/0 ONLINE ONLINE rac1
ora....SM2.asm application 0/5 0/0 ONLINE ONLINE rac2
ora....C2.lsnr application 0/5 0/0 ONLINE ONLINE rac2
ora.rac2.gsd application 0/5 0/0 OFFLINE OFFLINE
ora.rac2.ons application 0/3 0/0 ONLINE ONLINE rac2
ora.rac2.vip ora....t1.type 0/0 0/0 ONLINE ONLINE rac2
ora....ry.acfs ora....fs.type 0/5 0/ ONLINE ONLINE rac1
ora.scan1.vip ora....ip.type 0/0 0/0 ONLINE ONLINE rac2
ora.scan2.vip ora....ip.type 0/0 0/0 ONLINE ONLINE rac1
ora.scan3.vip ora....ip.type 0/0 0/0 ONLINE ONLINE rac1
說明:
英文解釋
ora.gsd is OFFLINE by default ifthere is no 9i database in the cluster.
ora.oc4j is OFFLINE in 11.2.0.1 as DatabaseWorkload Management(DBWLM) is unavailable. these can be ignored in11gR2 RAC.
中文解釋
ora.gsd是集群服務(wù)中用于與9i數(shù)據(jù)庫進(jìn)行通信的一個進(jìn)程,在當(dāng)前版本中為了向后兼容才保存下來,狀態(tài)為OFFLINE不影響CRS的正常運(yùn)行與性能,我們忽略即可
ora.oc4j是在11.2.0.2以上版本中有效的服務(wù)進(jìn)程,用于DBWLM的資源管理,因此在11.2.0.1以下版本并沒有使用
2.啟動數(shù)據(jù)庫:
oracl用戶執(zhí)行srvctl命令:
語法:srvctl start|stop|status database -d dbname [-o immediate]
作用:可以一次性啟動dbname的所有實(shí)例
[oracle@rac1 ~]$ srvctl start database -d racdb -啟動所有節(jié)點(diǎn)上的實(shí)例
然后查看狀態(tài):
[oracle@rac1 ~]$ srvctl status database -d racdb
3.詳細(xì)輸出資源全名稱并檢查狀態(tài)
crsctl status resource -t
crsctl status resource
4.常用srvctl命令
指定dbname上某個實(shí)例
srvctl start|stop|status instance -d -i instance_name
5.顯示RAC下所有實(shí)例配置與狀態(tài)
srvctl status|config database -d
6.顯示所有節(jié)點(diǎn)的應(yīng)用服務(wù)(VIP,GSD,listener,ONS)
srvctl start|stop|status nodeapps -nnode_name
7.ASM進(jìn)程服務(wù)管理
srvctl start|stop|status|config asm -n [-i asm_inst_name] [-ooracle_home]
srvctl config asm -a
srvctl status asm -a
6.可以獲取所有的環(huán)境信息:
srvctl getenv database -d [-iinstance_name]
7.設(shè)置全局環(huán)境和變量:
srvctl setenv database -d -t LANG=en
8.在OCR中刪除已有的數(shù)據(jù)庫信息
srvctl remove database -d
9.向OCR中添加一個數(shù)據(jù)庫的實(shí)例:
srvctl add instance -d -iinstance_name -n
srvctl add instance -d -iinstance_name -n
10.檢查監(jiān)聽的狀態(tài)
srvctl status listener
srvctl config listener -a
SCAN配置信息
srvctl config scan
SCAN listener狀態(tài)信息
srvctl status scan
小結(jié):crsctl命令是一個集群級別命令,可以對所有集群資源進(jìn)行統(tǒng)一啟動、停止等管理操作
srvctl命令是一個服務(wù)級別命令,可以對單一服務(wù)資源進(jìn)行統(tǒng)一啟動、停止等管理操作
附:srvctl命令啟動與停止的詳細(xì)幫助
[root@rac2 ~]# srvctl start -h
The SRVCTL start command starts, Oracle Clusterware enabled, non-running objects.
Usage: srvctl start database -d db_unique_name[-o start_options] [-n ]
Usage: srvctl start instance -d db_unique_name{-n node_name[-i inst_name] | -i inst_name_list} [-o start_options]
Usage: srvctl start service -d db_unique_name[-s "service_name_list" [-n node_name| -i inst_name] ] [-o start_options]
Usage: srvctl start nodeapps [-n node_name] [-g] [-v]
Usage: srvctl start vip { -n node_name| -i vip_name} [-v]
Usage: srvctl start asm [-n node_name] [-o start_options]
Usage: srvctl start listener [-l lsnr_name] [-n node_name]
Usage: srvctl start scan [-i ordinal_number] [-n node_name]
Usage: srvctl start scan_listener [-n node_name] [-i ordinal_number]
Usage: srvctl start oc4j [-v]
Usage: srvctl start home -o oracle_home-s state_file-n node_name
Usage: srvctl start filesystem -d volume_device[-n node_name]
Usage: srvctl start diskgroup -g dg_name[-n "node_list"]
Usage: srvctl start gns [-l log_level] [-n node_name] [-v]
Usage: srvctl start cvu [-n node_name]
For detailed help on each command and object and its options use:
srvctl -h
[root@rac2 ~]# srvctl stop -h
The SRVCTL stop command stops, Oracle Clusterware enabled, starting or running objects.
Usage: srvctl stop database -d db_unique_name[-o stop_options] [-f]
Usage: srvctl stop instance -d db_unique_name{-n node_name| -i inst_name_list} [-o stop_options] [-f]
Usage: srvctl stop service -d db_unique_name[-s "service_name_list" [-n node_name| -i inst_name] ] [-f]
Usage: srvctl stop nodeapps [-n node_name] [-g] [-f] [-r] [-v]
Usage: srvctl stop vip { -n node_name | -i vip_name} [-f] [-r] [-v]
Usage: srvctl stop asm [-n node_name] [-o stop_options] [-f]
Usage: srvctl stop listener [-l lsnr_name] [-n node_name] [-f]
Usage: srvctl stop scan [-i ordinal_number] [-f]
Usage: srvctl stop scan_listener [-i ordinal_number] [-f]
Usage: srvctl stop oc4j [-f] [-v]
Usage: srvctl stop home -o oracle_home-s state_file-n node_name[-t stop_options] [-f]
Usage: srvctl stop filesystem -d volume_device[-n node_name] [-f]
Usage: srvctl stop diskgroup -g dg_name[-n "node_list"] [-f]
Usage: srvctl stop gns [-n node_name] [-f] [-v]
Usage: srvctl stop cvu [-f]
For detailed help on each command and object and its options use:
srvctl -h
在windows里啟動Oracle有兩個步驟,一是先啟動服務(wù),二是再啟動實(shí)例、數(shù)據(jù)庫,這兩個都可以設(shè)置成自動或者手動
針對數(shù)據(jù)庫開機(jī)自動啟動問題,解決方法有兩個
方法一:在服務(wù)把oracleservice%SID%這個服務(wù)改成手動啟動
方法二:修改注冊表HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\HOME0\ORA_%SID%_AUTOSTART的值為false,這個是控制啟動服務(wù)時是否自動啟動數(shù)據(jù)庫(實(shí)例,占內(nèi)存),默認(rèn)是true
注冊表還有個ORA_%SID%_shutdown它是控制你關(guān)機(jī)時是否自動關(guān)數(shù)據(jù)庫的
啟動服務(wù)可以用net start oracleservice%SID% 命令
停止服務(wù)可以用net start oracleservice%SID% 命令
手動啟動數(shù)據(jù)庫要先開始服務(wù),不然sqlplus不能進(jìn)行操作系統(tǒng)驗(yàn)證了
進(jìn)入sqlplus “/as sysdba"
啟動數(shù)據(jù)庫是在sqlplus里輸入startup
關(guān)閉數(shù)據(jù)庫是在sqlplus里輸入shutdown immediate
Deleting a Cluster Node on Linux and UNIX Systems
1.確定要刪除的節(jié)點(diǎn),是否active,pinned
$ olsnodes -s -t
如果 pinned ,則crsctl unpin css -n nodename unpinned 相應(yīng)的節(jié)點(diǎn)
2、禁用相應(yīng)集群節(jié)點(diǎn)的應(yīng)用資源,進(jìn)程
先停掉 em:
emctl stop dbconsole
以root 用戶運(yùn)行 在要刪除節(jié)點(diǎn)的 $Grid_home/crs/install 路徑下運(yùn)行rootcrs.pl 腳本
# ./rootcrs.pl -deconfig -force
如果要刪除所有節(jié)點(diǎn):
# ./rootcrs.pl -deconfig -force -lastnode
有時vip 資源不一定會被刪除,這是需要手動來刪除:
# srvctl stop vip -i vip_name-f
# srvctl remove vip -i vip_name-f
3、在其他節(jié)點(diǎn)執(zhí)行以下命令:
crsctl delete node -n node_to_be_deleted
4、在要刪除的節(jié)點(diǎn)上執(zhí)行以下命令:
腳本在 :$Grid_home/oui/bin
$ ./runInstaller -updateNodeList Oracle_HOME=Grid_home"CLUSTER_NODES={node_to_be_deleted}" CRS=TRUE -silent -local
5、清理要刪除節(jié)點(diǎn)的Clusterware home 安裝文件:
$ Grid_home/deinstall/deinstall –local
注意一定要添加 -local 選項(xiàng) ,否者會刪除 所有節(jié)點(diǎn)的Clusterware home 安裝目錄.
6、在其他節(jié)點(diǎn)執(zhí)行以下命令,更新節(jié)點(diǎn)信息:
腳本在 $Grid_home/oui/bin
$./runInstaller -updateNodeList ORACLE_HOME=Grid_home"CLUSTER_NODES={remaining_nodes_list}" CRS=TRUE -silent
7、驗(yàn)證要刪除的節(jié)點(diǎn)是否已經(jīng)成功刪除:
$ cluvfy stage -post nodedel -n node_list[-verbose]
/etc/init.d/oracle #!/bin/sh
#
# oraShell -- user start|stop script for oracle
#
LOG_EMERG=0 # system is unusable
LOG_ALERT=1 # action must be taken immediately
LOG_CRIT=2 # critical conditions
LOG_ERR=3 # error conditions
LOG_WARNING=4 # warning conditions
LOG_NOTICE=5 # normal but significant condition
LOG_INFO=6 # informational
LOG_DEBUG=7 # debug-level messages
script_name=`basename $0`
clulog()
{
log_level=$1
log_info=$2
/opt/cluster/bin/clulog -p $$ -n $script_name -s $log_level "$log_info"
}
case $1 in
start)
# start listener
su - oracle -c "lsnrctl start"
retval=$?
if [ $retval -eq 0 ]; then
clulog $LOG_INFO "oraShell: lsnrctl start succeeded."
else
clulog $LOG_ERR "oraShell: lsnrctl start failed, ret=$retval."
exit 1
fi
# start oracle
su - oracle -c "sqlplus /nolog" EOF
connect / as sysdba
startup
quit
EOF
ps -wwwef | grep ora_pmon | grep -v grep /dev/null 21
retval=$?
if [ $retval -eq 0 ]; then
clulog $LOG_INFO "oraShell: oracle database start succeeded."
else
clulog $LOG_ERR "oraShell: oracle database start failed."
exit 1
fi
;;
stop)
# stop listener
su - oracle -c "lsnrctl stop"
retval=$?
if [ $retval -eq 0 ]; then
clulog $LOG_INFO "oraShell: lsnrctl stop succeeded."
else
clulog $LOG_ERR "oraShell: lsnrctl stop failed, ret=$retval."
exit 1
fi
# stop oracle
su - oracle -c "sqlplus /nolog" EOF
connect / as sysdba
shutdown immediate
quit
EOF
ps -wwwef | grep ora_pmon | grep -v grep /dev/null 21
retval=$?
if [ $retval -ne 0 ]; then
clulog $LOG_INFO "oraShell: oracle database stop succeeded."
else
clulog $LOG_ERR "oraShell: oracle database stop failed."
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
# succeed
exit 0