一、修改 Oracle 的系统配置文件 /etc/oratab:
/etc/oratab 的格式为:SID:ORACLE_HOME:AUTO,把 AUTO 域的值改为 Y。
二、编写服务脚本
这个脚本放到 /etc/rc.d/init.d 目录下:
内容参考如下:
#!/bin/sh
# chkconfig: 35 68 42
# description: Oracle
ORACLE_HOME=/data/oracle/app/oracle/product/11.2.0/dbhome_1
ORACLE_OWNER=oracle
if [ ! -f ${ORACLE_HOME}/bin/dbstart ] || [ ! -f ${ORACLE_HOME}/bin/dbshut ]; then
echo "Error: Missing the script file ${ORACLE_HOME}/bin/dbstart or ${ORACLE_HOME}/bin/dbshut."
exit 1
fi
db_start(){
echo "Starting Oracle Listener ..."
su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/lsnrctl start"
echo "Done."
echo "Starting Oracle Database ..."
su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/dbstart ${ORACLE_HOME}"
echo "Done."
echo "Starting database control ..."
su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/emctl start dbconsole"
echo "Done."
}
db_stop(){
echo "Stopping database control ..."
su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/emctl stop dbconsole"
echo "Done."
echo "Stopping Oracle Database ..."
su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/dbshut ${ORACLE_HOME}"
echo "Done."
echo "Stopping Oracle Listener ..."
su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/lsnrctl stop"
echo "Done."
}
case "$1" in
start)
db_start
;;
stop)
db_stop
;;
restart)
db_stop
sleep 2
db_start
;;
esac
exit 0
三、改变文件权限
四、添加服务
五、需要在关机或重启机器之前停止数据库
[root@RicenOS ~]# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle
Copyright © 2005-2023 by www.ricensoftwares.com.cn All Rights Reserved.