Linux上Oracle自動啟停方案

來源:互聯網
上載者:User

環境

CentOS 6 x86_64, Oracle 11g R2

方案

Oracle在$ORACLE_HOME/bin目錄下提供了dbstart和dbshut兩個指令碼來啟動和停止Oracle。dbstart指令碼將啟動指定的資料庫執行個體和Listener。

首先,修改/etc/oratab,把要自動啟動的執行個體對應的啟動標誌設定為"Y"。

ORA01:/home/oracle/app/oracle/product/11.2.0/dbhome_1:Y

然後,建立/etc/init.d/dbora指令碼,內容如下:

#!/bin/bash                                                                                                                                                                                                 

### BEGIN INIT INFO

# Provides: Oracle

# Required-Start: $local_fs $network $remote_fs

# Required-Stop: $local_fs $network $remote_fs

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: start and stop oracle

# Description: Oracle is a damn RDBMS

### END INIT INFO

#

# Change the value of ORACLE_HOME to specify the correct Oracle home

# directory for your installation.

ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1/

#

# Change the value of ORACLE_OWNER to the login name of the

# oracle owner at your site.

#

ORACLE_OWNER="oracle"

LOCK_FILE="/var/lock/subsys/dbora"

case $1 in

'start')

    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME &"

    touch $LOCK_FILE

    ;;

'stop')

    su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME &"

    rm -f $LOCK_FILE

    ;;

*)

    echo "usage: $0 {start|stop}"

    exit

    ;;

esac

exit


給dbora添加執行許可權:

chmod a+x /etc/init.d/dbora

將dbora添加到自啟動服務:

chmod a+x /etc/init.d/dbora

這樣就可以將Oracle作為系統服務自動啟停了。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.