root用户登录
1、 修改Oracle系统配置文件/etc/oratab
/etc/oratab 格式为: SID:ORACLE_HOME:AUTO
把AUTO域设置为Y(大写),只有这样,oracle 自带的dbstart和dbshut才能够发挥作用。
我的为:orcl216:/home/oracle/oracle/product/10.2.0/db_1:Y
2、 编写服务脚本:
保存在/etc/rc.d/init.d下
touch oracle
如下
#!/bin/bash
#
#################FUNCTION#############
#
# AutoStart Oracle and listener
# AutoStop Oracle and listener
#
#####################################
#
# Created by ZhouYS 2003-11-26
#
case "$1" in
start)
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databasee as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "dbstart" >> /var/log/oracle
echo "Done."
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -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
;;
stop)
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - oracle -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)
$0 stop
$0 start
;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac
将脚本命名为oracle,保存在/etc/rc.d/init.d下
改变文件属性:chmod 755 oracle
3、建立服务连接:
系统启动时启动数据库,我们需要以下连结∶
--------------------------------------------------------------------------------
$ ln -s ../init.d/oracle /etc/rc.d/rc2.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc3.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc5.d/S99oracle #rc4.d unused
--------------------------------------------------------------------------------
要在重新启动时停止数据库,我们需要以下连结∶
--------------------------------------------------------------------------------
$ ln -s ../init.d/oracle /etc/rc.d/rc0.d/K01oracle # 停止
$ ln -s ../init.d/oracle /etc/rc.d/rc6.d/K01oracle # 重新启动
--------------------------------------------------------------------------------
Linux中在Oracle安装完毕以后,如果重新启动Linux ,Oracle是不会自动启动的,
你可以通过手动调用dbstart命令来进行启 动,不过这样似乎也很繁琐。
我们可以通过配置Oracle的自动启动脚本,然后利用Linux的Service来启动Oracle服务器。
首先在/etc/rc.d/init.d/目录下配置Oracle的服务文件。
touch oracle10g
chmod a+x oracle10g
然后编辑此oracle10g文件。内容如下。
我自己配置的oracle10g自动启动文件。
注意:其中ORA_HOME需要根据自己的实际情况设置,其他的不需要变。
vi /etc/rc.d/init.d/oracle10g
# !/bin/bash
#whoami
# root
# chkconfig: 345 51 49
# description: starts the oracle dabase deamons
#
ORA_HOME=/home/app/oracle/product/10.2.0/db_1/
ORA_OWNER=oracle
case "$1" in
'start')
echo -n "Starting oracle10g: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" &
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" &
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole" &
su - $ORA_OWNER -c "$ORA_HOME/bin/isqlplusctl start"
touch /var/lock/subsys/oracle10g
echo
;;
'stop')
echo -n "shutting down oracle10g: "
su - $ORA_OWNER -c "$ORA_HOME/bin/isqlplusctl stop" &
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole" &
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" &
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
rm -f /var/lock/subsys/oracle10g
echo
;;
'restart')
echo -n "restarting oracle10g: "
$0 stop
$0 start
echo
;;
*)
echo "usage: oracle10g "
exit 1
esac
exit 0
保存文件,退出以后,添加并启动察看服务。
/sbin/chkconfig --add oracle10g
/sbin/chkconfig --list oracle10g
重新启动Linux的时候,如果看到启动项Oracle出现OK,代表Oracle成功随Linux启动了。