Oracle10gr2 开机自启动脚本

  • 时间:3年前
  • 浏览:1156次
  • 网赌被黑找腾龙D哥出黑【微信:JLYL78999 QQ:840093333】

    目录

    软件环境

    Oracle服务启动、停止、重启脚本

    su - oracle
    cd /u01/oracle/bin
    #进入到Oracle安装的home目录下bin目录中

    创建启动脚本
    /u01/oracle/bin下创建启停脚本。
    vim dbstartup

        #!/bin/bash
        lsnrctl start                 #启动监听程序
        sqlplus /nolog <<EOF          
        connect / as sysdba
        startup                       #进入到Oracle并且连接到SYS管理员账户,执行启动Database
        EOF
    

    vi dbstop

        #!/bin/bash
        lsnrctl stop
        sqlplus /nolog <<EOF
        connect / as sysdba
        shutdown immediate
        EOF

    赋予执行权限

    chmod +x dbstartup
    chmod +x dbstop

    进入到root用户

    su - root
    cd /etc/rc.d/init.d

    创建oracle服务管理脚本
    oracle脚本调用了上面的dbstartupdbstop脚本,可以实现在root用户下启动、停止、重启Oracle服务,并且能够通过/var/log/oracle查看启动日志。
    vi oracle

        #!/bin/bash
        case "$1" in
        start)
            echo "Starting Oracle Listener and Database ... "
            echo "----------------------------------------------------------------------" >> /var/log/oracle
            date +" %T %a %D : Starting Oracle Listener and Database ... " >> /var/log/oracle
            echo "----------------------------------------------------------------------" >> /var/log/oracle
            su - oracle -c dbstartup >> /var/log/oracle
            echo "Done."
            echo ""
            echo "---------------------------------------------------------------------" >> /var/log/oracle
            date +" %T %a %D :Finished." >>/var/log/oracle
            echo "---------------------------------------------------------------------" >> /var/log/oracle
            touch /var/lock/subsys/oracle
            ;;
        stop)
            echo "Stop Oracle Database and Listener ... "
            echo "---------------------------------------------------------------------" >> /var/log/oracle
            date +" %T %a %D : Stop Oracle Listener and Databases ..." >> /var/log/oracle
            echo "---------------------------------------------------------------------" >> /var/log/oracle
            su - oracle -c dbstop >> /var/log/oracle
            rm -f /var/lock/subsys/oracle
            echo "Done."
            echo ""
            echo "---------------------------------------------------------------------" >> /var/log/oracle
            date +" %T %a %D : Finished." >> /var/log/oracle
            echo "---------------------------------------------------------------------" >> /var/log/oracle
            ;;
        restart)
            echo "Restarting Oracle Listener and Database ..."
            echo "---------------------------------------------------------------------" >> /var/log/oracle
            date +" %T %a %D : Restart ing Oracle Listener and Databases ..." >> /var/log/oracle
            echo "---------------------------------------------------------------------" >> /var/log/oracle
            su - oracle -c dbstop >> /var/log/oracle
            su - oracle -c dbstartup >> /var/log/oracle
            echo "Done."
            echo ""
            echo "---------------------------------------------------------------------" >> /var/log/oracle
            date +" %T %a %D : Finished." >> /var/log/oracle
            echo "---------------------------------------------------------------------" >> /var/log/oracle
            touch /var/lock/subsys/oracle
            ;;
        *)
            echo "Usage: oracle {start|stop|restart}"
            exit 1
        esac

    赋予执行权限

    chmod +x oracle

    测试

    [root@jmilk init.d]# /sbin/service oracle restart
    Restarting Oracle Listener and Database ...
    Done

    创建进程链接文件

    [root@jmilk init.d]# ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc3.d/K01oracle
    [root@jmilk init.d]# ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc3.d/S99oracle
    [root@jmilk init.d]# ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc5.d/K01oracle
    [root@jmilk init.d]# ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc5.d/S99oracle
    [root@jmilk init.d]# ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc0.d/K01oracle
    [root@jmilk init.d]# ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc6.d/K01oracle

    自动启动实例:
    vi /etc/oratab

    demo:/u01/oracle:Y     #把N改为Y
    网赌被黑找腾龙D哥出黑【微信:JLYL78999 QQ:840093333】

    留言反馈

    网赌被黑找腾龙D哥出黑【微信:JLYL78999 QQ:978107219】鲁ICP备13008445号-3||Theme by Cn+网络, Soft by ZBlogPHP
  • 网赌被黑