關於linux oracle自啟動 [轉]

msdnchina發表於2011-07-04

關於oracle在linux系統下安裝後,如何在系統重啟的情況下讓服務自動啟動起來,網上有很多的教程和現成的指令碼,這裡只是個人工作中的一點經驗。

以redhat as4和oracle 10g為例。單機在安裝過程依照oracle官方的文件一步步下來,只要設定好引數、安裝好必要的包,一般不會出什麼問題。安裝好了以後系統重 啟,oracle重啟服務,網上很多人建議自己寫指令碼(其實指令碼也很簡單),這裡講的是用oracle本身的指令碼實現,當然不可避免最後還要寫一點點的。

1、配置dbstart和dbshut

在$ORACLE_HOME/bin中,有dbstart和dbshut這兩個指令碼,more dbstart看一下可以看到:

QUOTE:
#
# $Id: dbstart.sh.pp 11-may-2005.18:18:07 vikrkuma Exp $
# Copyright (c) 1991, 2005, Oracle. All rights reserved.
#

###################################
#
# usage: dbstart
#
# This is used to start ORACLE from /etc/rc(.local).
# It should ONLY be executed as part of the system boot procedure.
#
# This will start all databases listed in the oratab file
# whose third field is a "Y". If the third field is set to "Y" and
# there is no ORACLE_SID for an entry (the first field is a *),
# then this will ignore that entry.
#
# This requires that ASM ORACLE_SID's start with a +, and
# that non-ASM instance ORACLE_SID's do not start with a +.
#
# If ASM instances are to be started with this , it cannot
# be used inside an rc*.d directory, and should be invoked from
# rc.local only. Otherwise, the CSS service may not be available
# yet, and this will block init from completing the boot
# cycle.
#
# Note:
# Use ORACLE_TRACE=T for tracing this .
#
# The progress log for each instance bringup plus Error and Warning message[s]
# are logged in file $ORACLE_HOME/startup.log. The error messages related to
# instance bringup are also logged to syslog (system log module).
# The Listener log is located at $ORACLE_HOME_LISTNER/listener.log
......

可以看出這個指令碼是用來啟動oracle服務的,包括listener、instance、asm instances,並且可以放到/etc/rc(.local).,同樣dbshut也是起到關閉服務的作用。

配置系統使這個指令碼起作用:

1)、以root編輯/etc/oratab,類似 orcl:/u01/product/10.2.0/db_1:N 這種格式,其中orcl是你的ORACLE_SID,/u01/product/10.2.0/db_1是ORACLE_HOME,這裡需要把N改為Y, 即orcl:/u01/product/10.2.0/db_1:Y這樣。

2)、以oracle編輯$ORACLE_HOME/bin/dbstart,找到其中第78行:ORACLE_HOME_LISTNER=改為你自己的路徑,或者可以改成ORACLE_HOME_LISTNER=$ORACLE_HOME

儲存指令碼,以oracle使用者執行dbshut和dbstart看是否能關閉、啟動資料庫。如果不能,一般是引數設定,根據報錯找到對應位置更改。

2、把dbstart和dbshut加到redhat啟動服務中

經過上一步的配置,可以直接用dbstart命令啟動資料listener、instance、asm instances,但是還沒有啟動oracle10g的EM,ORACLE利用web頁面管理資料庫相當方便,也是10g的一個特色,所以應該一併啟動起該服務來。
QUOTE:
$ORACLE_HOME/bin/emctl start dbconsole

因此我們可以用rc.local或者redhat服務都可以實現要求的開機啟動。下面分別說一下:

1)、利用rc.local。直接把dbstart加到rc.local中,實現開機自動啟動。這裡需要注意的是必須以oracle啟動該指令碼。

用root編輯/etc/rc.local,新增下面一行:
QUOTE:
su - oracle -c "/u01/product/10.2.0/db_1/bin/dbstart"
su - oracle -c "/u01/product/10.2.0/db_1/bin/emctl start dbconsole"

這裡/u01/product/10.2.0/db_1需要替換成實際的ORACLE_HOME

儲存並退出後,reboot伺服器測試一下,可以看到,當系統啟動以後oracle監聽、例項和em都已經起來了

2)、如果我們不用rc.local,也可以加到redhat服務中。在/etc/rc.d/init.d中新增如下指令碼檔案,命名為oracle:
QUOTE:
#!/bin/sh
#chkconfig: 2345 99 01
#deion: ORACLE 10g Server

ORACLE_HOME=/u01/product/10.2.0/db_1

if [ ! -f $ORACLE_HOME/bin/dbstart ]
then
echo "ORACLE cannot start"
exit
fi

case "$1" in
'start')
echo "Starting Oracle Database..."
su - oracle -c "$ORACLE_HOME/bin/dbstart"
su - oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"
;;
'stop')
echo "Stoping Oracle Database"
su - oracle -c "$ORACLE_HOME/bin/emctl stop dbconsole"
su - oracle -c "$ORACLE_HOME/bin/dbshut"
;;
esac

注意其中兩行註釋,網上很多指令碼因為少了這兩行不能使服務自啟動:
QUOTE:
#chkconfig: 2345 99 01
#deion: ORACLE 10g Server

其中chkconfig:2345 99 01 是指指令碼將為執行級2、3、4、5啟動oracle 10g服務,啟動優先順序為99,關閉優先順序為01。

然後以root許可權:
QUOTE:
# cd /etc/rc2.d
# ln -s /etc/rc.d/init.d/oracle S99oracle
# chkconfig --list oracle
# chkconfig --level 2345 on

重啟系統,就可以在啟動的過程中看到 Starting oracle,因為我們設定的優先順序為99,一般是最後啟動。[OK]以後就可以了。因為要啟動emctl,可能有點慢,等待的時間要稍微長一點。

啟動以後可以以root執行oracle start或者oracle stop來啟動或停止服務。

【轉自】http://www.shineblog.com/user5/net-work/archives/2009/1022166.shtml

[@more@]

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

相關文章