禁止oracle自启,【原创】各平台环境Oracle自启动与自关闭的配置方法 | DBStyle'S BLOG - NOT ONLY THE ORACLE...

Report Content

Issue: *

Copyright Infringment

Spam

Invalid Contents

Broken Links

Your Name:

*

Your Email:

*

Details:

*

Submit Report

3577da14244745895ea3ce4964b54d3e.gif

一、Linux平台

网上很多朋友还在问这个问题,于是写出来(全以root用户执行):

1. 修改/etc/oratab ,格式 ORACLE_SID:ORACLE_HOME:Y

[root@OracleCX oracle]# cat /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::

#

# 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.

#

#

nms:/oracle/product/11.2.0/dbhome_1:Y

nms10:/oracle10/product/10.2.0/db_1:Y

2.编辑开机自启动脚本,路径为/etc/rc.d/init.d/下面

[root@OracleCX init.d]# vi /etc/rc.d/init.d/oracle

#chkconfig:2345 90 00 ---#这两行一定要,这样才能用chkconfig进行管理

#description:oracle ---#这两行一定要,这样才能用chkconfig进行管理

#!/bin/bash

case "$1" in

start)

su oracle -c '/oracle/product/11.2.0/dbhome_1/bin/dbstart /oracle/product/11.2.0/dbhome_1' -一定不要用变量的形式,改成绝对路径

;;

stop)

su oracle -c '/oracle/product/11.2.0/dbhome_1/bin/dbshut /oracle/product/11.2.0/dbhome_1'

;;

esac

说明:/etc/init.d/目录下的服务文件都有一些共同点,那就是有一行类似# chkconfig: 2345 10 90这样的内容,就和第一行#! /bin/bash一样,是必需的,而不是我们平时所说的注释。三栏表示的意思是:不同的运行级别、启动顺序、关闭顺序。也就是说在/etc/rc.d/rcN.d/(N为2、3、4、5)下会有S10开头的对应文件和/etc/rc.d/rcN.d/(N为0、1、6)下以K90开头的对应文件。这个我们可以查看前面有关运行级别的相关信息。

3.修改oracle脚本的权限为可执行的

[root@OracleCX init.d]# chmod 755 oracle

4.然后将这个脚本加到相应的执行级别

[root@OracleCX init.d]# chkconfig --add oracle

[root@OracleCX init.d]# chkconfig --level 235 oracle on

5.确认相应的/etc/rc.d/rcX.d目录是否有K和S开头的链接,不需要手动增加链接,第4步的命令执行以后,会自动在相应级别下生成Sxxx启动文件(和rc0.d下面 的Kxxxxx关闭文件)

(其他级别的Kxxxxx关闭文件会在命令执行后自动生成)。

6.在/var/lock/subsys目录建一个和脚本名一样的文件,如touch /var/lock/subsys/ora(这条语句要加到/etc/rc.d/rc.local/中每次都关机后这个文件都会被删除)。

这样在关机的时候关机的的脚本才会执行,很多朋友因为没有手动建立这个文件,手动执行/etc/rc.d/init.d/ora stop又是正常,但是关机时又不能执行,需多注意!

[root@OracleCX subsys]# touch /var/lock/subsys/oracle

[root@OracleCX subsys]# cat /etc/rc.d/rc.local

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

touch /var/lock/subsys/oracle

二、Solaris平台

1. 修改/var/opt/oracle/oratab ,将“N”改为“Y”,格式 ORACLE_SID:ORACLE_HOME:Y,使之支持开机启动。如下:

root@ZHZCDB2#vi /var/opt/oracle/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::

#

# 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.

#

#

zhfx:/oracle/product/10.2.0/db_1:N

cmdb:/oracle/product/10.2.0/db_1:N

unionmon:/oracle/product/10.2.0/db_1:Y

report:/oracle/product/10.2.0/db_1:N

pasm:/oracle/product/10.2.0/db_1:Y

uip:/oracle/product/10.2.0/db_1:N

2.创建启动脚本:

root@ZHZCDB2#vi /etc/init.d/oracle

#!/bin/sh

ORACLE_HOME=/oracle/product/10.2.0/db_1

ORACLE_OWNER=oracle

if [ ! -f $ORACLE_HOME/bin/dbstart ]

then

echo "Oracle startup:cannot start"

exit

fi

case "$1" in

'start' )

su - $ORACLE_OWNER -c $ORACLE_HOME/bin/dbstart &

;;

'stop' )

su - $ORACLE_OWNER -c $ORACLE_HOME/bin/dbshut &

;;

esac

3.赋予脚本执行权限:

root@ZHZCDB2#chmod 755 /etc/init.d/oracle

4.在/etc/rc2.d中设置启动链接:

root@ZHZCDB2#cd /etc/rc2.d/

root@ZHZCDB2#ln -s /etc/init.d/oracle S99oracle

5.在/etc/rc0.d中设置关闭链接:

root@ZHZCDB2#cd /etc/rc0.d

root@ZHZCDB2#ln -s /etc/init.d/oracle K10oracle

三、AIX平台

1. 修改/etc/oratab ,将“N”改为“Y”,格式 ORACLE_SID:ORACLE_HOME:Y,使之支持开机启动。如下:

# vi /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::

#

# 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.

#

#

nms115:/oracle/product/10.2.0/db_1:Y

web52:/oracle/product/10.2.0/db_1:Y

jh1210:/oracle/product/10.2.0/db_1:Y

nms512a:/oracle/product/10.2.0/db_1:Y

2.创建启动脚本

# vi /etc/rc.oracle

export ORACLE_SID=nms115

echo "Start Oracle instance: nms115"

su oracle -c '/oracle/product/10.2.0/db_1/bin/dbstart /oracle/product/10.2.0/db_1'

export ORACLE_SID=web52

echo "Start Oracle instance: web52"

su oracle -c '/oracle/product/10.2.0/db_1/bin/dbstart /oracle/product/10.2.0/db_1'

export ORACLE_SID=jh1210

echo "Start Oracle instance: jh1210 "

su oracle -c '/oracle/product/10.2.0/db_1/bin/dbstart /oracle/product/10.2.0/db_1'

3.创建关闭脚本

# vi /etc/rc.shutdown

export ORACLE_SID=nms115

echo "Start Oracle instance: nms115"

su oracle -c '/oracle/product/10.2.0/db_1/bin/dbshut /oracle/product/10.2.0/db_1'

export ORACLE_SID=web52

echo "Start Oracle instance: web52"

su oracle -c '/oracle/product/10.2.0/db_1/bin/dbshut /oracle/product/10.2.0/db_1'

export ORACLE_SID=jh1210

echo "Start Oracle instance: jh1210 "

su oracle -c '/oracle/product/10.2.0/db_1/bin/dbshut /oracle/product/10.2.0/db_1'

注:关于为什么脚本叫/etc/rc.shutdown,以及怎么工作。如下注解:

系统管理员可以在 /etc/rc.shutdown shell 脚本中放置本地定制的关闭过程。如果该脚本存在,则在关闭开始时就运行。如果脚本运行但是失败(返回非零返回码),则关机停止。

4.赋予脚本执行权限:

# chmod 755 /etc/rc.oracle

# chmod 755 /etc/rc.shutdown

5.添加到/etc/inittab最下面,实现自启动。并且创建启动日志:

# vi /etc/inittab

oracle:2:wait:/etc/rc.oracle > /home/oracle/oracle.log 2>$1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值