Linux下oracle開機自啟動


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

orcl:/u01/app/oracle/product/12.1.0/dbhome_1:N
,改為 
orcl:/u01/app/oracle/product/12.1.0/dbhome_1:Y

 

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

su oracle -lc "/u01/app/oracle/product/12.1.0/dbhome_1/bin/lsnrctl start" 
su oracle -lc /u01/app/oracle/product/12.1.0/dbhome_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=/u01/app/oracle    #根據個人情況修改路徑
export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1
export ORACLE_SID=orcl          #改成自己的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 /u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart
找到下面的代碼:
ORACLE_HOME_LISTNER=$1
將其改為
ORACLE_HOME_LISTNER=$ORACLE_HOME

 同樣也修改dbshut腳本:

 

# vim
/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbshut 
找到下面的代碼: ORACLE_HOME_LISTNER=$1 將其改為 ORACLE_HOME_LISTNER=$ORACLE_HOME

6 將 oracle服務加入到系統服務

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

7、檢查是否生效:

chkconfig --list oracle

8、加入自啟動隊列

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM