Oracle10gr2 开机自启动脚本

标签: oracle操作系统vim脚本软件
796人阅读 评论(0) 收藏 举报
分类:

目录

软件环境

  • 操作系统
    • RHEL6.1
  • 软件
    • Oracle10gr2

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
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:839291次
    • 积分:10831
    • 等级:
    • 排名:第1638名
    • 原创:271篇
    • 转载:6篇
    • 译文:1篇
    • 评论:249条
    看累了?! 我有歌你要听一下吗
    Github
    博客专栏
    轻松一下~ Hope you enjoy !
    最新评论
    广告位去除
    统计