linux平臺下監聽器和Oracle的自動啟動與停止

jinqibingl發表於2012-10-04

linux平臺下監聽器和Oracle的自動啟動與停止  

1、 修改Oracle系統配置檔案/etc/oratab
/etc/oratab 格式為: SID:ORACLE_HOME:AUTO
把AUTO域設定為Y(大寫),只有這樣,oracle 自帶的dbstart和dbshut才能夠發揮作用。我的為:
ora9i:/home/oracle/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/oracle
date +" %T %a %D : Starting Oracle Databasee as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "dbstart" >> /var/log/oracle
echo "Done."
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 - oracle -c "lsnrctl start" >> /var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle


;;
stop)
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 - oracle -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
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 - oracle -c "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


;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac
將指令碼命名為oracle,儲存在/etc/rc.d/init.d下
改變檔案屬性:chmod 755 oracle
注意:在windows下編輯此檔案時有DOS格式字元導致在linux下不能夠正常執行,建議用gedit 或用 vi編輯

3、建立服務連線:
系統啟動時啟動資料庫,我們需要以下連結∶
--------------------------------------------------------------------------------
$ ln -s ../init.d/oracle /etc/rc.d/rc2.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc3.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc5.d/S99oracle #rc4.d unused
--------------------------------------------------------------------------------
要在重新啟動時停止資料庫,我們需要以下連結∶
--------------------------------------------------------------------------------
$ ln -s ../init.d/oracle /etc/rc.d/rc0.d/K01oracle # 停止
$ ln -s ../init.d/oracle /etc/rc.d/rc6.d/K01oracle # 重新啟動

4、注意,資料庫版本,估計低版本的不行,因為需要oracle資料庫帶有DBSTART和DBSHUT指令碼。

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

相關文章