zoukankan      html  css  js  c++  java
  • Linux 环境下开机自启动Oracle服务

    使用如下命令查看Oracle相关服务是否已启动:

    ps aux | grep ora_ #若无ora_**_**相关的进程,则oracle数据库实例未启动

    netstat -tlnup | grep 1521 #若无任何显示,则监听器未启动

    lsnrctl status #查看监听器状态

    netstat -tlnup | grep 1158 #若无任何显示,则EM未启动

    emctl status dbconsole #查看EM状态

    1.启动数据库实例还得打开Oracle设置的一个关卡:vi /etc/oratab,修改行:

    [root@localhost ~]# vi /etc/oratab

    # orcl:/u01/app/oracle/product/11.2.0/db_1:N

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

    2.在linux 的/etc/init.d/ 添加oracle 服务,以root身份建立开机启动oracle服务的脚本:vi /etc/init.d/oracle,添加如下脚本:

    [root@localhost ~]# su - oracle

    [oracle@localhost ~]$ echo $ORACLE_HOME

    /u01/app/oracle/product/11.2.0/db_1

    [oracle@localhost ~]$ su - root

    密码:

    [root@localhost ~]# touch /var/log/oracle.log

    [root@localhost /]# vi /etc/init.d/oracle

    #!/bin/sh$
    
    #chkconfig: 2345 20 80
    
    #description: Oracle dbstart / dbshut
    
    # It is that is needed for chkconfig 
    
    ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
    
    ORA_OWNER=oracle
    
    LOGFILE=/var/log/oracle.log
    
    echo "#################################" >> ${LOGFILE}
    
    date +"### %T %a %D: Run Oracle" >> ${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(){
    
        echo "###Startup Database..."
    
        su - ${ORA_OWNER} -c "${ORACLE_HOME}/bin/dbstart ${ORACLE_HOME}"
    
        echo "###Done."
    
        echo "###Run database control..."
    
        su - ${ORA_OWNER} -c "${ORACLE_HOME}/bin/emctl start dbconsole"
    
        echo "###Done."
    
    }
    
    stop(){
    
        echo "###Stop database control..."
    
        su - ${ORA_OWNER} -c "${ORACLE_HOME}/bin/emctl stop dbconsole"
    
        echo "###Done."
    
        echo "###Shutdown Database..."
    
        su - ${ORA_OWNER} -c "${ORACLE_HOME}/bin/dbshut ${ORACLE_HOME}"
    
        echo "###Done."
    
    }
    
    case "$1" in
    
        'start')
    
            start >> ${LOGFILE}
    
        ;;
    
        'stop')
    
            stop >> ${LOGFILE}
    
        ;;
    
        'restart')
    
            stop >> ${LOGFILE}
    
            start >> ${LOGFILE}
    
        ;;
    
    esac
    
    date +"### %T %a %D: Finished." >> ${LOGFILE}
    
    echo "#################################" >> ${LOGFILE}
    
    echo ""
    oracle服务器启动脚本

    2.1使用如下命令将 /etc/init.d/oracle 置为可执行文件:

      [root@localhost /]# chmod a+x /etc/init.d/oracle

    2.2至此,可使用如下命令对oracle进行启动和关闭:

      [root@localhost /]# /etc/init.d/oracle start

      [root@localhost /]# /etc/init.d/oracle stop

      [root@localhost /]# /etc/init.d/oracle restart

    3.将oracle服务 添加到 chkconfig中,设置为系统服务:

      [root@localhost /]# chkconfig --add oracle

      [root@localhost /]# chkconfig | grep oracle

      oracle        0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭

    3.1使用如下命令查看和设置oracle服务的开机启动级别:

      [root@localhost /]# chkconfig --level 24 oracle off  #修改oracle服务的开机启动级别

      [root@localhost /]# chkconfig --level 35 oracle on  #修改oracle服务的开机启动级别

    4.至此,所添加的服务已经作为linux中的服务了,可使用如下命令对oracle的启动或关闭进行管理:

      [root@localhost /]# service oracle stop

      [root@localhost /]# service oracle start

    5.建立连接:

      [root@localhost /]# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle  #关机执行

      [root@localhost /]# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle  #重启执行

    5.1 rc.d说明:

      [root@localhost ~]# ls /etc/rc.d/
      init.d  rc0.d  rc1.d  rc2.d  rc3.d  rc4.d  rc5.d  rc6.d

      0 - 停机 
      1 - 单用户模式 
      2 - 多用户,但是没有NFS ,不能使用网络 
      3 - 完全多用户模式,我最喜欢的模式 
      4 - “打酱油” 模式,没有用到 
      5 - X11   桌面模式
      6 - 重新启动 (如果将默认启动模式设置为6,Linux将会不断重启)

      rc#.d       其中#代表系统运行级别

  • 相关阅读:
    css样式表
    js正则表达式
    jQuery工具函数
    jquery tmpl 详解
    JS产生随机数的几个用法!
    IE浏览器中用Firebug调试网站的方法
    CSS clip:rect矩形剪裁功能及一些应用介绍
    如何修改vs2010中html的默认模板
    sublime text 3 注册机
    SQL语句报com.alibaba.druid.sql.parser.ParserException: TODO IDENTIFIER cross
  • 原文地址:https://www.cnblogs.com/HondaHsu/p/4864175.html
Copyright © 2011-2022 走看看