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 # 重新启动