ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Orale自动启动以及关闭脚本_linux

Orale自动启动以及关闭脚本_linux

原创 Linux操作系统 作者:andyann 时间:2011-05-23 15:10:29 0 删除 编辑
目的
--- 能够实现开机启动Oracle
--- 重启、关闭服务器的时候能先关闭
--- Oracle可以用service命令启、停Oracle

1. 修改Oracle系统配置文件:/etc/oratab //oratab格式:SID:ORACLE_HOME:AUTO
# vi /etc/oratab
orcl:/Oracle/app/product/11.1.0/db:Y

2. 在 /etc/init.d/ 下创建文件oracle,11G以前编写内容如下:

#!/bin/bash
#chkconfig: 35 99 01
#description: Oracle auto start-stop-restart script
#
#Set ORA_HOME to be equivalent to the $ORACLE_HOME from which you wish to execute dbstart and dbshutdown
#
#Set ORA_OWNER to the user id of the owner of the Oracle database in ORA_HOME.

ORA_HOME=/Oracle/app/product/11.1.0/db
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 Databasee 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

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

4. 添加服务
# chkconfig --level 35 oracle on

5. 需要在重新启动时停止数据库,做一下操作
# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle   //关机
# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle   //重启

6. 使用方法
# service oracle start //启动oracle
# service oracle stop //关闭oracle



11G以后脚本:

修改dbstart和dbshut脚本
行:ORACLE_HOME_LISTNER=$1修改为:
ORACLE_HOME_LISTNER=$ORACLE_HOME

#!/bin/bash
#chkconfig: 35 99 01
#description:Startup Script. for oracle Databases
#/etc/rc.d/init.d/oradbstart
export ORACLE_BASE=/Oracle/app/
export ORACLE_HOME=/Oracle/app/product/11.1.0/db
export ORACLE_SID=pir
export PATH=$PATH:$ORACLE_HOME/bin

case"$1"in
start)
echo "-----startuporacle-----" >> /var/log/oracle11log
su oracle -c $ORACLE_HOME/bin/dbstart
touch /var/lock/subsys/oracle11
echo "-----startuporaclesuccessful-----" >> /var/log/oracle11log
echo "OK"
;;
stop)
echo "-----shutdwnoracle-----" >> /var/log/oracle11log
suoracle-c$ORACLE_HOME/bin/dbshut
rm -f /var/lock/subsys/oracle11
echo "-----shutdownoraclesuccessful-----" >> /var/log/oracle11log
echo "OK"
;;
*)
echo "Usage:'basename$0'start|stop"
exit1
esac
exit0

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

上一篇: REDO日志管理
请登录后发表评论 登录
全部评论

注册时间:2011-03-24

  • 博文量
    25
  • 访问量
    89325