在CentOS7.3下设置Oracle11g随系统启动

目录

编辑oratab文件

编辑rc.local文件

新建Oracle服务启动脚本

测试


编辑oratab文件

#用root用户执行编辑

vi /etc/oratab

# 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::
#
# 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:/data/oracle/product/11.2.0/db_1:Y

#最后一行的N改成Y

编辑rc.local文件

#用root用户进行编辑操作

vim /etc/rc.d/rc.local

#!/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 -c '/data/oracle/product/11.2.0/db_1/bin/lsnrctl start'
su - oracle -c '/data/oracle/product/11.2.0/db_1/bin/dbstart'

#最后两行为添加内容

#给rc.local文件可执行权限
chmod +x /etc/rc.d/rc.local

新建Oracle服务启动脚本

#用root用户编辑操作

vim /etc/init.d/oracle


#!/bin/sh
# chkconfig: 345 61 61
# description: Oracle 11g R2 AutoRun Servimces
# /etc/init.d/oracle
#
# Run-level Startup script for the Oracle Instance, Listener, and
# Web Interface
export ORACLE_BASE=/data/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.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: cannot 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
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbstart
echo "Oracle Start Succesful!OK."
;;
stop)
# Oracle listener and instance shutdown
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbshut
echo "Oracle Stop Succesful!OK."
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo $"Usage: `basename $0` {start|stop|reload|reload}"
exit 1
esac
exit 0

#增加 oracle服务控制脚本执行权限
chmod +x /etc/rc.d/init.d/oracle

#将 oracle服务加入到系统服务
chkconfig --add  oracle

#检查 oracle服务是否已经生效
chkconfig --list  oracle

此命令:chkconfig --list oracle执行后如下图所示:

在CentOS7.3下设置Oracle11g随系统启动_第1张图片

测试

reboot重启进行测试

你可能感兴趣的:(Oracle专栏)