zoukankan      html  css  js  c++  java
  • Oracle自动启动脚本配置

    需要为Oracle数据库配置自动启动么?这本身就是一个需要考虑的事情^_^.

    下面提供两个脚本,分别用来配置Linux 6和7的自动启动服务。

    适用环境:Red Hat/CentOS/OEL 6/7

    For 6:

    #!/bin/bash

    echo "获取Oracle Home路径"
    ORACLE_HOME=$(cat /etc/oratab | grep ^[a-zA-Z] | awk -F":" '{print $2}' | uniq | head -1)
    echo "Oracle Home: $ORACLE_HOME"
    echo -n "请确认Oracle Home是否正确(Y/n): "
    read confirm
    if [ "x$confirm" = "x" ] || [ "x$confirm" = "xY" ] || [ "x$confirm" = "xy" ]; then ls -ld $ORACLE_HOME; else exit; fi

    echo "设置服务自动启动"
    cat > /etc/init.d/oradb <<!
    #!/bin/bash
    # chkconfig: 345 99 10
    # 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_OWNER=oracle
    ORA_HOME=$ORACLE_HOME

    if [ ! -f $ORA_HOME/bin/dbstart ]
    then
    echo "Oracle: cannot find dbstart command!"
    exit
    fi

    RETVAL=0
    # See how we were called.
    case "$1" in
    'start')
    # Start the Oracle databases:
    # The following command assumes that the oracle login
    # will not prompt the user for any values
    su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
    RETVAL=$?
    touch /var/lock/subsys/oradb
    ;;
    'stop')
    # Stop the Oracle databases:
    # The following command assumes that the oracle login
    # will not prompt the user for any values
    su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
    RETVAL=$?
    rm -f /var/lock/subsys/oradb
    ;;
    'status')
    oraProcess=$(ps -ef | grep ora_pmon | wc -l)
    if [ $oraProcess -eq 0 ]; then
    echo "Oracle Service is not running!"
    else
    echo "Oracle Running Processes: "
    ps -ef | grep ora_ | grep -v grep | awk '{print " ├─"$2" "$8}'
    fi
    RETVAL=$?
    ;;
    *)
    echo "usage: $0 {start|stop|status}"
    exit
    ;;
    esac

    exit $RETVAL
    !

    chmod 750 /etc/init.d/oradb
    chkconfig --add oradb

    echo "打开自动启动设置 - /etc/oratab"
    sed -i '/^[a-zA-Z]/{s/N/Y/}' /etc/oratab
    grep ^[a-zA-Z] /etc/oratab | grep Y


    echo -e "服务启动命令:
    service oradb start
    service oradb status
    service oradb stop
    "

    For 7:

    #!/bin/bash

    echo "获取Oracle Home路径"
    ORACLE_HOME=$(cat /etc/oratab | grep ^[a-zA-Z] | awk -F":" '{print $2}' | uniq | head -1)
    echo "Oracle Home: $ORACLE_HOME"
    echo -n "请确认Oracle Home是否正确(Y/n): "
    read confirm
    if [ "x$confirm" = "x" ] || [ "x$confirm" = "xY" ] || [ "x$confirm" = "xy" ]; then ls -ld $ORACLE_HOME; else exit; fi

    echo "安装服务"
    cat > /usr/lib/systemd/system/oracle.service <<!
    [Unit]
    Description=Oracle Database as Service
    After=syslog.target network.target

    [Service]
    User=oracle
    Group=oinstall
    LimitMEMLOCK=infinity
    LimitNOFILE=65535
    Type=oneshot
    RemainAfterExit=yes
    Restart=no
    Environment=NLS_LANG=AMERICAN_AMERICA.AL32UTF8
    Environment=LANG=en_US.UTF-8
    Environment=ORACLE_HOME=$ORACLE_HOME
    ExecStart=/bin/bash -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
    ExecStop=/bin/bash -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"

    [Install]
    WantedBy=multi-user.target
    !

    echo "设置服务自动启动"
    systemctl daemon-reload
    systemctl enable oracle.service

    echo "打开自动启动设置 - /etc/oratab"
    sed -i '/^[a-zA-Z]/{s/N/Y/}' /etc/oratab
    grep ^[a-zA-Z] /etc/oratab | grep Y

    echo -e "服务启动命令:
    systemctl start oracle.service
    systemctl status oracle.service
    systemctl stop oracle.service
    "

  • 相关阅读:
    jdbc操作数据库并自动获取字段类型
    oracle sqlplus登陆命令
    2014木瓜移动校园招聘笔试题
    线段树总结
    JAVA的Split小技巧
    百度地图2.2框架黑屏和只有网格处理方法
    Zend Studio 实用快捷键大全
    Ext4中获取下拉框的值
    Java如何显示不同语言的时间?
    Java如何以不同国家的格式显示时间?
  • 原文地址:https://www.cnblogs.com/bdp-data/p/13085001.html
Copyright © 2011-2022 走看看