前段时间整理的linux下ORACLE自动启动的方法,今天回顾一下:
1. Root用户登录,vi /etc/oratab
orcl:/u01/app/oracle/product/10.2.0/db_1:N 改为orcl:/u01/app/oracle/product/10.2.0/db_1:Y
--------------------------------------------------------------------------------------------------
2. root 用户 在/etc/rc.d/init.d/目录下新建一个文件 oracle10g,把如下内容放到这个文件里,注意参数需要修改
[root@rhel5 ~]# cd /etc/rc.d/init.d/
[root@rhel5 init.d]# touch oracle10g
[root@rhel5 init.d]# chmod a+x oracle10g
[root@rhel5 init.d]# vim oracle10g
#!/bin/bash
# chkconfig: 345 99 10
# description: Startup Script for Oracle Databases
# /etc/rc.d/init.d/oracle10g
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: can not 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 oracle10g: "
su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart"
touch /var/lock/subsys/oracle10g
su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctl start"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
echo "OK"
;;
'stop')
# Oracle listener and instance shutdown
echo -n "shutting down oracle10g: "
su - $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/isqlplusctl stop"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut"
su - $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
rm -f /var/lock/subsys/oracle10g
echo "OK"
;;
'reload|restart')
$0 stop
$0 start
;;
*)
echo "Usage:'basename $0' start|stop|restart|reload"
exit 1
esac
exit 0
-----------------------------------------------------------------------------------------------------
3.使用oracle用户修改$ORACLE_HOME/bin/dbstart文件:
# su - oracle
$ cd $ORACLE_HOME/bin
$ gedit dbstart
找到 ORACLE_HOME_LISTNER=.....这行, 修改成
ORACLE_HOME_LISTNER=/u01/app/oracle/product/10.2.0/db_1
或者直接修改成:
ORACLE_HOME_LISTNER=$ORACLE_HOME
注意:是修改,不是增加,可是使用gedit的查找功能查找:
确保执行dbstart命令没有错误,如果不修改上面的路径,dbstart会报错
--------------------------------------------------------------------------------------------------------
4.ROOT用户编辑 /etc/rc.d/rc.local 文件,目前我这边保留的是如下:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
su - oracle -lc "/u01/app/oracle/product/10.2.0/db_1/bin/lsnrctl start"
su - oracle -lc "/u01/app/oracle/product/10.2.0/db_1/bin/dbstart"
重启操作系统,就可以自动启动了