WEB开发网
开发学院数据库Oracle 讲解Linux环境下Oracle的自动启动与停止 阅读

讲解Linux环境下Oracle的自动启动与停止

 2008-09-02 12:47:36 来源:WEB开发网   
核心提示:1、 修改Oracle系统配置文件/etc/oratab /etc/oratab 格式为: SID:ORACLE_HOME:AUTO 把AUTO域设置为Y(大写),只有这样,讲解Linux环境下Oracle的自动启动与停止,oracle 自带的dbstart和dbshut才能够发挥作用,我的为: ora9i:/home

1、 修改Oracle系统配置文件/etc/oratab

/etc/oratab 格式为: SID:ORACLE_HOME:AUTO

把AUTO域设置为Y(大写),只有这样,oracle 自带的dbstart和dbshut才能够发挥作用。我的为:

ora9i:/home/oracle/ora/products/9.2.0:Y

2、 编写服务脚本:

如下:

#!/bin/bash 
# 
#################FUNCTION############# 
# 
#AutoStartOracleandlistener 
#AutoStopOracleandlistener 
# 
##################################### 
# 
#createdbyZhouYS2003-11-26 
# 
case"$1"in 
start) 
echo"StartingOracleDatabases..." 
echo"-------------------------------------------------">>/var/log/oracle 
date+"%T%a%D:StartingOracleDatabaseeaspartofsystemup.">>/var/log/oracle 
echo"-------------------------------------------------">>/var/log/oracle 
su-oracle-c"dbstart">>/var/log/oracle 
echo"Done." 
echo"StartingOracleListeners..." 
echo"-------------------------------------------------">>/var/log/oracle 
date+"%T%a%D:StartingOracleListenersaspartofsystemup.">>/var/log/oracle 
echo"-------------------------------------------------">>/var/log/oracle 
su-oracle-c"lsnrctlstart">>/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"StopingOracleListeners..." 
echo"-------------------------------------------------">>/var/log/oracle 
date+"%T%a%D:StopingOracleListeneraspartofsystemdown.">>/var/log/oracle 
echo"-------------------------------------------------">>/var/log/oracle 
su-oracle-c"lsnrctlstop">>/var/log/oracle 
echo"Done." 
rm-f/var/lock/subsys/oracle 
echo"StopingOracleDatabases..." 
echo"-------------------------------------------------">>/var/log/oracle 
date+"%T%a%D:StopingOracleDatabasesaspartofsystemdown.">>/var/log/oracle 
echo"-------------------------------------------------">>/var/log/oracle 
su-oracle-c"dbshut">>/var/log/oracle 
echo"Done." 
echo"" 
echo"-------------------------------------------------">>/var/log/oracle 
date+"%T%a%D:Finished.">>/var/log/oracle 
echo"-------------------------------------------------">>/var/log/oracle 
;; 
restart) 
$0stop 
$0start 
;; 
*) 
echo"Usage:oracle{start|stop|restart}" 
exit1 
esac

将脚本命名为oracle,保存在/etc/rc.d/init.d下

改变文件属性:chmod 755 oracle

注意:在windows下编辑此文件时有DOS格式字符导致在linux下不能够正常运行,建议用gedit 或用 vi编辑

3、建立服务连接:

系统启动时启动数据库,我们需要以下连结∶

--------------------------------------------------------------------------------

$ ln -s ../init.d/oracle /etc/rc.d/rc2.d/S99oracle

$ ln -s ../init.d/oracle /etc/rc.d/rc3.d/S99oracle

$ ln -s ../init.d/oracle /etc/rc.d/rc5.d/S99oracle #rc4.d unused

--------------------------------------------------------------------------------

要在重新启动时停止数据库,我们需要以下连结∶

--------------------------------------------------------------------------------

$ ln -s ../init.d/oracle /etc/rc.d/rc0.d/K01oracle # 停止

$ ln -s ../init.d/oracle /etc/rc.d/rc6.d/K01oracle # 重新启动

Tags:讲解 Linux 环境

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接