環境說明:
ORACLE_SID= orcl
ORACLE_BASE=/oracle/app/oracle
ORACLE_HOME=/oracle/app/oracle/product/11.2.0/dbhome_1
(以下操作都用root執行)
1. 修改Oracle系統配置檔案:/etc/oratab,隻有這樣,Oracle 自帶的dbstart和dbshut才能夠發揮作用。
# vi /etc/oratab , 将 ORACLE_SID:ORACLE_HOME:Y 相應子產品替換 ,如下
orcl:/oracle/app/oracle/product/11.2.0/dbhome_1:Y
2. 在 /etc/init.d/ 下建立檔案oracle,内容如下: (指定該環境的ORA_HOME=XX 路徑)
#!/bin/bash
#chkconfig:345 61 61
#description:Apache
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/oracle/app/oracle/product/11.2.0/dbhome_1
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 Databases as part of system up." >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
echo "Done"
# Start the Listener:
echo "Starting Oracle Listeners ... "
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
echo "Done."
date +" %T %a %D : Finished." >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
rm -f /var/lock/subsys/oracle
# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo ""
'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
# service oracle restart //重新開機oracle
7. 測試
文章可以轉載,必須以連結形式标明出處。
本文轉自 張沖andy 部落格園部落格,原文連結: http://www.cnblogs.com/andy6/p/5723435.html ,如需轉載請自行聯系原作者