1. 程式人生 > 實用技巧 >linux7(centos7)設定oracle11開機自啟動

linux7(centos7)設定oracle11開機自啟動

在linux7下安裝了oracle,每次重啟之後都要重新啟動資料庫很麻煩,所以設定為開機自啟動。

1、修改oracle自啟動配置檔案oratab,修改N為Y,允許oracle資料庫在系統啟動時啟動

[root@test-1 ~]# vi /etc/oratab

 如下所示,將最後一行的N修改為Y 

# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.

# 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.
#
#
orcl:/syn/oracle/product/11.2.0:Y

2、修改oracle的dbstart檔案

將ORACLE_HOME_LISTNER=$1
修改為ORACLE_HOME_LISTNER=$ORACLE_HOME

[root@test-1 bin]# vi /syn/oracle/product/11.2.0/bin/dbstart

  如下所示:

# usage: dbstart $ORACLE_HOME
#
# whose third field is a "Y".  If the third field is set to "Y" and
# there is no ORACLE_SID for an entry (the first field is a *),
# then this script will ignore that entry.
#
# This script requires that ASM ORACLE_SID's start with a +, and
# that non-ASM instance ORACLE_SID's do not start with a +.
#
# If ASM instances are to be started with this script, it cannot
# be used inside an rc*.d directory, and should be invoked from
# rc.local only. Otherwise, the CSS service may not be available
# yet, and this script will block init from completing the boot
# cycle.
#
# If you want dbstart to auto-start a single-instance database that uses
# an ASM server that is auto-started by CRS (this is the default behavior
# for an ASM cluster), you must change the database's ORATAB entry to use
# a third field of "W" and the ASM's ORATAB entry to use a third field of "N".
# These values specify that dbstart auto-starts the database only after
# the ASM instance is up and running.
#
# Note:
# Use ORACLE_TRACE=T for tracing this script.
#
# The progress log for each instance bringup plus Error and Warning message[s]
# are logged in file $ORACLE_HOME/startup.log. The error messages related to
# instance bringup are also logged to syslog (system log module).
# The Listener log is located at $ORACLE_HOME_LISTNER/listener.log
#
# On all UNIX platforms except SOLARIS
# ORATAB=/etc/oratab
#
# To configure, update ORATAB with Instances that need to be started up
#    Entries are of the form:
#    $ORACLE_SID:$ORACLE_HOME:<N|Y|W>:
#    An example entry:
#    main:/usr/lib/oracle/emagent_10g:Y
#
# Overall algorithm:
# 1) Bring up all ASM instances with 'Y' entry in status field in oratab entry
# 2) Bring up all Database instances with 'Y' entry in status field in
#    oratab entry
# 3) If there are Database instances with 'W' entry in status field
#      wait for all of them to be started
#    fi
# 4) Bring up all Database instances with 'W' entry in status field in
#    oratab entry
#
#####################################

LOGMSG="logger -puser.alert -s "

trap 'exit' 1 2 3

# for script tracing
case $ORACLE_TRACE in
  T) set -x ;;
esac

# Set path if path not set (if called from /etc/rc)
SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ; export PATH
SAVE_LLP=$LD_LIBRARY_PATH

# First argument is used to bring up Oracle Net Listener
ORACLE_HOME_LISTNER=$ORACLE_HOME
if [ ! $ORACLE_HOME_LISTNER ] ; then

 

3、將dbstart加入開機自啟動,修改/etc/rc.d/rc.local檔案

[root@test-1 ~]# vi /etc/rc.d/rc.local

  在最後新增su - oracle -lc /syn/oracle/product/11.2.0/bin/dbstart,並儲存。(按oracle實際路徑填寫)

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

su - oracle -lc /syn/oracle/product/11.2.0/bin/dbstart

4、給/etc/rc.d/rd.local檔案新增可執行許可權(centos7中為了安全預設取消了該檔案的可執行許可權)

[root@xydykt-1 ~]# chmod u+x /etc/rc.d/rc.local

5、重啟伺服器後,oracle資料庫及監聽均已成功啟動