centos 7 oracle11g 开机自启

一、修改oratab文件 
以root身份进入系统,通过vi命令打开文件 
vim /etc/oratab 
进入vim编辑器后,找到“orcl:/data/u01/app/oracle/product/11.2.0/dbhome_1:N”, 
改为“orcl:/data/u01/app/oracle/product/11.2.0/dbhome_1:Y”。修改完成后,保存退出

“vim /etc/rc.d/rc.local” 
在vim编辑器中,添加:

su - oracle  -lc "/data/u01/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start"
su - oracle  -lc "/data/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart"

注:其中/home/oracle/app/oracle/product/11.2.0/dbhome_1 为ORACLE_HOME 
二、oracle启动绑定监听器 
1、修改dbstart和dbshut启动关闭脚本,使其启动数据库的同时也自动启动监听器(即启动数据库时启动监听器,停止数据库时停止监听器): 
vim /data/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart


找到下面的代码,在实际脚本代码的同样也修改dbshut脚本: 
vim /data/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbshut

三、新建Oracle服务启动脚本 
vim /etc/init.d/oracle 
新建一个以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=/home/oracle/app
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/db_1
export ORACLE_SID=ORCL
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

 

保存退出 
四、检查一下脚本能否正确执行

 chmod 750 /etc/rc.d/init.d/oracle
cd /etc/rc.d/init.d 
./oracle start 
./oracle stop 
五、加入自动启动行列 
执行如下命令: 
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/rc0.d/K61oracle 
ln -s /etc/rc.d/init.d/oracle /etc/rc6.d/K61oracle 
chkconfig –level 234 oracle on 
chkconfig –add oracle

 

参考: 
1.https://blog.csdn.net/eakom/article/details/79792198
2.http://hechuangqiang.iteye.com/blog/2233538

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈苏漾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值