修改Oracle系统配置文件/etc/oratab
/etc/oratab 格式为: SID:ORACLE_HOME:AUTO
把AUTO域设置为Y(大写),只有这样,oracle 自带的dbstart和dbshut才能够发挥作用
我在/etc/rc.local文件中加入
su - oracle -c "lsnrctl start"
su - oracle -c "dbstart" 也可以这样(
创建一个脚本脚本内容如下:
#!/bin/bash
su - oracle -c "lsnrctl <<EOF
start
exit
EOF"
su - oracle -c "sqlplus /nolog <<EOF
connect / as sysdba
startup
exit
EOF"
或是写成
su - oracle -c "lsnrctl start"
su - oracle -c "dbstart"。保存脚本,为脚本分配执行权限:chmod 755 脚本名.之后在
/etc/rc.d/rc.local脚本中加入 你创建的脚本所有在路径,如:
/root/autooracle 其中autooracle为脚本名。
如果你的服务器上就一个实例,可以不用执行dbstart脚本,试试这样
) 聚体还是要自己试过才知道..........
利用这个方法启动oracle:。下面是我在网上搜到的内容,希望对大家有帮,我本人并没有按照下面脚本实现
1、 修改Oracle系统配置文件/etc/oratab
/etc/oratab 格式为: SID:ORACLE_HOME:AUTO
把AUTO域设置为Y(大写),只有这样,oracle 自带的dbstart和dbshut才能够发挥作用。如:
ora9i:/home/oracle/ora/products/9.2.0:Y
2、 编写服务脚本:
如下
#!/bin/bash
#
#################FUNCTION#############
#
# AutoStart Oracle and listener
# AutoStop Oracle and listener
#
case "$1" in
start)
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databasee as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "dbstart" >> /var/log/oracle
echo "Done."
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "lsnrctl start" >> /var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
stop)
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac
将脚本命名为oracle,保存在/etc/rc.d/init.d下
改变文件属性:chmod 755 oracle
注意:在windows下编辑此文件时有DOS格式字符导致在linux下不能够正常运行,建议用gedit 或用 vi编辑
3、建立服务连接:
系统启动时启动数据库,我们需要以下连结∶
--------------------------------------------------------------------------------
$pwd
/etc/rc.d/init.d/oracle
$ 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 # 重新启动
重启服务器,检查/var/log/oracle日志文件,发现:
...
Can't find init file for Database "SID".
...
的错误,修改dbstart脚本:
some bugs in dbstart when you using spfile in oracle9i
You can do the following step to solve it:
code:
- edit the dbstart script
- add the following line:
SPFILE=${ORACLE_HOME}/dbs/spfile${ORACLE_SID}.ora
after this line:
PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora
- change:
if [ -f $PFILE ] ; then
to:
if [ -f $PFILE -o -f $SPFILE ] ; then
说明,在我安装的oracle9i,并没有数据库的init文件(PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora),所有提示的信息
现在增加了SPFILE=${ORACLE_HOME}/dbs/spfile${ORACLE_SID}.ora,代替init file.
重启后,设置的数据库实例自动启动.
另一种方法是编写如下脚本,加到rc.local文件中
#!/bin/bash
#
# oracle This shell script takes care of starting and stopping
#
# chkconfig: - 90 10
# description: Oracle database server.
# processname: oracle
ORA_HOME=/home/oracle
ORA_OWNER=oracle
prog="Oracle"
# Source function library.
. /etc/rc.d/init.d/functions
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
start(){
su - $ORA_OWNER -c $ORA_HOME/bin/dbstart >/dev/null 2>&1 &
ret=$?
if [ $ret -eq 0 ]; then
action $"Starting $prog: " /bin/true
else
action $"Starting $prog: " /bin/false
fi
[ $ret -eq 0 ] && touch /var/lock/subsys/oracled
return $ret
}
stop(){
su - $ORA_OWNER -c $ORA_HOME/bin/dbshut >/dev/null 2>&1
ret=$?
if [ $ret -eq 0 ]; then
action $"Stopping $prog: " /bin/true
else
action $"Stopping $prog: " /bin/false
fi
[ $ret -eq 0 ] && rm -f /var/lock/subsys/oracled
return $ret
}
restart(){
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
condrestart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac