您的位置:首页 > 数据库 > Oracle

Linux下oracle 10g开机自动启动(监听,实例)

2011-11-09 10:35 1126 查看
当前环境:Oracle enterprise Linux 5.6+Oracle 10.2.0.1

数据库安装成功后,如果操作系统重启,数据库不会自动启动,以下步骤将实现oralce数据库随操作系统自动启动。

一、使用root用户修改/etc/oratab 文件:

$ vi /etc/oratab

orcl:/oracle/app/product/10.2.0/db_1:N

改为:

orcl:/oracle/app/product/10.2.0/db_1:Y ##也就是将最后的N改为Y

二、使用ORACLE用户修改$ORACLE_HOME/bin/dbstart文件:

# su - oracle $ cd $ORACLE_HOME/bin

$ vi dbstart

找到 ORACLE_HOME_LISTNER=这行,修改成

ORACLE_HOME_LISTNER=$ORACLE_HOME



三、测试运行 dbshut, dbstart 脚本看能否启动oracle服务及listener服务:

1.修改dbstart和dbshut的日志文件的权限:

$su - root

#cd $ORACLE_HOME

#chown oracle:oinstall startup.log

#chown oracle:oinstall shutdown.log 以上2个日志文件可能不存在,或下一步的时候再回去查看日志文件

2.执行相应的脚本进行测试

#su - oracle

$cd $ORACLE_HOME/bin

$./dbstart (或./dbshut)

$ ps -efw | grep ora_

$ lsnrctl status #查看监听状态

$ ps -efw | grep LISTEN | grep -v grep

四:创建添加自动启动执行脚本

$su - root

# cd /etc/rc.d/init.d/

# gedit oradbstart

复制如下脚本1或者脚本2内容到oradbstart文件:

脚本1:

#!/bin/bash

# chkconfig: 345 99 10

# description: Startup Script for oracle Databases

# /etc/rc.d/init.d/dbstart

export ORACLE_BASE=/u01/app/oracle/

export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1

export ORACLE_SID=orcl

export PATH=$PATH:$ORACLE_HOME/bin

ORA_OWNR="oracle"

# if the executables do not exist -- display error

if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]

then

echo "Oracle startup: cannot start"

exit 1

fi

# depending on parameter -- startup, shutdown, restart

# of the instance and listener or usage display

case "$1" in

start)

# Oracle listener and instance startup

echo -n "Starting Oracle: "

su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart"

touch /var/lock/oracle

su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"

su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctrl start"

echo "OK"

;;

stop)

# Oracle listener and instance shutdown

echo -n "Shutdown Oracle: "

su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"

su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctrl stop"

su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut"

su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"

rm -f /var/lock/oracle

echo "OK"

;;

reload|restart)

$0 stop

$0 start

;;

*)

echo "Usage: `basename $0` start|stop|restart|reload"

exit 1

esac

exit 0

脚本2

#!/bin/bash

# chkconfig: 345 99 10

# description: Startup Script for oracle Databases

# /etc/rc.d/init.d/oradbstart

export ORACLE_BASE=/u01/app/oracle/

export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1

export ORACLE_SID=orcl

export PATH=$PATH:$ORACLE_HOME/bin

case "$1" in

start)

su oracle -c $ORACLE_HOME/bin/dbstart

touch /var/lock/oracle

echo "OK"

;;

stop)

echo -n "Shutdown oracle: "

su oracle -c $ORACLE_HOME/bin/dbshut

rm -f /var/lock/oracle

echo "OK"

;;

*)

echo "Usage: 'basename $0' start|stop"

exit 1

esac

exit 0

注意点

(1).#开始的行不能少,否则后面运行chkconfig命令会报错:oradbstart 服务不支持chkconfig

(2).根据自己的环境修改环境变量配置部分

最后打开终端执行:

$su - root

#chown oracle.oinstall /etc/rc.d/init.d/oradbstart

#chmod 775 /etc/rc.d/init.d/oradbstart

然后执行:

chkconfig --add oradbstart

chkconfig --list oradbstart

chkconfig --list oradbstart

运行结果:

oradbstart 0:off 1:off 2:off 3:on 4:on 5:on 6:off

注:根据上面的运行结果,当相应的运行级别为on时(例如:5:on),在对应的/etc/rc.d/rcN.d(例如:和5:on对应的是:/etc/rc.d/rc5.d)下面会生成一个文件:S99oradbstart,使用vi S99oradbstart打开该文件,可以看到该文件的内容和/etc/rc.d/init.d/oradbstart内容相同,表示配置成功

最后重启操作系统测试。
本文出自 “老大不小” 博客,请务必保留此出处http://lubcdc.blog.51cto.com/3785870/710062
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: