Oracle自启动与自关闭的配置方法(不同操作系统)




  • 一、Linux平台
    网上很多朋友还在问这个问题,于是写出来(全以root用户执行):
    1. 修改/etc/oratab ,格式 ORACLE_SID:ORACLE_HOME:Y
    [root@OracleCX oracle]# cat /etc/oratab
    #
    # 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.
    #
    #
    nms:/oracle/product/11.2.0/dbhome_1:Y
    nms10:/oracle10/product/10.2.0/db_1:Y
     
    2.编辑开机自启动脚本,路径为/etc/rc.d/init.d/下面
    [root@OracleCX init.d]# vi /etc/rc.d/init.d/oracle
    #chkconfig:2345 90 00     #这两行一定要,这样才能用chkconfig进行管理
    #description:oracle            #这两行一定要,这样才能用chkconfig进行管理
    #!/bin/bash
    case "$1" in
    start)
    su oracle -c '/oracle/product/11.2.0/dbhome_1/bin/dbstart /oracle/product/11.2.0/dbhome_1'  #一定不要用变量的形式,改成绝对路径
    ;;
    stop)
    su oracle -c '/oracle/product/11.2.0/dbhome_1/bin/dbshut /oracle/product/11.2.0/dbhome_1'
    ;;
    esac

    说明:/etc/init.d/目录下的服务文件都有一些共同点,那就是有一行类似# chkconfig: 2345 10 90这样的内容,就和第一行#! /bin/bash一样,是必需的,而不是我们平时所说的注释。
    三栏表示的意思是:不同的运行级别、启动顺序、关闭顺序。也就是说在/etc/rc.d/rcN.d/(N为2、3、4、5)下会有S10开头的对应文件和/etc/rc.d/rcN.d/(N为0、1、6)下以K90开头的对应文件。这个我们可以查看前面有关运行级别的相关信息。

    3.修改oracle脚本的权限为可执行的
    [root@OracleCX init.d]# chmod 755 oracle
     
    4.然后将这个脚本加到相应的执行级别
    [root@OracleCX init.d]# chkconfig --add oracle
    [root@OracleCX init.d]# chkconfig --level 235 oracle on
     
    5.确认相应的/etc/rc.d/rcX.d目录是否有K和S开头的链接,不需要手动增加链接,第4步的命令执行以后,会自动在相应级别下生成Sxxx启动文件(和rc0.d下面 的Kxxxxx关闭文件)(其他级别的Kxxxxx关闭文件会在命令执行后自动生成)。
     
    6.在/var/lock/subsys目录建一个和脚本名一样的文件,如touch /var/lock/subsys/ora(这条语句要加到/etc/rc.d/rc.local/中每次都关机后这个文件都会被删除)。
    这样在关机的时候关机的的脚本才会执行,很多朋友因为没有手动建立这个文件,手动执行/etc/rc.d/init.d/ora stop又是正常,但是关机时又不能执行,需多注意!
    [root@OracleCX subsys]# touch /var/lock/subsys/oracle
    [root@OracleCX subsys]# cat /etc/rc.d/rc.local
    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff.touch /var/lock/subsys/local
    touch /var/lock/subsys/oracle
     
    二、Solaris平台
     
    1. 修改/var/opt/oracle/oratab ,将“N”改为“Y”,格式 ORACLE_SID:ORACLE_HOME:Y,使之支持开机启动。如下:
    root@ZHZCDB2#vi /var/opt/oracle/oratab
    #
    # 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.
    #
    #
    zhfx:/oracle/product/10.2.0/db_1:N
    cmdb:/oracle/product/10.2.0/db_1:N
    unionmon:/oracle/product/10.2.0/db_1:Y
    report:/oracle/product/10.2.0/db_1:N
    pasm:/oracle/product/10.2.0/db_1:Y
    uip:/oracle/product/10.2.0/db_1:N
     
    2.创建启动脚本:
    root@ZHZCDB2#vi /etc/init.d/oracle
    #!/bin/sh
    ORACLE_HOME=/oracle/product/10.2.0/db_1
    ORACLE_OWNER=oracle
    if [ ! -f $ORACLE_HOME/bin/dbstart ]
    then
    echo "Oracle startup:cannot start"
    exit
    fi
    case "$1" in
    'start' )
    su - $ORACLE_OWNER -c $ORACLE_HOME/bin/dbstart &
    ;;
    'stop' )
    su - $ORACLE_OWNER -c $ORACLE_HOME/bin/dbshut &
    ;;
    esac
     
    3.赋予脚本执行权限:
    root@ZHZCDB2#chmod 755 /etc/init.d/oracle
     
    4.在/etc/rc2.d中设置启动链接:
    root@ZHZCDB2#cd /etc/rc2.d/
    root@ZHZCDB2#ln -s /etc/init.d/oracle S99oracle
     
    5.在/etc/rc0.d中设置关闭链接:
    root@ZHZCDB2#cd /etc/rc0.d
    root@ZHZCDB2#ln -s /etc/init.d/oracle K10oracle
      
    三、AIX平台
      
    1. 修改/etc/oratab ,将“N”改为“Y”,格式 ORACLE_SID:ORACLE_HOME:Y,使之支持开机启动。如下:
    # vi /etc/oratab#
    # 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.
    #
    #
    nms115:/oracle/product/10.2.0/db_1:Y
    web52:/oracle/product/10.2.0/db_1:Y
    jh1210:/oracle/product/10.2.0/db_1:Y
    nms512a:/oracle/product/10.2.0/db_1:Y
     
    2.创建启动脚本
    # vi /etc/rc.oracleexport ORACLE_SID=nms115
    echo "Start Oracle instance: nms115"
    su oracle -c '/oracle/product/10.2.0/db_1/bin/dbstart /oracle/product/10.2.0/db_1'export ORACLE_SID=web52
    echo "Start Oracle instance: web52"
    su oracle -c '/oracle/product/10.2.0/db_1/bin/dbstart /oracle/product/10.2.0/db_1'export ORACLE_SID=jh1210
    echo "Start Oracle instance: jh1210 "
    su oracle -c '/oracle/product/10.2.0/db_1/bin/dbstart /oracle/product/10.2.0/db_1'
     
    3.创建关闭脚本
    # vi /etc/rc.shutdownexport ORACLE_SID=nms115
    echo "Start Oracle instance: nms115"
    su oracle -c '/oracle/product/10.2.0/db_1/bin/dbshut /oracle/product/10.2.0/db_1'export ORACLE_SID=web52
    echo "Start Oracle instance: web52"
    su oracle -c '/oracle/product/10.2.0/db_1/bin/dbshut /oracle/product/10.2.0/db_1'export ORACLE_SID=jh1210
    echo "Start Oracle instance: jh1210 "
    su oracle -c '/oracle/product/10.2.0/db_1/bin/dbshut /oracle/product/10.2.0/db_1'
    注:关于为什么脚本叫/etc/rc.shutdown,以及怎么工作。如下注解:
    系统管理员可以在 /etc/rc.shutdown shell 脚本中放置本地定制的关闭过程。如果该脚本存在,则在关闭开始时就运行。如果脚本运行但是失败(返回非零返回码),则关机停止。
     
    4.赋予脚本执行权限:
    # chmod 755 /etc/rc.oracle
    # chmod 755 /etc/rc.shutdown
     
    5.添加到/etc/inittab最下面,实现自启动。并且创建启动日志:
    # vi /etc/inittab
    oracle:2:wait:/etc/rc.oracle > /home/oracle/oracle.log 2>$1

    Speak Your Mind

    *

    京ICP备14059771号-2