Centos 6.4下Oracle启动&停止脚本

来源:互联网 发布:tim kaine知乎 编辑:程序博客网 时间:2024/05/20 02:26

1. 修改Oracle系统配置文件:/etc/oratab,只有这样,Oracle 自带的dbstart和dbshut才能够发挥作用。

<span style="font-size:14px;"># 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.###orcl:/trs/oracle/112:Norcl:/trs/oracle/112:Y</span>


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

#!/bin/sh# chkconfig: 35 80 10# description: Oracle auto start-stop script.## 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=/trs/oracle/112ORA_OWNER=oracleif [ ! -f $ORA_HOME/bin/dbstart ]then    echo "Oracle startup: cannot start"    exitficase "$1" in'start')# Start the Oracle databases:echo "Starting Oracle Databases ... "echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oraclesu - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracleecho "Done"# Start the Listener:echo "Starting Oracle Listeners ... "echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oraclesu - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracleecho "Done."echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Finished." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oracletouch /var/lock/subsys/oracle;;'stop')# Stop the Oracle Listener:echo "Stoping Oracle Listeners ... "echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oraclesu - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracleecho "Done."rm -f /var/lock/subsys/oracle# Stop the Oracle Database:echo "Stoping Oracle Databases ... "echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracleecho "-------------------------------------------------" >> /var/log/oraclesu - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracleecho "Done."echo ""echo "-------------------------------------------------" >> /var/log/oracledate +" %T %a %D : Finished." >> /var/log/oracleecho "-------------------------------------------------" >> /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
# service oracle restart     //重启oracle



0 0