開機自動啟動ORACLE ON Linux

zhanglei_itput發表於2010-05-17

 
    在單例項Linux平臺中,oracle是不會跟os啟動而啟動的,需要手工啟動資料庫,所以嘗試使用如下自動啟動資料庫指令碼,其中的em和isqlplus服務根據現有情況決定是否自動啟動。
 
1.  首先編輯/etc/oratab檔案
      確認哪些資料庫可以使用dbstart命令啟動,修改成Y(預設是N),例如:
      ora10g:/oracle/product/10.2.0/db:Y
      test:/oracle/product/10.2.0/db:Y

2. 建立啟動關閉指令碼/etc/init.d/dbora
# chmod +x /etc/init.d/dbora
[/etc/init.d/dbora]
#!/bin/bash
# Oracle init script. for Linux.
#
# chkconfig: 345 99 10
# description: Oracle Automatic Startup/Shutdown on Linux
ORACLE_OWNER=oracle
ORACLE_HOME=/home/oracle/product/10.2.0/db
case "$1" in
  start)
    echo "Starting Oracle Databases ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbstart" >> /var/log/oracle
    echo "Done."
    echo "Starting Oracle Listeners ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    echo "Done."
    echo "Starting Oracle10g DBConsole ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/emctl start dbconsole" >> /var/log/oracle
    echo "Done."
    echo "Starting Oracle10g iSQLPlus ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/isqlplusctl start" >> /var/log/oracle
    echo "Done."
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Finished." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    touch /var/lock/subsys/oracle
    ;;
  stop)
    rm -f /var/lock/subsys/oracle
    echo "Stoping Oracle10g iSQLPlus ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/isqlplusctl stop" >> /var/log/oracle
    echo "Done."
    echo "Stoping Oracle10g DBConsole ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/emctl stop dbconsole" >> /var/log/oracle
    echo "Done."
    echo "Stoping Oracle Listeners ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop" >> /var/log/oracle
    echo "Done."
    echo "Stoping Oracle Databases ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbshut" >> /var/log/oracle
    echo "Done."
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Finished." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: dbora {start|stop|restart}"
    exit 1
esac

3. 開機自動啟動
    # chkconfig dbora on
    開機關閉自動啟動
    # chkconfig dbora off
 

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

相關文章