ITPub博客

首页 > 数据库 > Oracle > DB - RHEL5 开机启动数据库脚本 - Oracle/DB2

DB - RHEL5 开机启动数据库脚本 - Oracle/DB2

Oracle 作者:sophiefan 时间:2013-06-28 19:51:05 0 删除 编辑
1. 修改Oracle系统配置文件:/etc/oratab,只有这样,Oracle 自带的dbstart和dbshut才能够发挥作用。

# vi /etc/oratab
orcl:/opt/oracle/102:Y

# Entries are of the form:
  $ORACLE_SID:$ORACLE_HOME::

1. 在 /etc/init.d/ 下创建文件oracle,内容如下:

/etc/init.d/oracle

#!/bin/sh
# 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=/home/oracle/app/oracle/product/11.2.0/dbhome_1
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

2。改变文件权限
# chmod 755 /etc/init.d/oracle

3. 添加服务

# chkconfig --add oracle
# chkconfig --level 345 oracle on

4. 需要在关机或重启机器之前停止数据库,做一下操作
# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle   //关机
# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle   //重启 

5. 使用方法
# service oracle start        //启动oracle
# service oracle stop        //关闭oracle
# service oracle restart     //重启oracle

6.补充:DB2开机启动
/etc/init.d/db2
#!/bin/sh

DB2_HOME=/opt/ibm/db2/V9.5
DB2_OWNER=db2inst1

if [ ! -f $DB2_HOME/adm/db2start ]
then
    echo "IBM DB2 startup: cannot start"
    exit
fi

case "$1" in
'start')
echo "starting IBM db2"
su - $DB2_OWNER -c $DB2_HOME/adm/db2start
echo "Start completed"
touch /var/lock/subsys/db2
;;

'stop')
echo -n "shutdown ibm db2"
su - $DB2_OWNER -c $DB2_HOME/adm/db2stop
echo "Shutdown Completed"
rm -f /var/lock/subsys/db2
;;

'restart')
$0 stop
$0 start
;;
esac

<!-- 正文结束 -->

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23721457/viewspace-1116552/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2010-04-14