Orale自動啟動以及關閉指令碼_linux

andyann發表於2011-05-23
目的
--- 能夠實現開機啟動Oracle
--- 重啟、關閉伺服器的時候能先關閉
--- Oracle可以用service命令啟、停Oracle

1. 修改Oracle系統配置檔案:/etc/oratab //oratab格式:SID:ORACLE_HOME:AUTO
# vi /etc/oratab
orcl:/Oracle/app/product/11.1.0/db:Y

2. 在 /etc/init.d/ 下建立檔案oracle,11G以前編寫內容如下:

#!/bin/bash
#chkconfig: 35 99 01
#description: Oracle auto start-stop-restart script
#
#Set ORA_HOME to be equivalent to the $ORACLE_HOME from which you wish to execute dbstart and dbshutdown
#
#Set ORA_OWNER to the user id of the owner of the Oracle database in ORA_HOME.

ORA_HOME=/Oracle/app/product/11.1.0/db
ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databasee as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
echo "Done"

# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl 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')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle

# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
;;

'restart')
$0 stop
$0 start
;;
esac

3. 改變檔案許可權
# chmod 755 /etc/init.d/oracle

4. 新增服務
# chkconfig --level 35 oracle on

5. 需要在重新啟動時停止資料庫,做一下操作
# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle   //關機
# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle   //重啟

6. 使用方法
# service oracle start //啟動oracle
# service oracle stop //關閉oracle



11G以後指令碼:

修改dbstart和dbshut指令碼
行:ORACLE_HOME_LISTNER=$1修改為:
ORACLE_HOME_LISTNER=$ORACLE_HOME

#!/bin/bash
#chkconfig: 35 99 01
#description:Startup Script. for oracle Databases
#/etc/rc.d/init.d/oradbstart
export ORACLE_BASE=/Oracle/app/
export ORACLE_HOME=/Oracle/app/product/11.1.0/db
export ORACLE_SID=pir
export PATH=$PATH:$ORACLE_HOME/bin

case"$1"in
start)
echo "-----startuporacle-----" >> /var/log/oracle11log
su oracle -c $ORACLE_HOME/bin/dbstart
touch /var/lock/subsys/oracle11
echo "-----startuporaclesuccessful-----" >> /var/log/oracle11log
echo "OK"
;;
stop)
echo "-----shutdwnoracle-----" >> /var/log/oracle11log
suoracle-c$ORACLE_HOME/bin/dbshut
rm -f /var/lock/subsys/oracle11
echo "-----shutdownoraclesuccessful-----" >> /var/log/oracle11log
echo "OK"
;;
*)
echo "Usage:'basename$0'start|stop"
exit1
esac
exit0

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

相關文章