1、 修改Oracle系統設定檔,把N改成Y:
sudo vi /etc/oratab
orcl:/oracle/oracle_home:Y
blogs:/oracle/oracle_home:Y
說明:
/etc/oratab 格式為: SID:ORACLE_HOME:AUTO
把N設定為Y(大寫),只有這樣,oracle 內建的dbstart和dbshut才能夠發揮作用。
2、 以root登入編寫服務指令碼:
如下#!/bin/bash
#
# chkconfig: 35 95 1
# description: init script to start/stop oracle database 10g, TNS listener, EMS, isqlplus
#
#
#
# match these values to your environment:
export ORACLE_BASE=/oracle/oracle_home
export ORACLE_HOME=$ORACLE_BASE
# export ORACLE_TERM=xterm
export PATH=$PATH:$ORACLE_HOME/bin
#export NLS_LANG='american_america.ZHS16GBK'
export ORACLE_SID=esales
# export DISPLAY=localhost:0
export ORACLE_USER=oracle
# see how we are called:
case $1 in
start)
su - "$ORACLE_USER"<<EOO
lsnrctl start
sqlplus /nolog<<EOS
connect / as sysdba
startup
EOS
emctl start dbconsole
isqlplusctl start
EOO
;;
stop)
su - "$ORACLE_USER"<<EOO
lsnrctl stop
sqlplus /nolog<<EOS
connect / as sysdba
shutdown immediate
EOS
emctl stop dbconsole
isqlplusctl stop
EOO
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
;;
esac
將指令碼命名為oracle,儲存在/etc/rc.d/init.d下
改變檔案屬性:chmod 755 oracle
3、建立服務串連:
系統啟動時啟動資料庫,我們需要以下連結∶
--------------------------------------------------------------------------------
$ ln -s ../init.d/oracle /etc/rc.d/rc2.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc3.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc5.d/S99oracle #rc4.d unused
--------------------------------------------------------------------------------
要在重新啟動時停止資料庫,我們需要以下連結∶
--------------------------------------------------------------------------------
$ ln -s ../init.d/oracle /etc/rc.d/rc0.d/K01oracle # 停止
$ ln -s ../init.d/oracle /etc/rc.d/rc6.d/K01oracle # 重新啟動