CENTOS7下设置oracle 11g自启动

CENTOS7下设置oracle 11g自启动

十月 22, 2018

修改oratab文件

以root身份进入系统,通过vi命令打开文件

1
vi /etc/oratab

进入vi编辑器后,找到“orcl:/oracle/app/product/11.2.0/dbhome_1:N”,改为“orcl:/oracle/app/product/11.2.0/dbhome_1:Y”。修改完成后,保存退出vi

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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::
#
# 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.
#
#
#orcl11g:/oracle/app/oracle/product/11.2.0/db_1:N
orcl11g:/u01/app/oracle/product/11.2.0/dbhome_1:Y

键入命令“vi /etc/rc.d/rc.local”
在vi编辑器中,添加:

1
2
su oracle -lc "/u01/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start"
su oracle -lc "/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart"

新建Oracle服务启动脚本

1
vim /etc/init.d/oracle

新建一个以oracle命名的文件,并将以下脚本代码复制到文件里

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/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=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_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

保存退出

在/etc新建oratab

1
2
cd /etc
vi oratab

添加如下内容:

1
orcl:/oracle/app/product/11.2.0/dbhome_1:Y

保存后退出。

检查一下脚本能否正确执行

1
2
3
cd /etc/rc.d/init.d
./oracle start
./oracle stop

加入自动启动行列

执行如下命令:

1
2
3
4
5
6
chmod 750 /etc/rc.d/init.d/oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc0.d/K61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc2.d/S61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc3.d/S61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc4.d/S61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc6.d/K61oracle

linux