Linux 中配置oracle 自启动

准备工作

版本

Linux版本:Oracle Linux 6.3
Oracle版本:Oracle11.2.0.4
也适用于centos,Oracle 11 R2其他版本

安装,配置环境变量 .bash_profile

关于安装的教程很多,不赘述
这里贴出我自己的 .bash_profile

JAVA_HOME=/usr/java/jdk1.8.0_144
ORACLE_SID=orcl
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
PATH=$ORACLE_HOME/bin:$JAVA_HOME/bin:$PATH

export JAVA_HOME ORACLE_SID ORACLE_BASE ORACLE_HOME
export PATH

alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'

步骤

  1. 修改/etc/oratab:将N 改为Y

    orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y
  2. 切换到root用户,在/etc/init.d中创建oracle文件并将下面内容添加到文件中
    新建oracle文件
    将ORA_HOME 与ORA_OWNER 替换成你自己的

    
    #!/bin/sh
    
    
    # chkconfig: 2345 80 20
    
    
    # description: Oracle auto start-stop script.
    
    #
    
    # Set ORA_HOME to be equivalent to the $ORACLE_HOME
    
    
    # from which you wish to execute dbstart and dbshut;
    
    #
    
    # Set ORA_OWNER to the user id of the owner of the
    
    
    # Oracle database in ORA_HOME.
    
    ORA_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
    ORA_OWNER=oracle
    if [ ! -f $ORA_HOME/bin/dbstart ]
    then
        echo "Oracle startup: cannot start"
        exit
    fi
    case "$1" in
    'start')
    
    # Start the Oracle databases:
    
    echo "Starting Oracle Databases ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
    echo "Done"
    
    
    # Start the Listener:
    
    echo "Starting Oracle Listeners ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
    echo "Done."
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Finished." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    touch /var/lock/subsys/oracle
    ;;
    
    'stop')
    
    # Stop the Oracle Listener:
    
    echo "Stoping Oracle Listeners ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
    echo "Done."
    rm -f /var/lock/subsys/oracle
    
    
    # Stop the Oracle Database:
    
    echo "Stoping Oracle Databases ... "
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
    echo "Done."
    echo ""
    echo "-------------------------------------------------" >> /var/log/oracle
    date +" %T %a %D : Finished." >> /var/log/oracle
    echo "-------------------------------------------------" >> /var/log/oracle
    ;;
    
    'restart')
    $0 stop
    $0 start
    ;;
    esac
    
  3. 设置权限
    设置权限

    chmod a+x /etc/init.d/oracle
  4. 添加到服务中心
    输入如下命令

    chkconfig --add oracle

    添加到服务中心

  5. 添加到/etc/rc.d/rc.local 中
    编辑 /etc/rc.d/rc.local,在末尾添加

    /etc/init.d/oracle start

    rc.local

    vi rc.local

测试

终端输入 reboot 重启机器
reboot

等待机器重启后
输入 lsnrctl status 查看实例状态
status

数据库也可以连上
sqlplus

还可以在/var/log文件夹中查看oracle 日志文件

cat /var/log/oracle

log
log

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值