• Linux Oracle服务启动&停止脚本与开机自启动


    环境说明:
    ORACLE_SID= orcl
    ORACLE_BASE=/oracle/app/oracle
    ORACLE_HOME=/oracle/app/oracle/product/11.2.0/dbhome_1


    (以下操作都用root执行)
    1. 修改Oracle系统配置文件:/etc/oratab,只有这样,Oracle 自带的dbstart和dbshut才能够发挥作用。

    # vi /etc/oratab , 将 ORACLE_SID:ORACLE_HOME:Y 相应模块替换 ,如下
    orcl:/oracle/app/oracle/product/11.2.0/dbhome_1:Y

    2. 在 /etc/init.d/ 下创建文件oracle,内容如下: (指定该环境的ORA_HOME=XX 路径)

    #!/bin/bash
    #chkconfig:345 61 61
    #description:Apache
    #
    # 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=/oracle/app/oracle/product/11.2.0/dbhome_1
    ORA_OWNER=oracle
    if [ ! -f $ORA_HOME/bin/dbstart ]
    then
    echo "Oracle startup: cannot start"
    exit
    fi
    case "$1" in
    'start')
    # Start the Oracle databases:
    echo "Starting Oracle Databases ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
    echo "Done"

    # Start the Listener:
    echo "Starting Oracle Listeners ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
    echo "Done."
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Finished." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    touch /var/lock/subsys/oracle
    ;;

    'stop')
    # Stop the Oracle Listener:
    echo "Stoping Oracle Listeners ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
    echo "Done."
    rm -f /var/lock/subsys/oracle

    # Stop the Oracle Database:
    echo "Stoping Oracle Databases ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
    echo "Done."
    echo ""
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Finished." >> /var/log/oracle
    echo "-------------------------------------------------" >> /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

    7. 测试

  • 相关阅读:
    MAVEN学习-第一个Maven项目的构建
    MAVEN学习笔记-maven的获取和安装
    Hibernate中的锁机制
    java进阶之反射:反射基础之如何获取一个类以及如何获取这个类的所有属性和方法(2)
    java进阶之反射:反射基础之如何获取一个类以及如何获取这个类的所有属性和方法(1)
    java中的文件读取和文件写出:如何从一个文件中获取内容以及如何向一个文件中写入内容
    开篇:勇敢踏上这第一步
    有关嵌入式linux的注意点总结
    《nodejs开发指南》微博实例express4.x版
    JavaScript中的数据类型转换
  • 原文地址:https://www.cnblogs.com/andy6/p/5723435.html
Copyright © 2020-2023  润新知