Redhat Linux AS4(AS5)下oracle10g自啟動(dòng)腳本設(shè)置
以redhat as4和oracle 10g為例。單機(jī)在安裝過程依照oracle官方的文檔一步步下來,只要設(shè)置好 參數(shù)、安裝好必要的包,一般不會(huì)出什么問題。安裝好了以后系統(tǒng)重啟,oracle重啟服務(wù),網(wǎng)上很多人建議自己寫腳本(其實(shí)腳本也很簡(jiǎn)單),這里講的是用 oracle本身的腳本實(shí)現(xiàn),當(dāng)然不可避免最后還要寫一點(diǎn)點(diǎn)的。
1、配置dbstart和dbshut
在$ORACLE_HOME/bin 中,有dbstart和dbshut這兩個(gè)腳本,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
......
可以看出這個(gè)腳本是用來啟動(dòng)oracle服務(wù)的,包括listener、instance、asm instances,并且可以放到/etc/rc(.local).,同樣dbshut也是起到關(guān)閉服務(wù)的作用。
配置系統(tǒng)使這個(gè)腳本起作 用:
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用戶運(yùn)行dbshut和dbstart看是 否能關(guān)閉、啟動(dòng)數(shù)據(jù)庫。如 果不能,一般是參數(shù)設(shè)置,根據(jù)報(bào)錯(cuò)找到對(duì)應(yīng)位置更改。
2、 把dbstart和dbshut加到redhat啟動(dòng)服務(wù)中
經(jīng)過上一步的配置,可以直接用 dbstart命令啟動(dòng)數(shù)據(jù)listener、instance、asm instances,但是還沒有啟動(dòng)oracle10g的EM,ORACLE利用web頁 面管理數(shù)據(jù)庫相當(dāng)方便,也 是10g的一個(gè)特色,所以應(yīng)該一并啟動(dòng)起該服務(wù)來。
$ORACLE_HOME/bin/emctl start dbconsole
因此我們可以用rc.local或者redhat服務(wù)都可以實(shí)現(xiàn)要求的開機(jī)啟動(dòng)。下面分別說一下:
1)、利用 rc.local。直接把dbstart加到rc.local中,實(shí)現(xiàn)開機(jī)自動(dòng)啟動(dòng)。這里需要注意的是必須以oracle啟動(dòng)該腳本。
用 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需要替換成實(shí)際的ORACLE_HOME
保存并退出后,reboot服務(wù)器測(cè)試一下,可以看到,當(dāng)系統(tǒng)啟動(dòng)以后oracle監(jiān)聽、實(shí)例 和em都已經(jīng)起來了
2)、如果我們不用rc.local,也可以加到redhat服務(wù)中。在/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
注意其中兩行注釋,網(wǎng)上很多腳本因?yàn)樯倭诉@兩行不能使服務(wù)自啟動(dòng):
#chkconfig: 2345 99 01
#description: ORACLE 10g Server
其中chkconfig:2345 99 01 是指腳本將為運(yùn)行級(jí)2、3、4、5啟動(dòng)oracle 10g服務(wù),啟動(dòng)優(yōu)先級(jí)為99,關(guān)閉優(yōu)先級(jí)為01。
然后以root權(quán)限:
# cd /etc/rc2.d
# ln -s /etc/rc.d/init.d/oracle S99oracle
# chkconfig --list oracle
# chkconfig --level 2345 oracle on
重啟系統(tǒng),就可以在啟動(dòng)的過程中看到 Starting oracle,因?yàn)槲覀冊(cè)O(shè)置的優(yōu)先級(jí)為99,一般是最后啟動(dòng)。[OK]以后就可以了。因?yàn)橐獑?dòng)emctl,可能有點(diǎn)慢,等待的時(shí)間要稍微長一點(diǎn)。
啟 動(dòng)以后可以以root執(zhí)行oracle start或者oracle stop來啟動(dòng)或停止服務(wù)。
posted on 2010-10-27 19:46 風(fēng) 閱讀(527) 評(píng)論(0) 編輯 收藏 所屬分類: Oracle