天天看点

如何让oracle DB、监听和oem开机启动(dbstart) 如何让oracle DB、监听和oem开机启动(dbstart)

Oracle提供了伴随操作系统自动重启的功能,在Windows中,可以修改“我的电脑-->管理-->服务-->OracleService$ORACLE_SID”,或直接使用Win+R键打开运行窗口,输入services.msc即可打开服务,找到相应的Oracle服务,然后将其属性中的启动类型修改成自动。一般在Windows系统上安装完后会自动设置成自动。

如何让oracle DB、监听和oem开机启动(dbstart) 如何让oracle DB、监听和oem开机启动(dbstart)

对于Linux/Unix操作系统,如果想设置自动重启,那该如何操作呢?对此Oracle提供了dbstart命令用于启动,可以有2种方法来配置。

1. 修改/etc/oratab

[root@oracle ~]#vim /etc/oratab

orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y     #将N改为Y

文件/etc/oratab由root.sh脚本创建,在用DBCA创建实例时也会更新这个文件。当$ORACLE_SID:$ORACLE_HOME:设置为Y时,允许实例自启动,当设置为N时,则不允许自启动。这个文件里的配置仅仅起一个开关的作用,其并不会具体的执行启动和关闭,具体的操作由$ORACLE_HOME/bin/dbstart和dbshut脚本来实现。这2个脚本在执行时会检查/etc/oratab文件里的配置,为Y时才能继续执行。

   2. 修改$ORACLE_HOME/bin/dbstart和$ORACLE_HOME/bin/dbshut

[root@oracle ~]#vim

$ORACLE_HOME/bin/dbstart

$ORACLE_HOME/bin/dbshut

ORACLE_HOME_LISTNER=$ORACLE_HOME ($1改为$ORACLE_HOME)

ORACLE_HOME_LISTNER的位置:Oracle 11g的dbstart在第80行,dbshut文件中在第50行。

3. 建立启动脚本

使用root用户创建脚本:

/etc/rc.d/init.d/oracle

#!/bin/bash

#

chkconfig: 2345 99 10

description: Startup Script for oracle Databases

export

ORACLE_BASE=/u01/app/oracle/

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

PATH=$PATH:$ORACLE_HOME/bin

ORACLE_UNQNAME=PROD1

echo "

" >> /var/log/oraclelog

echo

`date +'%Y-%m-%d %H:%M:%S'` >> /var/log/oraclelog

case

"$1" in

start)

"-----startup oracle-----" >> /var/log/oraclelog

su oracle -c

"$ORACLE_HOME/bin/dbstart"

"$ORACLE_HOME/bin/emctl start dbconsole"

touch /var/lock/subsys/oracle

"-----startup oracle successful-----" >> /var/log/oraclelog

"OK"

;;

stop)

"-----shutdown oracle-----" >> /var/log/oraclelog

"$ORACLE_HOME/bin/dbshut"

"$ORACLE_HOME/bin/emctl stop dbconsole"

rm -f

/var/lock/subsys/oracle

`date +'%Y-%m-%d %H:%M:%S'` >> /var/log/oraclelogg

"-----shutdown oracle successful-----" >> /var/log/oraclelog

restart)

touch

*)

"Usage: 'basename $0' start|stop|restart"

exit 1

esac

exit 0

4. 给脚本设置权限

[root@oracle

~]# chmod 755 /etc/rc.d/init.d/oracle

5. 建立服务

~]# chkconfig --add oracle

~]# chkconfig oracle on

~]# chkconfig --list oracle

oracle          0:off   1:off  

2:on    3:on   

4:on    5:on    6:off

6. 检查是否生效

先使用root用户测试服务是否生效:

[root@edsir4p1

~]# service oracle stop

~]# service oracle start

~]# service oracle restart

再重启OS,验证是否生效。

使用service测试:

Processing

Database instance "PROD1": log file

/u01/app/oracle/product/11.2.0/dbhome_1/shutdown.log

Database instance "PROD2": log file

Oracle

Enterprise Manager 11g Database Control Release 11.2.0.1.0

Copyright

(c) 1996, 2009 Oracle Corporation.  All

