轉自:http://blog.csdn.net/snakemyy/article/details/8668888
安裝完畢Oracle 11g每次都得手動啓動 | 停止數據庫(dbstart | dbshut)、監聽器(lsnrctl)、控制檯(emtcl)。
設置一下,若手動啓動數據庫的同時監聽器沒有啓動(即啓動數據庫時自動啓動監聽器,停止數據庫時停止監聽器),則需要修改dbstart腳本文件:
1
2
|
[oracle@localhost
~]$ cd /u01/app/oracle/product/11.1.0/db_1/bin/ [oracle@localhost
~]$ vi dbstart |
找到下面的代碼段:
1
2
3
4
5
6
7
8
|
#
First argument is used to bring up Oracle Net Listener ORACLE_HOME_LISTNER=$1
###
需要將此處的 ORACLE_HOME_LISTNER=$1 修改爲 ORACLE_HOME_LISTNER=$ORACLE_HOME if
[ ! $ORACLE_HOME_LISTNER ] ; then echo
"ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener" echo
"Usage: $0 ORACLE_HOME" else LOG=$ORACLE_HOME_LISTNER/listener.log |
同樣,修改dbshut:
1
2
3
4
5
6
7
8
9
10
|
[oracle@localhost
~]$ vi dbshut #
The this to bring down Oracle Net Listener ORACLE_HOME_LISTNER=$1 ###
需要將此處的 ORACLE_HOME_LISTNER=$1 修改爲 ORACLE_HOME_LISTNER=$ORACLE_HOME if
[ ! $ORACLE_HOME_LISTNER ] ; then echo
"ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener" echo
"Usage: $0 ORACLE_HOME" else LOG=$ORACLE_HOME_LISTNER/listener.log |
完成後配置Linux啓動腳本oracle,內容如下:
1
2
|
[oracle@localhost
bin]$ cd /etc/init.d/ [oracle@localhost
init.d]$ vi 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
41
42
43
44
45
46
|
#!/bin/sh #
chkconfig: 345 61 61 #
description: Oracle 11g AutoRun Services #
/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.1.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 |
賦予腳本可執行權限:
1
|
[oracle@localhost
init.d]$ chmod 750 /etc/init.d/oracle |
建立鏈接:
1
2
|
[oracle@localhost
init.d]$ ln -s /etc/init.d/oracle /etc/rc1.d/K61oracle [oracle@localhost
init.d]$ ln -s /etc/init.d/oracle /etc/rc3.d/S61oracle |
啓用腳本並添加到服務:
1
2
|
[oracle@localhost
init.d]$ chkconfig --level 345 oracle on [oracle@localhost
init.d]$ chkconfig --add oracle |
注意:
這樣的腳本一般不會啓動實例,如果想讓實例也隨腳本一起啓動的話,就需要修改文件/etc/oratab
如果這個文件不存在,就要運行腳本文件產生它。
1
|
[root@localhost
init.d]# $ORACLE_HOME/root.sh |
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:< 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:/u01/app/oracle/product/11.1.0/db_1:Y |
可以看出,實例orcl是自動啓動的(標識爲Y),只要在這裏配置好,再配合上面的腳本,即可實現自動啓動。