以redhat 和oracle g为例安装过程参考官方文档以下是实现oracle自启动的方法
配置dbstart和dbshut
在$ORACLE_HOME/bin中有dbstart和dbshut这两个脚本more dbstart看一下可以看到
QUOTE:
#
# $Id: dbstartshpp may:: vikrkuma Exp $
# Copyright (c) Oracle All rights reserved
#
###################################
#
# usage: dbstart
#
# This is used to start ORACLE from /etc/rc(local)
# It should ONLY be executed as part of the system boot procedure
#
# This 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 will ignore that entry
#
# This requires that ASM ORACLE_SIDs start with a + and
# that nonASM instance ORACLE_SIDs do not start with a +
#
# If ASM instances are to be started with this it cannot
# be used inside an rc*d directory and should be invoked from
# rclocal only Otherwise the CSS service may not be available
# yet and this will block init from completing the boot
# cycle
#
# Note:
# Use ORACLE_TRACE=T for tracing this
#
# The progress log for each instance bringup plus Error and Warning message[s]
# are logged in file $ORACLE_HOME/startuplog The error messages related to
# instance bringup are also logged to syslog (system log module)
# The Listener log is located at $ORACLE_HOME_LISTNER/listenerlog
可以看出这个脚本是用来启动oracle服务的包括listenerinstanceasm instances并且可以放到/etc/rc(local)同样dbshut也是起到关闭服务的作用
配置系统使这个脚本起作用
)以root编辑/etc/oratab类似 orcl:/u/product//db_:N 这种格式其中orcl是你的ORACLE_SID/u/product//db_是ORACLE_HOME这里需要把N改为Y即orcl:/u/product//db_:Y这样
)以oracle编辑$ORACLE_HOME/bin/dbstart找到其中第行:ORACLE_HOME_LISTNER=改为你自己的路径或者可以改成ORACLE_HOME_LISTNER=$ORACLE_HOME
保存脚本以oracle用户运行dbshut和dbstart看是否能关闭启动数据库如果不能一般是参数设置根据报错找到对应位置更改
把dbstart和dbshut加到redhat启动服务中
经过上一步的配置可以直接用dbstart命令启动数据listenerinstanceasm instances但是还没有启动oracleg的EMORACLE利用web页面管理数据库相当方便也是g的一个特色所以应该一并启动起该服务来
QUOTE:
$ORACLE_HOME/bin/emctl start dbconsole
因此我们可以用rclocal或者redhat服务都可以实现要求的开机启动下面分别说一下
)利用rclocal直接把dbstart加到rclocal中实现开机自动启动这里需要注意的是必须以oracle启动该脚本
用root编辑/etc/rclocal添加下面一行
QUOTE:
su oracle c /u/product//db_/bin/dbstart
su oracle c /u/product//db_/bin/emctl start dbconsole
这里/u/product//db_需要替换成实际的ORACLE_HOME
保存并退出后reboot服务器测试一下可以看到当系统启动以后oracle监听实例和em都已经起来了
)如果我们不用rclocal也可以加到redhat服务中在/etc/rcd/initd中添加如下脚本文件命名为oracle
QUOTE:
#!/bin/sh
#chkconfig:
#deion: ORACLE g Server
ORACLE_HOME=/u/product//db_
if [ ! f $ORACLE_HOME/bin/dbstart ]
then
echo ORACLE cannot start
exit
fi
case $ 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
注意其中两行注释网上很多脚本因为少了这两行不能使服务自启动
QUOTE:
#chkconfig:
#deion: ORACLE g Server
其中chkconfig 是指脚本将为运行级启动oracle g服务启动优先级为关闭优先级为
然后以root权限:
QUOTE:
# cd /etc/rcd
# ln s /etc/rcd/initd/oracle Soracle
# chkconfig list oracle
# chkconfig level on
重启系统就可以在启动的过程中看到 Starting oracle因为我们设置的优先级为一般是最后启动[OK]以后就可以了因为要启动emctl可能有点慢等待的时间要稍微长一点
启动以后可以以root执行oracle start或者oracle stop来启动或停止服务