日期:2014-05-17  浏览次数:20891 次

如何设置在Linux启动后,Oracle也启动,监听也启动?
我的Oracle版本是:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Linux版本是:
Linux version 2.6.18-194.el5 (mockbuild@x86-007.build.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Tue Mar 16 21:52:43 EDT 2010

------解决方案--------------------
SQL code
1 修改/etc/oratab的内容
把sid:$ORACLE_HOME:N 改成sid:$OEACLE_HOME:Y
比如
orcl:/oracle/product/10.2.0/db_1:N
改成
orcl:/oracle/product/10.2.0/db_1:Y
注意 如果 /etc/oratab的文件不存在 需运行如下命令 创建
Sh /oracle/ORACLE/product/10.2.0/db_1/root.sh
(格式 sh  /oracle_home/root.sh)

2在/etc/init.d/目录下配置Oracle的服务文件
命令如下:
cd /etc/init.d/
touch oracle10g
chmod a+x oracle10g

然后在oracle10g加入如下内容 (Vi /etc/rc.d/init.d/oracle10g)
# !/bin/bash
# whoami
# root
# chkconfig: 345 51 49
# /etc/init.d/oracle10g
# description: starts the oracle dabase deamons
#
ORA_HOME=/oracle/ORACLE/product/10.2.0/db_1/  ---这里是我的oracle目录 
ORA_OWNER=oracle
case "$1" in
start)
echo -n "Starting oracle10g: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" &
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
touch /var/lock/subsys/oracle10g
echo
;;

stop)
echo -n "shutting down oracle10g: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" &
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
rm -f /var/lock/subsys/oracle10g
echo
;;

restart)
echo -n "restarting oracle10g: "
$0 stop
$0 start
echo
;;
*)
echo "Usage: `basename $0` start|stop|restart"
exit 1

esac
exit 0

按esc键 :wq 保存退出

打开终端执行:
chmod 775 /etc/rc.d/init.d/oracle10g

设定oracle10g服务的启动级别
cd /etc/rc.d/init.d/
chkconfig --add oracle10g  ---加服务列表
chkconfig --list oracle10g   ---查看结果

(比如
chkconfig --list oracle10g   运行结果:
oracle10g   0:off 1:off 2:off 3:on 4:on 5:on 6:off)


3. 在 /etc/rc.d/rc.local上加上下面的内容(vi /etc/rc.d/rc.local)
su - oracle -c 'dbstart' su - oracle -c 'lsnrctl start'

按esc键 :wq 保存退出