我在设置开机启动oracle的时候使用的dbstarte
因为使用dbstart的时候需要用到linux下的/etc/oratab 文件如果没有此文件的话可以从
# This file is used by ORACLE utilities. It is created by root.sh # and updated by the Database Configuration Assistant when creating # a database. # A colon, ':', is used as the field terminator. A new line terminates # the entry. Lines beginning with a pound sign, '#', are comments. # # Entries are of the form: # $ORACLE_SID:$ORACLE_HOME:<N|Y>: # # The first and second fields are the system identifier and home # directory of the database respectively. The third filed indicates # to the dbstart utility that the database should , "Y", or should not, # "N", be brought up at system boot time. # # Multiple entries with the same $ORACLE_SID are not allowed. # # xxxx:/opt/app/oracle/product/10.2:Y
这里复制粘贴.
其中第一个冒号前面的是oracle的SID 设置为自己需要的SID
后面为ORACLE_HOME就是oracle在本机的安装路径这个路径必须和设置在/etc/profile的ORACLE_HOME相同
最后一个是是否使用dbstart启动
这个文件复制好以后
可以使用如下代码创建oratab
cd /etc/ vi oratab 复制上面的内容粘贴进去 然后输入:wq
保存成功以后这个步骤就算完成了
首先打开/etc/profile vi /etc/profile 在文件的最后面添加如下代码 export ORACLE_HOME="oracle的安装路径" export ORACLE_SID=orcl export PATH=$ORACLE_HOME/bin:$PATH
建立oracle的全局变量
然后在/etc/init.d 下面建立oracle的启动文件
cd /etc/init.d vi 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=/opt/app/oracle/product/10.2 ORA_OWNER=oracle if [ ! -f $ORA_HOME/bin/dbstart ] then echo "Oracle startup: cannot start" exit fi case "$1" in 'start') # Start the Oracle databases: echo "Starting Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle.log date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle.log echo "-------------------------------------------------" >> /var/log/oracle.log su - $ORA_OWNER -lc "$ORA_HOME/bin/dbstart" >> /var/log/oracle.log echo "Done" # Start the Listener: echo "Starting Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle.log date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle.log echo "-------------------------------------------------" >> /var/log/oracle.log su - $ORA_OWNER -lc "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle.log echo "Done." echo "-------------------------------------------------" >> /var/log/oracle.log date +" %T %a %D : Finished." >> /var/log/oracle.log echo "-------------------------------------------------" >> /var/log/oracle.log ;; 'stop') # Stop the Oracle Listener: echo "Stoping Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle.log date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle.log echo "-------------------------------------------------" >> /var/log/oracle.log su - $ORA_OWNER -lc "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle.log echo "Done." # Stop the Oracle Database: echo "Stoping Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle.log date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle.log echo "-------------------------------------------------" >> /var/log/oracle.log su - $ORA_OWNER -lc "$ORA_HOME/bin/dbshut" >>/var/log/oracle.log echo "Done." echo "" echo "-------------------------------------------------" >> /var/log/oracle.log date +" %T %a %D : Finished." >> /var/log/oracle.log echo "-------------------------------------------------" >> /var/log/oracle.log ;; 'restart') $0 stop $0 start ;; esac :wq
文件路径按照自己的需要需要修改一下
保存上面文件后
需要输入下面的命令
chmod -x oracle chkconfig --add oracle chkconfig --level 3 5 oracle on 上面命令是赋予oracle执行权限 把oracle添加在系统启动列表中 输入 chkconfig --list|grep oracle 可以查看是否添加成功
完成上面配置 基本就完成了oracle在centenos下面的开机启动了