1.修改/var/opt/oracle/oratab文件,后面的dbstart和dbshut依据这个文件启动数据库:

orcl:/opt/oracle/product/10.2:Y

2.修改$ORACLE_HOME/bin/dbstart和$ORACLE_HOME/bin/dbshut文件:

vi dbstart

#ORACLE_HOME_LISTNER=$1
ORACLE_HOME_LISTNER=/opt/oracle/product/10.2
export ORACLE_HOME_LISTNER

vi dbshut

#ORACLE_HOME_LISTNER=$1
ORACLE_HOME_LISTNER=/opt/oracle/product/10.2
export ORACLE_HOME_LISTNER

3.修改完毕后用看看oracle用户能否执行这两个文件,我的dbshut没问题,但是执行dbstart不行:

查看/opt/oracle/product/10.2/listener.log的权限:

原来是oracle用户没有写入listener的权限,赋予相应权限即可:
chown oracle:dba /opt/oracle/product/10.2/listener.log
执行后成功。

4.接下来在/etc/init.d下建立系统自动启动和关机前自动关闭Oracle的脚本文件,分别如下:

vi start_oracle.sh(开机后启动oracle数据库脚本):

#!/usr/bin/bash
#this script is used to start the oracle
su - oracle -c " /opt/oracle/product/10.2/bin/dbstart"

chmod a+x /etc/init.d/start_oracle.sh

vi stop_oracle.sh(关机前停止oracle数据库脚本):

#!/usr/bin/bash
#this script is used to stop the oracle
su - oracle -c " /opt/oracle/product/10.2/bin/dbshut"

chmod a+x /etc/init.d/stop_oracle.sh

5.创建随系统启动和关闭的链接:

在/etc/rc2.d下加入自动启动链接,命令如下:

ln -s /etc/init.d/start_oracle.sh /etc/rc2.d/S97start_oracle

在/etc/rc0.d下加入自动关闭链接,命令如下:

ln -s /etc/init.d/stop_oracle.sh /etc/rc0.d/K01stop_oracle


设置完毕,可以重启看看效果了。

-bash-3.00$ reboot

-bash-3.00$ ps -ef | grep ora
oracle 626 1 0 19:22:06 ? 0:00 ora_q000_orcl
oracle 490 1 0 19:21:40 ? 0:01 ora_pmon_orcl
oracle 494 1 0 19:21:40 ? 0:00 ora_mman_orcl
oracle 533 1 0 19:22:01 ? 0:02 ora_j000_orcl
oracle 492 1 0 19:21:40 ? 0:00 ora_psp0_orcl
oracle 401 1 0 19:21:27 ? 0:00 /opt/oracle/product/10.2/bin/tnslsnr LISTENER -inherit
oracle 496 1 0 19:21:41 ? 0:01 ora_dbw0_orcl
oracle 498 1 0 19:21:41 ? 0:01 ora_lgwr_orcl
oracle 500 1 0 19:21:41 ? 0:03 ora_ckpt_orcl
oracle 502 1 0 19:21:41 ? 0:02 ora_smon_orcl
oracle 504 1 0 19:21:41 ? 0:00 ora_reco_orcl
oracle 506 1 0 19:21:42 ? 0:01 ora_cjq0_orcl
oracle 508 1 0 19:21:42 ? 0:02 ora_mmon_orcl
oracle 510 1 0 19:21:42 ? 0:01 ora_mmnl_orcl
oracle 512 1 0 19:21:42 ? 0:00 ora_d000_orcl
oracle 514 1 0 19:21:43 ? 0:00 ora_s000_orcl
oracle 518 1 0 19:21:56 ? 0:00 ora_qmnc_orcl
oracle 635 1 0 19:22:07 ? 0:00 ora_q001_orcl
hrj 738 726 0 19:32:34 pts/2 0:00 grep ora

启动成功!