oracle10g for linux 4 自動啓動及腳本

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

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


1、配置dbstart和dbshut

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


#

# $Id: dbstart.sh.pp 11-may-2005.18:18:07 vikrkuma Exp $

# Copyright (c) 1991, 2005, Oracle. All rights reserved.

#


###################################

#

# usage: dbstart

#

# This script is used to start ORACLE from /etc/rc(.local).

# It should ONLY be executed as part of the system boot procedure.

#

# This script 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 script will ignore that entry.

#

# This script 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 script, 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 script will block init from completing the boot

# cycle.

#

# Note:

# Use ORACLE_TRACE=T for tracing this script.

#

# 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的一個特色,所以應該一併啓動起該服務來。

$ORACLE_HOME/bin/emctl start dbconsole

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


1)、利用rc.local。直接把dbstart加到rc.local中,實現開機自動啓動。這裏需要注意的是必須以oracle啓動該腳本。

用root編輯/etc/rc.local,添加下面一行:

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:

#!/bin/sh

#chkconfig: 2345 99 01

#description: 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


注意其中兩行註釋,網上很多腳本因爲少了這兩行不能使服務自啓動:

#chkconfig: 2345 99 01

#description: ORACLE 10g Server

其中chkconfig:2345 99 01 是指腳本將爲運行級2、3、4、5啓動oracle 10g服務,啓動優先級爲99,關閉優先級爲01。


然後以root權限:

# cd /etc/rc2.d

# chkconfig --add oracle

# chkconfig --list oracle

# chkconfig oracle 2345 on

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

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

轉於 http://blog.pconline.com.cn/article/221507.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章