linux服务器下oracle开机自启

原文:https://www.w3xue.com/exp/article/201910/60559.html

1、首先切换到Oracle用户

[oracle@oracletest ~]$ cd /u01/app/oracle/product/11.2.0/db_1/bin/       -----标红字体部分数据库可能不一样,有的是dbhome_1,以自己实际配置目录为准

[oracle@oracletest bin]$ vi dbstart 

  1. LOGMSG="logger -puser.alert -s "
  2. trap 'exit' 1 2 3
  3. # for script tracing
  4. case $ORACLE_TRACE in
  5. T) set -x ;;
  6. esac
  7. # Set path if path not set (if called from /etc/rc)
  8. SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ; export PATH
  9. SAVE_LLP=$LD_LIBRARY_PATH
  10. # First argument is used to bring up Oracle Net Listener
  11. ORACLE_HOME_LISTNER=$ORACLE_HOME ############此处原来是$1,改成$ORACLE_HOME
  12. if [ ! $ORACLE_HOME_LISTNER ] ; then
  13. echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener"
  14. echo "Usage: $0 ORACLE_HOME"
  15. else
  16. LOG=$ORACLE_HOME_LISTNER/listener.log

2、用root用户编辑oratab和rc.local

[root@oracletest ~]# vi /etc/oratab

  1. # This file is used by ORACLE utilities. It is created by root.sh
  2. # and updated by either Database Configuration Assistant while creating
  3. # a database or ASM Configuration Assistant while creating ASM instance.
  4. # A colon, ':', is used as the field terminator. A new line terminates
  5. # the entry. Lines beginning with a pound sign, '#', are comments.
  6. #
  7. # Entries are of the form:
  8. # $ORACLE_SID:$ORACLE_HOME:<N|Y>:
  9. #
  10. # The first and second fields are the system identifier and home
  11. # directory of the database respectively. The third filed indicates
  12. # to the dbstart utility that the database should , "Y", or should not,
  13. # "N", be brought up at system boot time.
  14. #
  15. # Multiple entries with the same $ORACLE_SID are not allowed.
  16. #
  17. #
  18. oadb:/u01/app/oracle/product/11.2.0/db_1:Y ###此处原来是N,改为Y

[root@oracletest ~]# vi /etc/rc.d/rc.local 

  1. #!/bin/sh
  2. #
  3. # This script will be executed *after* all the other init scripts.
  4. # You can put your own initialization stuff in here if you don't
  5. # want to do the full Sys V style init stuff.
  6. touch /var/lock/subsys/local
  7. #####在空白处添加下面两行,其中标红字体部分数据库可能不一样,有的是dbhome_1,以自己实际配置目录为准
  8. su oracle -lc "/u01/app/oracle/product/11.2.0/db_1/bin/lsnrctl start"
  9. su oracle -lc /u01/app/oracle/product/11.2.0/db_1/bin/dbstart

经过上面两步操作,数据库服务器重启后,数据库也会自动启动。

原文地址:https://www.cnblogs.com/wangmo/p/14950365.html