涉及的檔案有:
/etc/oratab
$ORACLE_HOME/bin下的兩個指令碼,dbstart和dbshut
編輯設定檔:
vim /etc/oratab
將:
orcl:/u01/oracle/product/10.2.0/db_1:N
改為:
orcl:/u01/oracle/product/10.2.0/db_1:Y
隨後最簡單的方法,在/etc/rc.local中加入:
su - oracle -c "/u01/oracle/product/10.2.0/db_1/bin/dbstart"
su - oracle -c "/u01/oracle/product/10.2.0/db_1/bin/lsnrctl start"
在/var/log/boot.log裡可以看到兩個命令的執行結果。
在/u01/oracle/product/10.2.0/db_1/startup.log裡可以看到dbstart的執行日誌。
當然也可以做一個啟動指令碼,把指令碼加到系統服務中:
做一個啟動指令碼 /etc/init.d/oracle,如下所示:
#!/bin/sh
# description: Oracle auto start-stop script.
# chkconfig: - 20 80
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/oracle/product/10.2.0/
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c $ORA_HOME/bin/dbstart
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
su - $ORA_OWNER -c $ORA_HOME/bin/dbshut
;;
'restart')
$0 stop
$0 start
;;
esac
賦予執行許可權
chmod 750 /etc/init.d/oracle
作成以下連結:
ln -s /etc/init.d/dbora /etc/rc0.d/K10dbora
ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora
執行以下命令:
chkconfig --level 345 oracle on
11xe版自啟動方法。
oracle 11xe版沒有提供啟動指令碼,大概是因為精簡的原因,只能自己寫了:
vim /home/oracle.sh
加入:
#!/bin/bash
su - oracle -c "
sqlplus / as sysdba <<EOF
startup;
exit;
EOF
"
設定許可權:
chmod 755 /home/oracle.sh
設定啟動:
vim /etc/rc.local
加入:
/home/oracle.sh