Redhat Linux上的Oracle 启动/关机 脚本

写RTC安装过程中插一篇,因为用到oracle,而且oracle是自己手工安装的,因此没有像其它商品化软件如Omega、Landmark一样会提供一个开机关机脚本,只有自己写一个。

1. 修改/etc/oratab

#
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
CLMDB:/oracle/ora/ora11g:Y

最后一行 ,最后一个字母,由 N 改为 Y

2. 测试dbstart,dbshut

首先要保证dbstart,dbshut命令能成功执行:
su - oracle
dbshut
dbstart
要能正常执行,没错误。

3. 编辑启动脚本

vi /etc/init.d/oracle

#!/bin/sh
# chkconfig: 35 99 01
# description: oracle

#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/oracle/ora/ora11g
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
echo "Done"

# Start the Listener:
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 - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
echo "Done."
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;

'stop')
# Stop the Oracle Listener:
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 - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle

# Stop the Oracle Database:
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 - $ORA_OWNER -c "$ORA_HOME/bin/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
;;
esac

注意:前三行,最好不要修改:

#!/bin/sh
# chkconfig: 35 99 01
# description: oracle

chkconfig: 35 99 01
是指在level 3和level 5时才启动oracle,
Level 3 是 Full multiuser mode
Level 5 是 X11图形模式
99 表示开机启动顺序,尽量在开机最后启动oracle,(当然要在使用oracle服务的其它服务之前启动)
01 是关机时执行脚本的顺序:设置成01是希望最先关闭oracle,然后再执行其它关机操作。
description: oracle
这一行也是给chkconfig命令管理使用的,最好和脚本文件名称都保持一致,这样不容易出错。
然后为脚本添加执行权限:
chmod 755 oracle

要把这个加本加到相应的执行级别,执行:
chkconfig –add oracle
查看:
chkconfig –list oracle
如果level 3、5没有 on,执行:
chkconifg –level 35 on oracle
脚本会自动链接到相应的位置,不用手工去链接:
/etc/rc0.d K01oracle -> ../init.d/oracle
/etc/rc3.d S99oracle -> ../init.d/oracle
/etc/rc5.d S99oracle -> ../init.d/oracle
/etc/rc6.d K01oracle -> ../init.d/oracle

正式在开机关机使用之前,先测试一下:
service oracle start
service oracle stop
service oracle restart

4. 关注 /var/lock/subsys 的问题

在 /var/lock/subsys目录建一个和脚本名一样的文件,
touch /var/lock/subsys/oracle
这样在关机的时候,关机脚本才会执行,如果没有这个文件,
则手动执行/etc//rc0.d/oracle stop是正常,但是关机时又不能执行。

这一步要配合脚本,有的直接在脚本中做了这一步,要注意的是:如果修改了文件名、服务名或脚本内容,要保持 /var/lock/subsys/ 目录下的文件和这些名字的一致性。

猜你喜欢

转载自blog.csdn.net/petrosofts/article/details/80103214