linux下 Oracle自動啟動與停止(經試驗可以執行在oracle9 10 11上)

zhanghjgnu發表於2008-06-15
1、 修改Oracle系統配置檔案/etc/oratab
/etc/oratab 格式為: SID:ORACLE_HOME:AUTO
把AUTO域設定為Y(大寫),只有這樣, 自帶的dbstart和dbshut才能夠發揮作用。我的為:
ora9i:/home//ora/products/9.2.0:Y
2、 編寫服務指令碼:
如下
#!/bin/bash
#
#################FUNCTION#############
#
# AutoStart Oracle and listener
# AutoStop Oracle and listener
#
#####################################
#
# Created by ZhouYS 2003-11-26
#

case "$1" in
start)
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/
date +" %T %a %D : Starting Oracle Databasee as part of system up." >> /var/log/
echo "-------------------------------------------------" >> /var/log/
su - -c "dbstart" >> /var/log/
echo "Done."
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/
echo "-------------------------------------------------" >> /var/log/
su - -c "lsnrctl start" >> /var/log/
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/
date +" %T %a %D : Finished." >> /var/log/
echo "-------------------------------------------------" >> /var/log/
touch /var/lock/subsys/

;;
stop)
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/
echo "-------------------------------------------------" >> /var/log/
su - -c "lsnrctl stop" >> /var/log/
echo "Done."
rm -f /var/lock/subsys/
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/
echo "-------------------------------------------------" >> /var/log/
su - -c "dbshut" >>/var/log/
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/
date +" %T %a %D : Finished." >> /var/log/
echo "-------------------------------------------------" >> /var/log/

;;
restart)
$0 stop
$0 start

;;
*)
echo "Usage: {start|stop|restart}"
exit 1
esac

將指令碼命名為,儲存在/etc/rc.d/init.d下
改變檔案屬性:chmod 755

注意:在windows下編輯此檔案時有DOS格式字元導致在下不能夠正常執行,建議用gedit 或用 vi編輯

3、建立服務連線:
系統啟動時啟動資料庫,我們需要以下連結∶
--------------------------------------------------------------------------------
$ ln -s ../init.d/ /etc/rc.d/rc2.d/S99
$ ln -s ../init.d/ /etc/rc.d/rc3.d/S99
$ ln -s ../init.d/ /etc/rc.d/rc5.d/S99 #rc4.d unused

--------------------------------------------------------------------------------

要在重新啟動時停止資料庫,我們需要以下連結∶

--------------------------------------------------------------------------------

$ ln -s ../init.d/ /etc/rc.d/rc0.d/K01 # 停止
$ ln -s ../init.d/ /etc/rc.d/rc6.d/K01 # 重新啟動

[@more@]

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

相關文章