Home > Database > Mysql Tutorial > Oracle设置(1)设置Oracle数据库为Linux系统服务

Oracle设置(1)设置Oracle数据库为Linux系统服务

WBOY
Release: 2016-06-07 15:30:42
Original
1131 people have browsed it

将Oracle数据库设为Linux系统服务,并使其能随系统启动和关闭数据库。 1. vi /etc/oratab 将最后一行改为Y. 只有改为Y,Oracle自带的dbstart与dbshut才能起作用。 如: xcldb:/u01/app/oracle/product/11.2.0/db_1:Y 2. 启动脚本文件 vi /etc/rc.d/init.d/orac

将Oracle数据库设为Linux系统服务,并使其能随系统启动和关闭数据库。

1. vi /etc/oratab

   将最后一行改为Y. 只有改为Y,Oracle自带的dbstart与dbshut才能起作用。

   如:

    xcldb:/u01/app/oracle/product/11.2.0/db_1:Y


2. 启动脚本文件

  vi /etc/rc.d/init.d/oracle

#!/bin/bash
  #chkconfig: 2345 20 80
  #description: Oracle dbstart/dbshut
  #/etc/rc.d/init.d/oracle
  export ORACLE_BASE=/u01/app/oracle
  export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
  ORACLE_OWNER=oracle
  LOGFILE=/var/log/oracle.log
  DATE=`date +%Y-%m-%d`
  echo "################################">>${LOGFILE}
  echo "## Run Oracle "${DATE} >> ${LOGFILE}
  if [! -f ${ORACLE_HOME}"/bin/dbstart" ] || [ ! -f ${ORACLE_HOME}"/bin/dbshut" ]; then
   echo "ERROR: Missing the script file "${ORACLE_HOME}"/bin/dbstart or "${ORACLE_HOME}"/bin/dbshut!">>${LOGFILE}
   echo "################################">>${LOGFILE}
   exit
  fi
  start(){
     touch /var/lock/subsys/oracle
      echo "###Startup oracle....."
   su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/lsnrctl start"
   su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/dbstart "${ORACLE_HOME}
   echo "###Done"
   #echo "###Run database control......"
   #su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/emctl start dbconsole"
   echo "###Done"
   echo "###startup oracle successful....."
  }
  stop(){
     #echo "###Stop database control......"
   #su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/emctl stop dbconsole"
   echo "###Done"
     echo "###Shutdown oracle------"
   su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/lsnrctl stop"
   su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/dbshut "${ORACLE_HOME}
   echo "###Done"
   rm -f /var/lock/subsys/oracle
   echo "###Shutdown oracle successful-------"
  }
 
  case "$1" in
  'start')
          start >> ${LOGFILE}
  ;;
  'stop')
          stop >> ${LOGFILE}
  ;;
  'restart')
  stop >> ${LOGFILE}
  start >> ${LOGFILE}
 ;;
  *)
  echo "Usage:`basename $0` start|stop|restart"
   exit 1
  esac
  echo "###Finished.">>${LOGFILE}
  echo "################################">>${LOGFILE}
  exit 0
Copy after login

3. 将脚本设置为可执行

  chmod a+x /etc/rc.d/init.d/oracle

  授权后,可手工用下面命令测试前面脚本的正确性:

   a. 启动

    /etc/rc.d/init.d/oracle start

   b. 停止

    /etc/rc.d/init.d/oracle stop

   c. 重启

    /etc/rc.d/init.d/oracle restart

4. 手工添加服务

 a.手工添加到chkconfig

    chkconfig --add /etc/rc.d/init.d/oracle

    b.查看oracle服务的开机启动级别

     chkconfig --list oracle 或

     chkconfig | grep oracle

    #c.修改oracle服务的开机启动级别

    #chkconfig --level 24 oracle off

    #chkconfig --level 35 oracle on

   注意:

     如果在启动脚本前不加下面两行,会出现"服务不支持 chkconfig"

  #chkconfig: 2345 20 80

    #description: Oracle dbstart/dbshut

5. 手工测试服务

  service oracle start

  service oracle stop

  service oracle restart

6.建立连接

  a.关机执行

  ln -s /etc/init.d/oracle /etc/rc.d/rc0.d/K01oracle

  b.重启执行

  ln -s /etc/init.d/oracle /etc/rc.d/rc6.d/K01oracle

  c.开机执行(Oracle10g以后能自启动了,可以省掉这步)

  ln -s /etc/init.d/oracle /etc/rc.d/rc3.d/S99oracle

  ln -s /etc/init.d/oracle /etc/rc.d/rc5.d/S99oracle

7.重启测试下

  reboot

  cat /var/log/oracle.log

 

备注:

  脚本中可以看到,start与stop时,弄了个/var/lock/subsys/oracle。

如果不增加这个文件的处理,在系统关闭时,你会发现stop并没有执行。

原因可以看看>


MAIL: xcl_168@aliyun.com

BLOG: http://blog.csdn.net/xcl168


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template