ORACLE设置自启动记录

设置开机自启动
1. 修改Oracle系统配置文件:/etc/oratab,只有这样,Oracle 自带的dbstart和dbshut才能够发挥作用。
[root@hailiang ~]# vi /etc/oratab
VDEDU:/u01/app/oracle/product/11.2.4/dbhome_1:Y

2. 在 /etc/init.d/ 下创建文件oracle,内容如下:
[root@hailiang ~]# vi /etc/init.d/oracle
#!/bin/sh
# chkconfig: 35 80 10
# description: Oracle auto start-stop script.
#
# 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=/u01/app/oracle/product/11.2.4/dbhome_1
ORA_OWNER=oracle
LOGFILE=/var/log/oracle.log
echo "#################################" >> ${LOGFILE}
date +"### %T %a %D: Run Oracle" >> ${LOGFILE}
if [ ! -f ${ORA_HOME}/bin/dbstart ] || [ ! -f ${ORA_HOME}/bin/dbshut ]; then
echo "Error: Missing the script file ${ORA_HOME}/bin/dbstart or ${ORA_HOME}/bin/dbshut!" >> ${LOGFILE}
echo "#################################" >> ${LOGFILE}
exit
fi
start(){
echo "###Startup Database..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}"
echo "###Done."
echo "###Run database control..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl start dbconsole"
echo "###Done."
}
stop(){
echo "###Stop database control..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl stop dbconsole"
echo "###Done."
echo "###Shutdown Database..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbshut ${ORA_HOME}"
echo "###Done."
}
case "$1" in
'start')
start >> ${LOGFILE}
;;
'stop')
stop >> ${LOGFILE}
;;
'restart')
stop >> ${LOGFILE}
start >> ${LOGFILE}
;;
esac
date +"### %T %a %D: Finished." >> ${LOGFILE}
echo "#################################" >> ${LOGFILE}
echo ""

3.改变文件权限
[root@hailiang ~]# chmod 755 /etc/init.d/oracle

4.添加服务
[root@hailiang ~]# chkconfig --level 35 oracle on

5.需要在关机或重启机器之前停止数据库,做一下操作
[root@hailiang ~]# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle
[root@hailiang ~]# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle

6.重新启动
[root@hailiang ~]#reboot

原文地址:https://www.cnblogs.com/kawashibara/p/8686390.html