以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
# ln -s /etc/rc.d/init.d/oracle S99oracle
# chkconfig --list oracle
# chkconfig --level 2345 oracle on
重啟系統,就可以在啟動的過程中看到 Starting oracle,因為我們設置的優先級為99,一般是最后啟動。[OK]以后就可以了。因為要啟動emctl,可能有點慢,等待的時間要稍微長一點。
啟 動以后可以以root執行oracle start或者oracle stop來啟動或停止服務。