oracle9.2.0.4.0 for Redhat8 开机自启动

阅读更多
摘自:http://yuwentong.spaces.live.com/Blog/cns!1p7LX0KNdjR0K7CVNOCFKwAw!707.entry

1,修改Oracle系统配置文件/etc/oratab
   /etc/oratab 格式为: SID:ORACLE_HOME:AUTO
   把AUTO域设置为Y(大写),只有这样,oracle 自带的dbstart和dbshut才能够发挥作用。
   我的修改为:ora9i:/home/oracle/ora/products/9.2:Y
 
   2,编写服务脚本
     root身份登陆,将脚本命名为oracle,保存在/etc/rc.d/init.d下
     [root@localhost root]# vi /etc/rc.d/init.d/oracle
内容如下:
#!/bin/sh
#
#/etc/rc.d/init.d/oracle
case "$1" in
  start)
        echo -n "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 - oracle -c /opt/ora9/product/9.2/bin/dbstart >> /var/log/oracle
        echo "Done."
        echo -n "Starting Oracle Listeners: "
        su - oracle -c "/opt/ora9/product/9.2/bin/lsnrctl start" >> /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 -n "Shutting Down Oracle Listeners: "
        echo "----------------------------------------------------" >> /var/log/oracle
        date +"! %T %a %D : Shutting Down Oracle Databases as part of system down." >> /var/log/oracle
        echo "----------------------------------------------------" >> /var/log/oracle
        su - oracle -c "/opt/ora9/product/9.2/bin/lsnrctl stop" >> /var/log/oracle
        echo "Done."
        rm -f /var/lock/subsys/oracle
        echo -n "Shutting Down Oracle Databases: "
        su - oracle -c /opt/ora9/product/9.2/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)
        echo -n "Restarting Oracle Databases: "
        echo "----------------------------------------------------" >> /var/log/oracle
        date +"! %T %a %D : Restarting Oracle Databases as part of system up." >> /var/log/oracle
        echo "----------------------------------------------------" >> /var/log/oracle
        su - oracle -c /opt/ora9/product/9.2/bin/dbshut >> /var/log/oracle
        su - oracle -c /opt/ora9/product/9.2/bin/dbstart >> /var/log/oracle
        echo "Done."
        echo -n "Restarting Oracle Listeners: "
        su - oracle -c "/opt/ora9/product/9.2/bin/lsnrctl stop" >> /var/log/oracle
        su - oracle -c "/opt/ora9/product/9.2/bin/lsnrctl start" >> /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 755 oracle
   
   3,创建实例
   [oracle@localhost oracle]$ vi /opt/ora9/product/9.2/bin/dbstart
   注意: PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora
   实际找不到我们新创建的ora9i的实例,创建缺少的文件:
   [oracle@localhost oracle]$ cd /opt/ora9/product/9.2/dbs
   [oracle@localhost dbs]$ cp init.ora /opt/ora9/product/9.2/initora9i.ora
   创建initora9i.ora,其内容和init.ora相同即可
   4,建立服务连接
系统启动时启动数据库,我们需要以下连结∶
--------------------------------------------------------------------------------
[oracle@localhost rc2.d]$ ln -s ../init.d/oracle /etc/rc.d/rc2.d/S99oracle
[oracle@localhost rc3.d]$ ln -s ../init.d/oracle /etc/rc.d/rc3.d/S99oracle
[oracle@localhost rc5.d]$ ln -s ../init.d/oracle /etc/rc.d/rc5.d/S99oracle #rc4.d unused
--------------------------------------------------------------------------------
要在重新启动时停止数据库,我们需要以下连结∶
--------------------------------------------------------------------------------
[oracle@localhost rc0.d]$ ln -s ../init.d/oracle /etc/rc.d/rc0.d/K01oracle # 停止
[oracle@localhost rc6.d]$ ln -s ../init.d/oracle /etc/rc.d/rc6.d/K01oracle # 重新启动
 
   5,重新启动
   [root@localhost root]# reboot
注意:
(1)如果与数据库有链接时,想强行重新启动计算机时,需要修改:
   vi /opt/ora9/product/9.2/dbshut
   将 shutdown 修改为 shutdown abort ,否则正常关闭计算机时,会显示 Stoping Oracle 停不掉!

你可能感兴趣的:(Oracle,C,C++,C#,脚本)