Linux下oracle開機自啓動服務

若是每次重啓操做系統都要進行以上操做好麻煩,那麼如何讓Oracle做爲系統服務在開機的時候自動啓動呢?數據庫

Oracle在$ORACLE_HOME/bin下提供許多對數據庫進行操做的腳本,其中dbstart和dbshut可分別用來啓動和關閉數據庫。注意,這兩個腳本已包含監聽器的啓動或關閉,但並未對EM進行相關的操做。使用以下命令:oracle

/opt/oracle/11g/bin/dbstart /opt/oracle/11g #啓動數據庫實例(包含監聽器) /opt/oracle/11g/bin/dbshut /opt/oracle/11g #關閉數據庫實例(包括監聽器)

以上命令要成功啓動數據庫實例還得打開Oracle設置的一個關卡:vi /etc/oratab,修改行:spa

orcl:/opt/oracle/11g:Y #默認爲orcl:/opt/oracle/11g:N

以root身份創建開機啓動oracle服務的腳本:vi /etc/init.d/oracle,添加以下腳本:操作系統

#!/bin/sh #chkconfig: 2345 20 80 #description: Oracle dbstart / dbshut #以上兩行爲chkconfig所需 ORA_HOME=/opt/oracle/11g ORA_OWNER=oracle LOGFILE=/var/log/oracle.log echo "#################################" >> ${LOGFILE} date +"### %T %a %D: Run Oracle" >> ${LOGFILE} if [ ! -f ${ORA_HOME}/bin/dbstart ] || [ ! -f ${ORA_HOME}/bin/dbshut ]; then echo "Error: Missing the script file ${ORA_HOME}/bin/dbstart or ${ORA_HOME}/bin/dbshut!" >> ${LOGFILE} echo "#################################" >> ${LOGFILE} exit fi start(){ echo "###Startup Database..." su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}" echo "###Done." echo "###Run database control..." su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl start dbconsole" echo "###Done." } stop(){ echo "###Stop database control..." su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl stop dbconsole" echo "###Done." echo "###Shutdown Database..." su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbshut ${ORA_HOME}" echo "###Done." } case "$1" in
    'start') start >> ${LOGFILE} ;; 'stop') stop >> ${LOGFILE} ;; 'restart') stop >> ${LOGFILE} start >> ${LOGFILE} ;; esac date +"### %T %a %D: Finished." >> ${LOGFILE} echo "#################################" >> ${LOGFILE} echo ""

 

使用以下命令將 /etc/init.d/oracle 置爲可執行文件:rest

chmod a+x /etc/init.d/oracle

至此,可以使用以下命令對oracle進行啓動和關閉code

/etc/init.d/oracle start #啓動oracle(包括數據庫實例、監聽器、EM) /etc/init.d/oracle stop #關閉oracle /etc/init.d/oracle restart #重啓oracle

將 oracle 添加到 chkconfig中:blog

chkconfig --add oracle

可以使用以下命令查看和設置oracle服務的開機啓動級別:ip

chkconfig | grep oracle #查看oracle服務的開機啓動級別 chkconfig --level 24 oracle off #修改oracle服務的開機啓動級別 chkconfig --level 35 oracle on

至此可以使用以下命令對oracle的啓動或關閉進行管理it

service oracle start #啓動 service oracle stop #關閉 service oracle restart #重啓

 創建鏈接:io

ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle #關機執行 ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle   #重啓執行
相關文章
相關標籤/搜索