Oracle 11G 开机自动启动(Linux)
1) root 下面修改/etc/oratab:将N改成Y。
[root@localhost etc]# vi oratab
# This file is used by ORACLE utilities. It is created by root.sh # and updated by the Database Configuration Assistant when creating # a database. # A colon, ':', is used as the field terminator. A new line terminates # the entry. Lines beginning with a pound sign, '#', are comments. # # Entries are of the form: # $ORACLE_SID:$ORACLE_HOME:<N|Y>: # # The first and second fields are the system identifier and home # directory of the database respectively. The third filed indicates # to the dbstart utility that the database should , "Y", or should not, # "N", be brought up at system boot time. # # Multiple entries with the same $ORACLE_SID are not allowed. # # VISUSIT:/opt/oracle/product/11.2.0/db1:Y
2) oracle 下面修改 $ORACLE_HOME/bin/dbstart:
找到 ORACLE_HOME_LISTNER 这行, 修改成:
ORACLE_HOME_LISTNER=/opt/oracle/product/11.2.0/db1
或者直接修改成:
ORACLE_HOME_LISTNER=$ORACLE_HOME
[oracle@localhost bin]$ cd $ORACLE_HOME/bin [oracle@localhost bin]$ vi dbstart ...
70 # for script tracing 71 case $ORACLE_TRACE in 72 T) set -x ;; 73 esac 74 75 # Set path if path not set (if called from /etc/rc) 76 SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ; export PATH 77 SAVE_LLP=$LD_LIBRARY_PATH 78 79 # First argument is used to bring up Oracle Net Listener 80 ORACLE_HOME_LISTNER=$ORACLE_HOME 81 if [ ! $ORACLE_HOME_LISTNER ] ; then 82 echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener" 83 echo "Usage: $0 ORACLE_HOME" 84 else 85 LOG=$ORACLE_HOME_LISTNER/listener.log 86 87 # Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to 88 # a different ORACLE_HOME for each entry in the oratab. 89 export ORACLE_HOME=$ORACLE_HOME_LISTNER 90 91 # Start Oracle Net Listener 92 if [ -x $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then 93 echo "$0: Starting Oracle Net Listener" >> $LOG 2>&1 94 $ORACLE_HOME_LISTNER/bin/lsnrctl start >> $LOG 2>&1 & 95 VER10LIST=`$ORACLE_HOME_LISTNER/bin/lsnrctl version | grep "LSNRCTL for " | cut -d' ' -f5 | cut -d'.' -f1` 96 export VER10LIST 97 else 98 echo "Failed to auto-start Oracle Net Listener using $ORACLE_HOME_LISTNER/bin/tnslsnr" 99 fi 100 fi
同样道理修改 $ORACLE_HOME/bin/dbshut.
3) 测试运行 dbshut, dbstart 看能否启动oracle 服务及listener服务。
[oracle@localhost bin]$ dbshut Processing Database instance "VISUSIT": log file /opt/oracle/product/11.2.0/db1/shutdown.log [oracle@localhost bin]$ dbstart Processing Database instance "VISUSIT": log file /opt/oracle/product/11.2.0/db1/startup.log [oracle@localhost bin]$
4)切换回 root在/etc/rc.d/init.d/目录新建orad:
[root@localhost dengxh]# cd /etc/rc.d/init.d [root@localhost init.d]# vi orad #!/bin/bash # # orad Starts and stops Oracle databases daemon # # chkconfig: 345 99 01 #2345 -- run level , 99 --the priority for startup system, 01 --the priority for shutdown system. # description: orad is the tools for startup/shutdown Oracle Databases # source function library . /etc/rc.d/init.d/functions PID_FILE=/var/run/orad.pid export ORACLE_SID=VISUSIT export ORACLE_BASE=/opt/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db1 export PATH=$PATH:$ORACLE_HOME/bin case "$1" in start) su oracle -c $ORACLE_HOME/bin/dbstart echo `pidof -s ora_pmon_$ORACLE_SID` > $PID_FILE echo "Start Oracle OK" ;; stop) su oracle -c $ORACLE_HOME/bin/dbshut rm -f $PID_FILE echo "Shutdown Oracle OK" ;; restart) $0 stop $0 start ;; status) status -p $PID_FILE orad-daemon ;; *) echo "Usage: $0 start|stop|restart" exit 1 esac exit 0
5) 测试运行orad start|stop|restart 看能否启动oracle 服务及listener服务。
[root@localhost init.d]# orad restart Processing Database instance "VISUSIT": log file /opt/oracle/product/11.2.0/db1/shutdown.log Processing Database instance "VISUSIT": log file /opt/oracle/product/11.2.0/db1/startup.log Restart Oracle OK [root@localhost init.d]# orad stop Processing Database instance "VISUSIT": log file /opt/oracle/product/11.2.0/db1/shutdown.log Shutdown Oracle OK [root@localhost init.d]# orad start Processing Database instance "VISUSIT": log file /opt/oracle/product/11.2.0/db1/startup.log Start Oracle OK
6) 添加orad到chkconfig中:
[root@localhost init.d]# chkconfig --add orad [root@localhost init.d]# chkconfig --list orad orad 0:off 1:off 2:off 3:on 4:on 5:on 6:of
7) 测试Sevice
[root@localhost init.d]# service orad restart Processing Database instance "VISUSIT": log file /opt/oracle/product/11.2.0/db1/shutdown.log Shutdown Oracle OK Processing Database instance "VISUSIT": log file /opt/oracle/product/11.2.0/db1/startup.log Start Oracle OK [root@localhost init.d]# service orad status orad-daemon (pid 5866) is running... [root@localhost init.d]#
重新启动Linux的时候,如果看到启动项orad出现OK,代表Oracle成功随Linux启动了。