設(shè)置開(kāi)機(jī)(Linux)自動(dòng)啟動(dòng)Oracle關(guān)機(jī)自動(dòng)關(guān)閉Oracle
1、切換到root用戶(hù)下,確認(rèn)啟動(dòng)文件和關(guān)閉文件是存在
[oracle@oracle3 bin]$ pwd
/u01/oracle/product/10.2.0/db_1/bin
[oracle@oracle3 bin]$ ls dbstart
dbstart --sqlplus執(zhí)行startup的時(shí)候調(diào)用的腳本
[oracle@oracle3 bin]$ ls dbshut
dbshut --sqlplus執(zhí)行shutdown的時(shí)候調(diào)用的腳本
2、修改oratab文件
[oracle@oracle3 etc]$ vim /etc/oratab
ORCL:/u01/oracle/product/10.2.0/db_1:Y --將N改為Y
3、測(cè)試啟動(dòng)文件和關(guān)閉文件的正確性
/u01/oracle/product/10.2.0/db_1/bin
[oracle@oracle3 bin]$ export ORACLE_SID=ORCL
[oracle@oracle3 bin]$ dbshut
[oracle@oracle3 bin]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jun 5 16:23:12 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected to an idle instance. --數(shù)據(jù)庫(kù)是關(guān)閉的
注意: conn /as sysdba = conn sys/orcl as sysdba
SQL> conn sys/orcl as sysdba
Connected to an idle instance. --連接到一個(gè)空閑的例程表示數(shù)據(jù)庫(kù)沒(méi)有啟動(dòng)
SQL> conn sys/orcl@ORCL as sysdba
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
Warning: You are no longer connected to ORACLE. --因?yàn)閿?shù)據(jù)庫(kù)關(guān)閉了,是無(wú)法用監(jiān)聽(tīng)器訪問(wèn)的,僅僅可以以sysdba的身份連接而已。
不管進(jìn)行什么操作,都必須連接一下,用sysdba的身份登錄校驗(yàn)操作系統(tǒng)的密碼文件。
[oracle@oracle3 bin]$ dbstart --測(cè)試啟動(dòng)文件是可用的
Failed to auto-start Oracle Net Listene using /ade/vikrkuma_new/oracle/bin/tnslsnr
Processing Database instance "ORCL": log file /u01/oracle/product/10.2.0/db_1/startup.log
[oracle@oracle3 bin]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jun 5 16:30:35 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected. --
4、編寫(xiě)一段shell腳本
[root@oracle3 ~]# cd /etc/rc.d/init.d
[root@oracle3 init.d]# touch start_shut
[root@oracle3 init.d]# vi start_shut
----------------------------------------------
#!/bin/sh
OPT_=$1
case "$OPT_" in
start)
/bin/echo "$0 : (start)"
#
# your service startup command goes here
#
su - oracle -c "/u01/oracle/product/10.2.0/db_1/bin/lsnrctl start"
su - oracle -c "/u01/oracle/product/10.2.0/db_1/bin/dbstart"
# NOTE:Must exit with zero unless error is server
chmod 1777 /tmp
chown sys:sys /tmp
exit 0
;;
stop)
/bin/echo "$ : (stop)"
#
# your service shutdown command goes here.
#
su - oralce -c "/u01/oracle/product/10.2.0/db_1/bin/dbshut"
su - oracle -c "/u01/oracle/product/10.2.0/db_1/bin/lsnrctl stop"
#Note: Must exit with zero unless error is server
exit 0
;;
*) /bin/echo ''
/bin/echo "Usage: $0[start|stop]"
/bin/echo "Invalid argument ==>\"${OPT_}\""
/bin/echo ''
exit 0
;;
esac
----------------------------------------------------------------------------------
5、修改權(quán)限
[root@oracle3 init.d]# chmod 755 start_shut
6、將文件鏈接到啟動(dòng)區(qū)域和關(guān)閉區(qū)域
[root@oracle3 init.d]# cd /etc/rc5.d
[root@oracle3 rc5.d]# ln -s /etc/rc.d/init.d/start_shut S99start_shut
[root@oracle3 rc5.d]# cd /etc/rc0.d
[root@oracle3 rc0.d]# ln -s /etc/rc.d/init.d/start_shut K01start_shut
7、測(cè)試:
init 6
創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)興寧,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢(xún)建站服務(wù):18980820575