rights reserved.

https://edsir4p1.us.oracle.com:1158/em/console/aboutApplication

Stopping

Oracle Enterprise Manager 11g Database Control ...

 ... 

Stopped.

OK

/u01/app/oracle/product/11.2.0/dbhome_1/startup.log

Starting

Oracle Enterprise Manager 11g Database Control ..... started.

------------------------------------------------------------------

Logs are

generated in directory

/u01/app/oracle/product/11.2.0/dbhome_1/edsir4p1.us.oracle.com_PROD1/sysman/log

  2. 修改$ORACLE_HOME/bin/dbstart和$ORACLE_HOME/bin/dbshut

将以下脚本添加到/etc/rc.d/rc.local或/etc/rc.local文件中(/etc/rc.local是/etc/rc.d/rc.local的软连接文件):

su

oracle -c $ORACLE_HOME/bin/dbstart

oracle -c "$ORACLE_HOME/bin/emctl start dbconsole"

若环境中没有创建EM,则可以不用添加ORACLE_UNQNAME,和emctl这2行。

需要注意的是,/etc/rc.local是/etc/rc.d/rc.local的软连接文件,如下所示:

[oracle@edsir4p1-PROD1 ~]$ ll /etc/rc.local

lrwxrwxrwx 1 root root 13 Aug 31  2013 /etc/rc.local -> rc.d/rc.local

[oracle@edsir4p1-PROD1 ~]$ ll /etc/rc.d/rc.local

-rwxr-xr-x 1 root root 401 Jan  2 03:51 /etc/rc.d/rc.local

需要注意的是,在CentOS7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限

chmod +x /etc/rc.d/rc.local

4. 检查是否生效

~]# export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

~]# su oracle -c $ORACLE_HOME/bin/dbstart

对于这2种方法,需要注意的几个问题:

1. 多个实例都会自动重启。

2. 监听也会自动重启。

3. 重启的详细日志为:$ORACLE_HOME/shutdown.log和$ORACLE_HOME/startup.log。

4. oracle用户的环境变量可以不用配置。

5. ORACLE_UNQNAME的作用是设置EM的环境变量,emctl是启动OEM,若没有则可以不用设置。

6. ORACLE_HOME的作用是设置数据库监听的环境变量。

7. 对于ASM、RAC环境,只需要将数据库资源注册的CRS中,即可实现开机启动。

About Me ............................................................................................................................................. ● 本文作者:小麦苗,部分内容整理自网络,若有侵权请联系小麦苗删除 ● QQ群号:230161599(满)、618766405 ● 微信群:可加我微信,我拉大家进群,非诚勿扰 ● 联系我请加QQ好友(646634621),注明添加缘由 ● 于 2018-01-01 06:00 ~ 2018-01-31 24:00 在魔都完成 ● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解 ● 版权所有,欢迎分享本文,转载请保留出处
如何让oracle DB、监听和oem开机启动(dbstart) 如何让oracle DB、监听和oem开机启动(dbstart)
如何让oracle DB、监听和oem开机启动(dbstart) 如何让oracle DB、监听和oem开机启动(dbstart)
如何让oracle DB、监听和oem开机启动(dbstart) 如何让oracle DB、监听和oem开机启动(dbstart)
如何让oracle DB、监听和oem开机启动(dbstart) 如何让oracle DB、监听和oem开机启动(dbstart)
   小麦苗的微信公众号      小麦苗的DBA宝典QQ群2     《DBA笔试面宝典》读者群       小麦苗的微店 <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&amp;uin=646634621&amp;site=qq&amp;menu=yes"></a>
如何让oracle DB、监听和oem开机启动(dbstart) 如何让oracle DB、监听和oem开机启动(dbstart)
如何让oracle DB、监听和oem开机启动(dbstart) 如何让oracle DB、监听和oem开机启动(dbstart)
如何让oracle DB、监听和oem开机启动(dbstart) 如何让oracle DB、监听和oem开机启动(dbstart)
如何让oracle DB、监听和oem开机启动(dbstart) 如何让oracle DB、监听和oem开机启动(dbstart)