Linux下創建Oracle 11.2.0.1服務及其開機自啓動

個人環境變量:
ORACLE_SID=bao
ORACLE_UNQNAME=$ORACLE_SID
ORACLE_BASE=/bao1
ORACLE_HOME=$ORACLE_BASE/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,添加以下腳本: rest

#!/bin/sh #chkconfig: 2345 20 80 #description: Oracle dbstart / dbshut #以上兩行爲chkconfig所需 ORA_HOME=/baofoo1/oracle ORA_OWNER=oracle LOGFILE=/baofoo1/oracle/startup.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." } stop(){     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 置爲可執行文件: code

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

 

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

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

 

將 oracle 添加到 chkconfig中: it

chkconfig --add oracle

 

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

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

 

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

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

 創建鏈接: 變量

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