码迷,mamicode.com
首页 > 数据库 > 详细

Linux下oracle开机自启动

时间:2018-09-20 23:28:08      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:startup   rc.d   自启   restart   end   -o   desc   chmod   $0   

1、以root身份登录到linux系统,编辑/etc/oratab文件,找到 

testsid:/data/oracle/product/11.2.0/db_1:N 
,改为 
testsid:/data/oracle/product/11.2.0/db_1:Y 

 

2、配置/etc/rc.d/rc.local,添加以下脚本:

su oracle -lc "/data/oracle/product/11.2.0/db_1/bin/lsnrctl start"
su oracle -lc /data/oracle/product/11.2.0/db_1/bin/dbstart

 

3、在/etc/init.d创建oracle服务启动,注意修改oracle路径:

vim /etc/init.d/oracle 

#!/bin/sh
# chkconfig: 345 61 61
# description: Oracle 11g R2 AutoRun Servimces
# /etc/init.d/oracle
#
# Run-level Startup script for the Oracle Instance, Listener, and
# Web Interface
export ORACLE_BASE=/data/oracle    #根据个人情况修改路径
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=testsid          #改成自己的ORACLE_SID:testsid
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNR="oracle"
# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbstart
echo "Oracle Start Succesful!OK."
;;
stop)
# Oracle listener and instance shutdown
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbshut
echo "Oracle Stop Succesful!OK."
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo $"Usage: `basename $0` {start|stop|reload|reload}"
exit 1
esac
exit 0

4、将oracle脚本文件赋予执行权限 
说明:/etc/init.d -> /etc/rc.d/init.d 其中/etc/init.d为link文件,所以执行哪个目录下的Oracle脚本都应该可以。

 cd /etc/rc.d/init.d
 chmod +x oracle

  

5、修改dbstart和dbshut启动关闭脚本,使其启动数据库的同时也自动启动监听器(即启动数据库时启动监听器,停止数据库时停止监听器): 

# vim /data/oracle/product/11.2.0/db_1/bin/dbstart
找到下面的代码:
ORACLE_HOME_LISTNER=$1
将其改为
ORACLE_HOME_LISTNER=$ORACLE_HOME

 同样也修改dbshut脚本:

# vim /data/oracle/product/11.2.0/db_1/bin/dbshut
找到下面的代码:
ORACLE_HOME_LISTNER=$1
将其改为
ORACLE_HOME_LISTNER=$ORACLE_HOME

 

6、加入自启动队列

ln –s /etc/rc.d/init.d/oracle /etc/rc0.d/K61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc2.d/S61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc3.d/S61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc4.d/S61oracle
ln –s /etc/rc.d/init.d/oracle /etc/rc6.d/K61oracle

 将 oracle服务加入到系统服务

chkconfig --level 234 oracle on
chkconfig --add oracle

7、检查是否生效:

chkconfig --list oracle

 

Linux下oracle开机自启动

标签:startup   rc.d   自启   restart   end   -o   desc   chmod   $0   

原文地址:https://www.cnblogs.com/archer-wen/p/9683898.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!