分类: Oracle
2009-07-12 14:24:25
修改系统配置文件/etc/oratab
/etc/oratab 格式为: SID:ORACLE_HOME:AUTO
把AUTO域设置为Y(大写),只有这样,oracle 自带的dbstart和dbshut才能够发挥作用。我的为:
$ORACLE_SID:$ORACLE_HOME:Y
这儿的ORACLE_SID和ORACLE_HOME是oracle用户下的环境变量,在不同的电脑上有不同的值.当你打开/etc/oratab的时候,修改一下就行了.
编写服务脚本
在/etc/rc.d/init.d目录下创建oracle文件作为启动脚本,内容如下:
#!/bin/bash
#chkconfig:2345 50 10
#description:启动及停止 Oracle 和监听程序
# /etc/rc.d/init.d/oracle
# 检查如何执行脚本文件
case "$1" in
start)
echo -n "Starting Oracle Databases: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - ora -c dbstart >> /var/log/oracle
echo "Done."
echo -n "Starting Oracle Listeners: "
su - ora -c "lsnrctl start" >> /var/log/oracle
#su - oracle "sqlplus /nolog" <
#connect /as sysdba
#startup
#exit
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
stop)
echo -n "Shutting Down Oracle Listeners: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Shutting Down Oracle Databases as part of system down." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - ora -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo -n "Shutting Down Oracle Databases: "
su - ora -c dbshut >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
;;
restart)
echo -n "Restarting Oracle Databases: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Restarting Oracle Databases as part of system up." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - ora -c dbstop >> /var/log/oracle
su - ora -c dbstart >> /var/log/oracle
echo "Done."
echo -n "Restarting Oracle Listeners: " #$0 stop
su - ora -c "lsnrctl stop" >> /var/log/oracle #$0 start
su - ora -c "lsnrctl start" >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac
在oracle用户下输入如上的内容,然后保存退出,由于是启动脚本,需要执行权限;执行命令chmod a+x oracle授予oracle执行权限.
建立服务连接
ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc2.d/S50oracle
ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc3.d/S50oracle
ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc5.d/S50oracle
ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc0.d/K10oracle
ln -s /etc/rc.d/init.d/oracle /etc/rc.d/rc6.d/K10oracle
chkconfig --add oracle(添加到系统服务)
chkconfig --levle 2345 oracle on(随系统启动)
运行./oracle start (service oracle start)命令,看是否能启动数据库,如果不能,查看日志,查找原因
我在执行得时候遇到了如下得错误信息
Can''t find init file for Database "linuxdb".
Database "linuxdb" NOT started.
通过查看${ORACLE_HOME}/bin/dbstart中的脚本,根据错误信息查找到语句,得知系统中缺少
${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora配置文件
解决办法
sqlplus "/as sysdba"
create pfile from spfile;
然后再执行就成功了.
重新启动linux主机,看数据库是否自动启动了.
注:oracle自带的dbstart脚本中含有启动Listeners的脚本,所以我认为应该把上面的脚本中的启动listeners的语句去掉,否则会报错,但是这个错误不影响启动的。