1、修改oratab 文件,该文件的功能是控制Oracle的启动(dbstart)和关闭脚本(dbshut)是否可用。
[root@localhost etc]# vi /etc/oratab
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:
ORACLESID: O R A C L E S I D : 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/dbhome_1:N #把N修改成Y
2、修改oratab的访问权限
[root@localhost etc]# chmod 755 /etc/oratab
3、编写自动启停脚本,脚本名称“oracle”,该文件需要保存在/etc/rc.d/init.d目录中。vi /etc/rc.d/init.d/oracle
!/bin/bash
#
Script. Function: Auto start oracle instance and listener.
Script. Name: oracle
Author:
Date: 2015-11-13
#
case “
1”instart)echo“StartingOracleDatabase…”su−oracle−c“dbstart”echo“Done.”echo“StartingOracleListener…”su−oracle−c“lsnrctlstart”echo“Done.”touch/var/lock/subsys/oracle;;stop)echo“ShuttingdownOracleListener…”su−oracle−c“lsnrctlstop”>>/var/log/oracleecho“Done.”rm−f/var/lock/subsys/oracleecho“ShuttingdownOracleDatabase…”su−oracle−c“dbshut”echo“Done.”echo“”;;restart)
1
”
i
n
s
t
a
r
t
)
e
c
h
o
“
S
t
a
r
t
i
n
g
O
r
a
c
l
e
D
a
t
a
b
a
s
e
…
”
s
u
−
o
r
a
c
l
e
−
c
“
d
b
s
t
a
r
t
”
e
c
h
o
“
D
o
n
e
.
”
e
c
h
o
“
S
t
a
r
t
i
n
g
O
r
a
c
l
e
L
i
s
t
e
n
e
r
…
”
s
u
−
o
r
a
c
l
e
−
c
“
l
s
n
r
c
t
l
s
t
a
r
t
”
e
c
h
o
“
D
o
n
e
.
”
t
o
u
c
h
/
v
a
r
/
l
o
c
k
/
s
u
b
s
y
s
/
o
r
a
c
l
e
;
;
s
t
o
p
)
e
c
h
o
“
S
h
u
t
t
i
n
g
d
o
w
n
O
r
a
c
l
e
L
i
s
t
e
n
e
r
…
”
s
u
−
o
r
a
c
l
e
−
c
“
l
s
n
r
c
t
l
s
t
o
p
”
>>
/
v
a
r
/
l
o
g
/
o
r
a
c
l
e
e
c
h
o
“
D
o
n
e
.
”
r
m
−
f
/
v
a
r
/
l
o
c
k
/
s
u
b
s
y
s
/
o
r
a
c
l
e
e
c
h
o
“
S
h
u
t
t
i
n
g
d
o
w
n
O
r
a
c
l
e
D
a
t
a
b
a
s
e
…
”
s
u
−
o
r
a
c
l
e
−
c
“
d
b
s
h
u
t
”
e
c
h
o
“
D
o
n
e
.
”
e
c
h
o
“
”
;
;
r
e
s
t
a
r
t
)
0 stop
$0 start
;;
*)
exit 1
esac
4、修改oracle脚本的权限
chmod 755 oracle
5、建立连接文件
ln -s ../init.d/oracle /etc/rc.d/rc2.d/S87oracle
ln -s ../init.d/oracle /etc/rc.d/rc3.d/S87oracle
ln -s ../init.d/oracle /etc/rc.d/rc5.d/S87oracle
6、重新启动Linux系统后,Oracle的实例和监听自动启动。进行验证:
[root@localhost ~]# su - oracle #切换Oracle用户
[oracle@localhost ~]$ lsnrctl status #查看监听状态
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 17-AUG-2018 16:40:10
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 17-AUG-2018 16:33:58
Uptime 0 days 0 hr. 6 min. 11 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /data/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.184.130)(PORT=1521)))
Services Summary…
Service “orcl” has 2 instance(s).
Instance “orcl”, status UNKNOWN, has 1 handler(s) for this service…
Instance “orcl”, status READY, has 1 handler(s) for this service…
Service “orclXDB” has 1 instance(s).
Instance “orcl”, status READY, has 1 handler(s) for this service…
The command completed successfully
[oracle@localhost ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Fri Aug 17 16:41:15 2018
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select instance_name,status from v$instance; #查看数据库状态
INSTANCE_NAME
STATUS
orcl
OPEN