您的位置:首页 > 数据库 > Oracle

Oracle使用DBSTART开机启动

2015-11-17 11:50 941 查看

记录Oracle使用DBSTART启动的问题

记录Oracle使用DBSTART启动的问题
出问题的原因

使用dbstart设置oracle开机启动
oratab讲解

创建oratab文件

在etcprofile里面添加ORACLE_HOME

在etcinitd 下面建立oracle的启动文件

出问题的原因

开发完成后,项目需要部署到生成环境进行测试的时候就需要搭建生产环境.

在生产环境CenterOs下搭建完环境,有一些东西就需要开机启动,例如oracle

这个时候就需要配置oracle开机启动了.防止以后使用中突然断电,需要手动启动oracle

使用dbstart设置oracle开机启动

因为使用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


复制过去.

文中打#的都是注释.可以自己阅读一下

oratab讲解

xxxx:/opt/app/oracle/product/10.2:Y


这句话的主要作用就是配置ORACLE的SID和PATH了,就是我个人理解的实列名和安装路径.

第一个:前面是配置实例名(SID).

中间这个:是ORACLE_HOME,这个地方配置有一点需要注意的就是他的路径必须和/etc/profile里面的ORACLE_HOME这个相同,不然配置无效,路径找不到.

最后一个:Y或者N 是配置是否使用dbstart启动oracle.

创建oratab文件

把上面的内容复制后:

cd /
cd etc/
vi oratab
按下i键
把内容复制进去
:wq


保存成功后这个步奏就算完成了

在etc/profile里面添加ORACLE_HOME

首先打开/etc/profile
vi /etc/profile
在文件的最后面添加如下代码
export ORACLE_HOME="oracle的安装路径"
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH


在/etc/init.d 下面建立oracle的启动文件

CenterOs的开机启动的文件一般都是放到init.d下面.在里面可以看到其他的一切启动文件.我们在里面建立oracle的启动文件oracle.注意linux下面没有后缀一说.后缀只是用来方便查看文件的. 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下面的开机启动了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle