ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 再谈用脚本自动启动关闭LINUX下的ORACLE数据库

再谈用脚本自动启动关闭LINUX下的ORACLE数据库

原创 Linux操作系统 作者:edwards63 时间:2010-07-08 08:47:20 0 删除 编辑

1、修改oratab文件,使数据库自动启动

#vi /etc/oratab

sid:/opt/app/ora10g/oracle/product/10.2.0/db_1:Y

2、修改dbstart、dbshut脚本,使之能够自动启动、关闭LISTENER

将dbstart与dbshut两个脚本中的ORACLE_HOME_LISTNER=$1改为

ORACLE_HOME_LISTNER=$ORACLE_HOME即可

3、编写启动脚本oracledb

#!/bin/bash

#

# oracledb This Starts/Stops the Oracle Server

#

# chkconfig: 2345 99 01

# description: oracledb starts/stops the Oracle server

#

#

# 

export ORACLE_SID=XXXX(对应你自己具体的数据库名)

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1

export ORACLE_OWNER=oracle

export PATH=$PATH:$ORACLE_HOME/bin

echo "Oracle Script. init.d"

if [  ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME  ]

then

  echo "Oracle startup: cannot start"

  exit 1

fi

start()

{

       # Oracle listener and instance startup

  echo -n "Starting Oracle: "

  su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbstart"

  su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/emctl start dbconsole"

  touch /var/lock/subsys/oracledb(必须与脚本同名)
  echo "OK"

}

Stop()

{

       # Oracle listener and instance shutdown

  echo -n "Shutdown Oracle: "

  su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/emctl stop dbconsole"

  su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbshut"

  rm -f /var/lock/subsys/oracledb(必须与脚本同名)

  echo "OK"

}

case "$1" in

start)

  start

  ;;

stop)

  stop

  ;;

reload|restart)

  $0 stop

  $0 start

;;

*)

  echo "Usage: `basename $0` start|stop|restart|reload"

  exit 1

esac

exit 0

4、添加服务

# cp oracledb /etc/rc.d/init.d/

# chmod +x /etc/rc.d/init.d/oracledb

# chkconfig --add oracledb

# chkconfig --list oracledb

oracledb        0:off  1:off  2:on  3:on  4:on  5:on  6:off

 

 

注意

一定要有这一句话

#chkconfig: 2345 99 01(定义启动和关闭数据库的运行级别Runlevel,一般启动为99最后一个启动,而关闭是01,第一个关闭)

有了这句参数后,LINUX在生成ORACLEDB服务后,将自动在对应的RCn.D目录中生成S99ORACLEDB(启动)、K01ORACLEDB(关闭),这样就可以在操作系统关闭和启动时自动关闭、启动ORACLE数据库了。

服务添加成功以后可以以root执行service oracledb start或者service oracledb stop来启动或停止服务,看脚本写得是否正确,如果能正常启动关闭数据库,则表示脚本正常。

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

请登录后发表评论 登录
全部评论

注册时间:2010-05-06

  • 博文量
    11
  • 访问量
    60669