oracle 隨系統開啟,自動啟動

lovehewenyu發表於2012-07-26

Centos5.6 oracle 10g開機啟動資料庫配置

 

系統

資料庫版本

實現功能開機自動啟動ORACLE

Centos5.6

10.2.0.1

很複雜,今天來學習

 

1 修改 /etc/oratab

 doudou:/opt/oracle/product/10.2.0:Y

2、修改$ORACLE_HOME/bin/dbstart指令碼中的一處錯誤

         ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle修改成ORACLE_HOME_LISTNER=$ORACLE_HOME

3 建立database指令碼

vi /etc/rc.d/init.d/database

#!/bin/bash

# chkconfig: 35 85 90

##(這裡跟我們chkconfig --add database有關)(這裡很重要如果你不設定,就不能新增chkconfig,不能自動啟動資料庫了。)##
# description: Oracle auto start-stop script.
# AUTH:seker
 
. /etc/init.d/functions

start(){
 if ps aux | grep ora_ | grep -v grep &>/dev/null
 then
  echo -n $"cannot start database: database is already running."
  failure $"cannot start database: database is already running."
  echo
  exit 1
 else
  echo -n $"Starting Database: "
  daemon su - $ORA_OWNER -c "dbstart" && touch /var/lock/subsys/`basename $0`
  echo
 fi
 
}
stop(){
 if ps aux | grep ora_ | grep -v grep &>/dev/null
 then
  echo -n $"Stoping Database: "
  daemon su - $ORA_OWNER -c "dbshut" && rm -f /var/lock/subsys/`basename $0`
  echo
 else
  echo -n $"cannot stop database:Database is not already running."
  failure $"cannot stop database:Database is not already running."
  echo
  exit 1
 fi
}

ORA_OWNER=oracle
case "$1" in
    start)
 start
 ;;
    stop)
 stop
 ;;
    emstart)
 su - $ORA_OWNER  -c 'emctl status dbconsole &>/dev/null && echo "OEM is already running" || emctl start dbconsole'
 ;;
    emstop)
 su - $ORA_OWNER  -c 'emctl status dbconsole &>/dev/null && emctl stop dbconsole || echo "OEM is not running"'
 ;;
    isqlstart)
 su - $ORA_OWNER  -c  'ps aux | grep 'isqlplus/config/server.xml' | grep -v grep &>/dev/null || isqlplusctl start'
 ;;
    isqlstop)
 su - $ORA_OWNER  -c  'ps aux | grep 'isqlplus/config/server.xml' | grep -v grep &>/dev/null && isqlplusctl stop ||  echo "isqlplus is not running"'
 ;;
    lsnstart)
 su - $ORA_OWNER  -c  'lsnrctl status &>/dev/null && echo "listen is already running" || lsnrctl start &>/dev/null'
 ;;
    lsnstop)
 su - $ORA_OWNER  -c  'lsnrctl status &>/dev/null && lsnrctl stop &>/dev/null || echo "lsnrctl is not already running"'
 ;;
 *)
 echo "USAGE: $0 {start|stop|lsnstart|lsnstop|emstart|emstop|isqlstart|isqlstop}"
 echo -e "\tstart     : database start"
 echo -e "\tstop      : database stop"
 echo -e "\tlsnstart  : listen start"
 echo -e "\tlsnstop   : listen stop"
 echo -e "\temstart   : OEM start"
 echo -e "\temstop    : OEM stop"
 echo -e "\tisqlstart : isqlplus start"
 echo -e "\tisqlstop  : isqlplus stop"
esac

 

4 修改執行許可權chmod 755 ora

chmod 755 /etc/rc.d/init.d/database

5 修改chkconfig database on 開機自動啟動

chkconfig --add database

chkconfig --list database

chkconfig database on

 

6、使用service是否可以開啟,關閉資料庫

      service database start

      service database stop

7reboot

OK,開機自動啟動資料庫了!

 

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

相關文章