Oracle使用DBSTART开机启动

记录Oracle使用DBSTART启动的问题

出问题的原因

开发完成后,项目需要部署到生成环境进行测试的时候就需要搭建生产环境.
在生产环境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下面的开机启动了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值