Linux下oracle設定開機自啟動的方法

來源:互聯網
上載者:User

方法1)、添加以下指令碼到/etc/rc.d/rc.local 或/etc/rc.d/rc

#設定環境變數
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/9204
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH
export ORACLE_OWNER=oracle
export ORACLE_SID=TEST
export ORACLE_TERM=xterm
export LD_ASSUME_KERNEL=2.4.19
export THREADS_FLAG=native
export LD_LIBRARY_PATH=/opt/oracle/product/9204/lib:$LD_LIBRARY_PATH
export PATH=/opt/oracle/product/9204/bin:$PATH

export DISPLAY=:0
#使用帳戶名稱oracle登入啟動oracle
oracle_user=oracle

# 啟動監聽和資料庫

su - "$oracle_user"<< EOO
lsnrctl start
sqlplus /nolog<<EOS
#使用dba帳戶 system登入 connect system(此為帳戶名稱)/system(帳戶密碼) as sysdba
connect system/system as sysdba
startup
EOS
EOO

ps:也可以把上面的指令碼放到一個檔案裡,然後在rc.local加入調用的語句。

方法2)、載入為服務自啟動、停止

步驟1:在/etc/rc.d/init.d 目錄添加一啟動指令碼,如oracleservice,指令碼如下

#!/bin/sh
#
#name:/etc/rc.d/init.d/oracleservice
# chkconfig: 345 99 99
# description: 啟動、停止oracle資料庫和監聽控製程序
# 註:上面兩行是必須,不明的可以參考chkconfig相關資料
# oracle environment

export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/9204
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH
export ORACLE_OWNER=oracle
export ORACLE_SID=TEST
export ORACLE_TERM=xterm
export LD_ASSUME_KERNEL=2.4.19
export THREADS_FLAG=native
export LD_LIBRARY_PATH=/opt/oracle/product/9204/lib:$LD_LIBRARY_PATH
export PATH=/opt/oracle/product/9204/bin:$PATH

export DISPLAY=:0

oracle_user=oracle

case "$1" in
start)

# 啟動監聽控製程序和資料庫

su - "$oracle_user"<< EOO
lsnrctl start
sqlplus /nolog<<EOS
connect system/system as sysdba
startup
EOS
EOO
;;

stop)

# 停止監聽控製程序和資料庫

su - "$oracle_user"<<EOO
lsnrctl stop
sqlplus /nolog<<EOS
connect     system/system as sysdba
shutdown immediate

EOS
EOO
;;

*)
;;

esac
#--指令碼結束
#從指令碼裡可以得知,此指令碼通過參數start或stop來啟動、停止資料庫和監聽控製程序

步驟2:

更改許可權,設定為可運行,在shel視窗中輸入:
# chmod +x /etc/rc.d/init.d/oracleservice

步驟3:把oracleservice添加到服務裡

# chkconfig –add /etc/rc.d/init.d/oracleservice

查看自動啟動設定是否成功:
# chkconfig –list oracleservice
oracleservice     0:關閉     1:關閉     2:關閉     3:開啟     4:開啟     5:開啟     6:關閉
*從上面可以看出level為345的都已經開啟了,配置成功!

步驟4:重啟檢查oracle自啟動是否成功。

方法3)、使用oracle本身的dbstart指令碼,位置$ORACLE_HOME/bin/dbstart
看網上介紹,使用dbstart是需要修改/etc/oratab把裡面設定的最後一項設定為Y,如:
TEST:/opt/oracle/product/9204:N,更改為TEST:/opt/oracle/product/9204:Y

使用dbstart方式還沒空嘗試,有空再試試

/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:
# $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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.