Linux下oracle设置开机自启动的方法

方法1)、添加以下脚本到/etc/rc.d/rc.local 或/etc/rc.d/rc

#设置环境变量
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/9204
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH
export ORACLE_OWNER=oracle
export ORACLE_SID=TEST
export ORACLE_TERM=xterm
export LD_ASSUME_KERNEL=2.4.19
export THREADS_FLAG=native
export LD_LIBRARY_PATH=/opt/oracle/product/9204/lib:$LD_LIBRARY_PATH
export PATH=/opt/oracle/product/9204/bin:$PATH

export DISPLAY=:0
#使用帐户名oracle登录启动oracle
oracle_user=oracle

# 启动监听和数据库

su - "$oracle_user"<< EOO
lsnrctl start
sqlplus /nolog<<EOS
#使用dba帐户 system登录 connect system(此为帐户名)/system(帐户密码) as sysdba
connect system/system as sysdba
startup
EOS
EOO

ps:也可以把上面的脚本放到一个文件里,然后在rc.local加入调用的语句。


方法2)、加载为服务自启动、停止

步骤1:在/etc/rc.d/init.d 目录添加一启动脚本,如oracleservice,脚本如下

#!/bin/sh
#
#name:/etc/rc.d/init.d/oracleservice
# chkconfig: 345 99 99
# description: 启动、停止oracle数据库和监听控制程序
# 注:上面两行是必须,不明的可以参考chkconfig相关资料
# oracle environment

export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/9204
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH
export ORACLE_OWNER=oracle
export ORACLE_SID=TEST
export ORACLE_TERM=xterm
export LD_ASSUME_KERNEL=2.4.19
export THREADS_FLAG=native
export LD_LIBRARY_PATH=/opt/oracle/product/9204/lib:$LD_LIBRARY_PATH
export PATH=/opt/oracle/product/9204/bin:$PATH

export DISPLAY=:0

oracle_user=oracle

case "$1" in
start)

# 启动监听控制程序和数据库

su - "$oracle_user"<< EOO
lsnrctl start
sqlplus /nolog<<EOS
connect system/system as sysdba
startup
EOS
EOO
;;

stop)

# 停止监听控制程序和数据库

su - "$oracle_user"<<EOO
lsnrctl stop
sqlplus /nolog<<EOS
connect     system/system as sysdba
shutdown immediate

EOS
EOO
;;

*)
;;

esac
#--脚本结束
#从脚本里可以得知,此脚本通过参数start或stop来启动、停止数据库和监听控制程序

步骤2:

更改权限,设置为可运行,在shel窗口中输入:
# chmod +x /etc/rc.d/init.d/oracleservice

步骤3:把oracleservice添加到服务里

# chkconfig –add /etc/rc.d/init.d/oracleservice

查看自动启动设置是否成功:
# chkconfig –list oracleservice
oracleservice     0:关闭     1:关闭     2:关闭     3:开启     4:开启     5:开启     6:关闭
*从上面可以看出level为345的都已经开启了,配置成功!

步骤4:重启检查oracle自启动是否成功。

方法3)、使用oracle本身的dbstart脚本,位置$ORACLE_HOME/bin/dbstart
看网上介绍,使用dbstart是需要修改/etc/oratab把里面设置的最后一项设置为Y,如:
TEST:/opt/oracle/product/9204:N,更改为TEST:/opt/oracle/product/9204:Y

使用dbstart方式还没空尝试,有空再试试

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值