1. 程式人生 > >Linux下oracle開機自啟動

Linux下oracle開機自啟動

case chm autorun art parameter bin $1 sid path

1、以root身份登錄到linux系統,編輯/etc/oratab文件,找到

testsid:/data/oracle/product/11.2.0/db_1:N 
,改為 
testsid:/data/oracle/product/11.2.0/db_1:Y 

 

2、配置/etc/rc.d/rc.local,添加以下腳本:

su oracle -lc "/data/oracle/product/11.2.0/db_1/bin/lsnrctl start"
su oracle -lc /data/oracle/product/11.2.0/db_1/bin/dbstart

 

3、在/etc/init.d創建oracle服務啟動,註意修改oracle路徑:

vim /etc/init.d/oracle

#!/bin/sh
# chkconfig: 345 61 61
# description: Oracle 11g R2 AutoRun Servimces
# /etc/init.d/oracle
#
# Run-level Startup script for the Oracle Instance, Listener, and
# Web Interface
export ORACLE_BASE=/data/oracle    #根據個人情況修改路徑
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=testsid          #改成自己的ORACLE_SID:testsid
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNR="oracle"
# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbstart
echo "Oracle Start Succesful!OK."
;;
stop)
# Oracle listener and instance shutdown
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbshut
echo "Oracle Stop Succesful!OK."
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo $"Usage: `basename $0` {start|stop|reload|reload}"
exit 1
esac
exit 0

4、將oracle腳本文件賦予執行權限
說明:/etc/init.d -> /etc/rc.d/init.d 其中/etc/init.d為link文件,所以執行哪個目錄下的Oracle腳本都應該可以。

 cd /etc/rc.d/init.d
 chmod +x oracle

  

5、修改dbstart和dbshut啟動關閉腳本,使其啟動數據庫的同時也自動啟動監聽器(即啟動數據庫時啟動監聽器,停止數據庫時停止監聽器):

# vim /data/oracle/product/11.2.0/db_1/bin/dbstart
找到下面的代碼:
ORACLE_HOME_LISTNER=$1
將其改為
ORACLE_HOME_LISTNER=$ORACLE_HOME

 同樣也修改dbshut腳本:

# vim /data/oracle/product/11.2.0/db_1/bin/dbshut
找到下面的代碼:
ORACLE_HOME_LISTNER=$1
將其改為
ORACLE_HOME_LISTNER=$ORACLE_HOME

6、加入自啟動隊列

ln –s /etc/rc.d/init.d/oracle /etc/rc0.d/K61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc2.d/S61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc3.d/S61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc4.d/S61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc6.d/K61oracle

 將 oracle服務加入到系統服務

chkconfig --level 234 oracle on
chkconfig --add oracle

7、檢查是否生效:

chkconfig --list oracle

Linux下oracle開機自啟動