centos7上oracle 开机自启

阅读更多
  1. 修改dbstart和dbshut启动关闭脚本,使其启动数据库的同时也自动启动监听器(即启动数据库时启动监听器,停止数据库时停止监听器):
    vim /oracle/product/11.2.0/db_1/bin/dbstart
    找到下面的代码,在实际脚本代码的前面 
    # First argument is used to bring up Oracle Net Listener
    ORACLE_HOME_LISTNER=$1
    # 将此处的 ORACLE_HOME_LISTNER=$1 修改为 
    ORACLE_HOME_LISTNER=$ORACLE_HOME
    if [ ! $ORACLE_HOME_LISTNER ] ; then
    echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener"
    echo "Usage: $0 ORACLE_HOME"
    else
    LOG=$ORACLE_HOME_LISTNER/listener.log
     同样也修改dbshut脚本:
    vim /oracle/product/11.2.0/db_1/bin/dbshut
     
    # The this to bring down Oracle Net Listener
    ORACLE_HOME_LISTNER=$1
    # 将此处的 ORACLE_HOME_LISTNER=$1 修改为 
    ORACLE_HOME_LISTNER=$ORACLE_HOME
    if [ ! $ORACLE_HOME_LISTNER ] ; then
    echo "ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener"
    echo "Usage: $0 ORACLE_HOME"
    else
    LOG=$ORACLE_HOME_LISTNER/listener.log
     
  2. 新建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=/oracle
    export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
    export ORACLE_SID=orcl
    export ORACLE_UNQNAME=$ORACLE_SID  
    export PATH=$ORACLE_HOME/bin:/user/sbin:$PATH
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
    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
     
  3. 在/etc新建oratab
    vim /etc/oratab
     插入
    orcl:/oracle/product/11.2.0/db_1:Y
     
  4. 检查一下脚本能否正确执行
    cd /etc/rc.d/init.d
    ./oracle start
    ./oracle stop
     注意先给 /etc/oratab 执行权限
  5. 加入自动启动行列
    chmod 750 /etc/rc.d/init.d/oracle
    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
     
     
  6. 最后重启动一下linux操作系统,检查oracle是否自动启动成功

你可能感兴趣的:(centos7,oracle11g)