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数据库及监听均已成功启动

posted @ 2020-12-02 10:04  灿烂初秋  阅读(1028)  评论(0编辑  收藏  举报