Oracle提供了伴随作業系統自動重新開機的功能,在Windows中,可以修改“我的電腦-->管理-->服務-->OracleService$ORACLE_SID”,或直接使用Win+R鍵打開運作視窗,輸入services.msc即可打開服務,找到相應的Oracle服務,然後将其屬性中的啟動類型修改成自動。一般在Windows系統上安裝完後會自動設定成自動。

對于Linux/Unix作業系統,如果想設定自動重新開機,那該如何操作呢?對此Oracle提供了dbstart指令用于啟動,可以有2種方法來配置。
1. 修改/etc/oratab
[root@oracle ~]#vim /etc/oratab
orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y #将N改為Y
檔案/etc/oratab由root.sh腳本建立,在用DBCA建立執行個體時也會更新這個檔案。當$ORACLE_SID:$ORACLE_HOME:設定為Y時,允許執行個體自啟動,當設定為N時,則不允許自啟動。這個檔案裡的配置僅僅起一個開關的作用,其并不會具體的執行啟動和關閉,具體的操作由$ORACLE_HOME/bin/dbstart和dbshut腳本來實作。這2個腳本在執行時會檢查/etc/oratab檔案裡的配置,為Y時才能繼續執行。
2. 修改$ORACLE_HOME/bin/dbstart和$ORACLE_HOME/bin/dbshut
[root@oracle ~]#vim
$ORACLE_HOME/bin/dbstart
$ORACLE_HOME/bin/dbshut
ORACLE_HOME_LISTNER=$ORACLE_HOME ($1改為$ORACLE_HOME)
ORACLE_HOME_LISTNER的位置:Oracle 11g的dbstart在第80行,dbshut檔案中在第50行。
3. 建立啟動腳本
使用root使用者建立腳本:
/etc/rc.d/init.d/oracle
#!/bin/bash
#
chkconfig: 2345 99 10
description: Startup Script for oracle Databases
export
ORACLE_BASE=/u01/app/oracle/
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
PATH=$PATH:$ORACLE_HOME/bin
ORACLE_UNQNAME=PROD1
echo "
" >> /var/log/oraclelog
echo
`date +'%Y-%m-%d %H:%M:%S'` >> /var/log/oraclelog
case
"$1" in
start)
"-----startup oracle-----" >> /var/log/oraclelog
su oracle -c
"$ORACLE_HOME/bin/dbstart"
"$ORACLE_HOME/bin/emctl start dbconsole"
touch /var/lock/subsys/oracle
"-----startup oracle successful-----" >> /var/log/oraclelog
"OK"
;;
stop)
"-----shutdown oracle-----" >> /var/log/oraclelog
"$ORACLE_HOME/bin/dbshut"
"$ORACLE_HOME/bin/emctl stop dbconsole"
rm -f
/var/lock/subsys/oracle
`date +'%Y-%m-%d %H:%M:%S'` >> /var/log/oraclelogg
"-----shutdown oracle successful-----" >> /var/log/oraclelog
restart)
touch
*)
"Usage: 'basename $0' start|stop|restart"
exit 1
esac
exit 0
4. 給腳本設定權限
[root@oracle
~]# chmod 755 /etc/rc.d/init.d/oracle
5. 建立服務
~]# chkconfig --add oracle
~]# chkconfig oracle on
~]# chkconfig --list oracle
oracle 0:off 1:off
2:on 3:on
4:on 5:on 6:off
6. 檢查是否生效
先使用root使用者測試服務是否生效:
[root@edsir4p1
~]# service oracle stop
~]# service oracle start
~]# service oracle restart
再重新開機OS,驗證是否生效。
使用service測試:
Processing
Database instance "PROD1": log file
/u01/app/oracle/product/11.2.0/dbhome_1/shutdown.log
Database instance "PROD2": log file
Oracle
Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright
(c) 1996, 2009 Oracle Corporation. All
rights reserved.
https://edsir4p1.us.oracle.com:1158/em/console/aboutApplication
Stopping
Oracle Enterprise Manager 11g Database Control ...
...
Stopped.
OK
/u01/app/oracle/product/11.2.0/dbhome_1/startup.log
Starting
Oracle Enterprise Manager 11g Database Control ..... started.
------------------------------------------------------------------
Logs are
generated in directory
/u01/app/oracle/product/11.2.0/dbhome_1/edsir4p1.us.oracle.com_PROD1/sysman/log
2. 修改$ORACLE_HOME/bin/dbstart和$ORACLE_HOME/bin/dbshut
将以下腳本添加到/etc/rc.d/rc.local或/etc/rc.local檔案中(/etc/rc.local是/etc/rc.d/rc.local的軟連接配接檔案):
su
oracle -c $ORACLE_HOME/bin/dbstart
oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"
若環境中沒有建立EM,則可以不用添加ORACLE_UNQNAME,和emctl這2行。
需要注意的是,/etc/rc.local是/etc/rc.d/rc.local的軟連接配接檔案,如下所示:
[oracle@edsir4p1-PROD1 ~]$ ll /etc/rc.local
lrwxrwxrwx 1 root root 13 Aug 31 2013 /etc/rc.local -> rc.d/rc.local
[oracle@edsir4p1-PROD1 ~]$ ll /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 401 Jan 2 03:51 /etc/rc.d/rc.local
需要注意的是,在CentOS7中,/etc/rc.d/rc.local的權限被降低了,是以需要執行如下指令賦予其可執行權限
chmod +x /etc/rc.d/rc.local
4. 檢查是否生效
~]# export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
~]# su oracle -c $ORACLE_HOME/bin/dbstart
對于這2種方法,需要注意的幾個問題:
1. 多個執行個體都會自動重新開機。
2. 監聽也會自動重新開機。
3. 重新開機的詳細日志為:$ORACLE_HOME/shutdown.log和$ORACLE_HOME/startup.log。
4. oracle使用者的環境變量可以不用配置。
5. ORACLE_UNQNAME的作用是設定EM的環境變量,emctl是啟動OEM,若沒有則可以不用設定。
6. ORACLE_HOME的作用是設定資料庫監聽的環境變量。
7. 對于ASM、RAC環境,隻需要将資料庫資源注冊的CRS中,即可實作開機啟動。
About Me ............................................................................................................................................. ● 本文作者:小麥苗,部分内容整理自網絡,若有侵權請聯系小麥苗删除 ● QQ群号:230161599(滿)、618766405 ● 微信群:可加我微信,我拉大家進群,非誠勿擾 ● 聯系我請加QQ好友(646634621),注明添加緣由 ● 于 2018-01-01 06:00 ~ 2018-01-31 24:00 在魔都完成 ● 文章内容來源于小麥苗的學習筆記,部分整理自網絡,若有侵權或不當之處還請諒解 ● 版權所有,歡迎分享本文,轉載請保留出處![]()
如何讓oracle DB、監聽和oem開機啟動(dbstart) 如何讓oracle DB、監聽和oem開機啟動(dbstart) ![]()
如何讓oracle DB、監聽和oem開機啟動(dbstart) 如何讓oracle DB、監聽和oem開機啟動(dbstart) ![]()
如何讓oracle DB、監聽和oem開機啟動(dbstart) 如何讓oracle DB、監聽和oem開機啟動(dbstart) 小麥苗的微信公衆号 小麥苗的DBA寶典QQ群2 《DBA筆試面寶典》讀者群 小麥苗的微店 <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=646634621&site=qq&menu=yes"></a>![]()
如何讓oracle DB、監聽和oem開機啟動(dbstart) 如何讓oracle DB、監聽和oem開機啟動(dbstart) ![]()
如何讓oracle DB、監聽和oem開機啟動(dbstart) 如何讓oracle DB、監聽和oem開機啟動(dbstart) ![]()
如何讓oracle DB、監聽和oem開機啟動(dbstart) 如何讓oracle DB、監聽和oem開機啟動(dbstart) ![]()
如何讓oracle DB、監聽和oem開機啟動(dbstart) 如何讓oracle DB、監聽和oem開機啟動(dbstart) ![]()
如何讓oracle DB、監聽和oem開機啟動(dbstart) 如何讓oracle DB、監聽和oem開機啟動(dbstart)