一聚教程网:一个值得你收藏的教程网站

热门教程

Linux下oracle自启动设置的方法介绍

时间:2022-06-29 09:53:13 编辑:袖梨 来源:一聚教程网


涉及的文件有:
/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 < startup;
exit;
EOF
"

设置权限:

chmod 755 /home/oracle.sh

设置启动:

vim /etc/rc.local

加入:

/home/oracle.sh

热门栏目