首先在/etc/init.d/目錄下配置Oracle的服務文件.
touch oracle10g
chmod a+x oracle10g
然後編輯此oracle10g文件.內容如下.
下載: oracle10g
# !/bin/bash
# whoami
# root
# chkconfig: 345 51 49
# /etc/init.d/oracle10g
# description: starts the oracle dabase deamons
#
ORA_HOME=/oracle/product/10.2.0/db_1/
ORA_OWNER=oracle
case "$1" in
start)
echo -n "Starting oracle10g: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" &
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
touch /var/lock/subsys/oracle10g
echo
;;
stop)
echo -n "shutting down oracle10g: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" &
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
rm -f /var/lock/subsys/oracle10g
echo
;;
restart)
echo -n "restarting oracle10g: "
$0 stop
$0 start
echo
;;
*)
echo "Usage: `basename $0` start|stop|restart"
exit 1
esac
exit 0
保存文件,退出以後,添加並啓動察看服務.
/sbin/chkconfig --add oracle10g
/sbin/chkconfig --list oracle10g
重新啓動Linux的時候,如果看到啓動項Oracle出現OK,代表Oracle成功隨Linux啓動了.
注意:
這樣的腳本啓動一般不會啓動實例,如果想讓實例也隨腳本一起啓動的話,就需要修改文件:/etc/oratab
如果這個文件不存在,那麼就得運行腳本文件產生它.ex:
sh /oracle/product/10.2.0/db_1/root.sh
比如我的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.
#
#
orcl:/oracle/product/10.2.0/db_1:N
xok:/oracle/product/10.2.0/db_1:Y
看設置,可以看出實例 xok 是自動啓動的(表識是Y),而orcl的表識是N,則不啓動.只要在這裏設置好後,在配合上面的腳本,即可實現開機自動啓動oracle以及實例了.
本文來自: E點廢墟(http://www.xok.la/) 詳細出處參考:http://xok.la/2008/11/linux_oracle_10g_instance_auto_start.html