• Oracle-配置单实例数据库在linux环境跟随系统自启动


    方法一、配置shell脚本,使用/etc/rc.local 跟随系统自启动

     
    # cat /home/oracle/script/start.sh
    lsnrctl start<<EOF
    EOF
    sqlplus / as sysdba <<EOF
    startup
    alter system register;
    exit
    EOF
    # su -c "sh /home/oracle/script/start.sh" - oracle
     
    # cat /etc/rc.local
    su -c "sh /home/oracle/script/start.sh" - oracle
    # ls -lrt /etc/rc.local
    lrwxrwxrwx. 1 root root 13 Mar 26 2020 /etc/rc.local -> rc.d/rc.local
    # ls -lrt /etc/rc.d/rc.local
    -rw-r--r--. 1 root root 523 Mar 25 02:12 /etc/rc.d/rc.local
    # chmod 755 /etc/rc.d/rc.local

    方法二、配置shell脚本,linux 添加服务的方式

    2.1 Liinux >=7

    http://www.jinbuguo.com/systemd/systemd.service.html
    #echo >/usr/lib/systemd/system/os_db_start.service
    echo "[Unit]
    Description=os_db_start
    
    [Service]
    User=oracle
    Type=forking
    ExecStart=/usr/bin/sh /home/oracle/script/start.sh
    ExecStop=/usr/bin/sh /home/oracle/script/stop.sh
    TimeoutStartSec=200
    
    [Install]
    WantedBy=multi-user.target" >>/usr/lib/systemd/system/os_db_start.service
    
    # cat /home/oracle/script/start.sh 
    export ORACLE_SID=odb
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=/u01/app/oracle/product/19.0.0/db_1
    export PATH=/u01/app/oracle/product/19.0.0/db_1/bin:/u01/app/oracle/product/19.0.0/db_1/bin:/usr/lib64/qt-3.3/bin:
    /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/oracle/.local/bin:/home/oracle/bin:/home/oracle/bin:/home/oracle/bin lsnrctl start <<EOF exit EOF sqlplus / as sysdba <<EOF startup exit EOF # cat /home/oracle/script/stop.sh export ORACLE_SID=odb export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=/u01/app/oracle/product/19.0.0/db_1 export PATH=$ORACLE_HOME/bin:$PATH:$HOME/bin lsnrctl stop<<EOF EOF sqlplus / as sysdba <<EOF shutdown immediate; exit EOF $chmod +x /home/oracle/script/*.sh # systemctl daemon-reload # systemctl start os_db_start # systemctl enable os_db_start # systemctl is-enabled os_db_start enabled 

    2.2 Liinux <=6  如下是DBA小伙伴-郭鑫提供,测试可用

    --开机自启动oracle数据库,运行./oracle.stop 手动关闭数据库和监听。
    oracle.start
    oracle.stop
    
    [oracle]$ vi /home/oracle/script/oracle.start
    #!/bin/bash
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1/
    export ORACLE_SID=tt
    export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
    lsnrctl start;
    sqlplus / as sysdba <<EOF
    startup
    EOF
      
    [oracle]$ vi /home/oracle/script/oracle.stop
    #!/bin/bash
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1/
    export ORACLE_SID=tt
    export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
    sqlplus / as sysdba <<EOF
    shutdown immediate;
    EOF
    lsnrctl stop;
     
    权限:
    chmod a+x oracle.start oracle.stop
    chmod +x /etc/init.d/oracle
    
    # vi /etc/init.d/oracle
    #! /bin/bash
    #
    # oracle       Bring up/down oracle
    #
    # chkconfig: 2345 90 1
    # description: Activates/Deactivates all oracle configured to 
    #              start at boot time.
    #
    # Source function library.
    . /etc/init.d/functions
    # See how we were called.
    case "$1" in
      start)
            su - oracle -c "/home/oracle/script/oracle.start"
            ;;
      stop)
            su - oracle -c "/home/oracle/script/oracle.stop"
            ;;
      *)
            echo $"Usage: $0 {start|stop}"
            exit 2
    esac
    #chkconfig oracle on
    验证端口:
    # netstat -an|grep :1521
    
    # netstat -an|grep :1521     
    tcp        0      0 192.168.60.69:1521          0.0.0.0:*                   LISTEN      
    tcp        0      0 192.168.60.69:18601         192.168.60.69:1521          ESTABLISHED 
    tcp        0      0 192.168.60.69:1521          192.168.60.69:18601         ESTABLISHED 
    tcp        0      0 192.168.60.69:1521          192.168.60.69:18600         TIME_WAIT


    #备注 19c 环境pdb可以先进行关闭,后续关闭cdb! pdb启动可以配置跟随cdb自启动。

    sqlplus / as sysdba <<EOF
    alter pluggable database all close;
    shutdown immediate;

     
     

  • 相关阅读:
    设计模式——装饰模式(Decorator Pattern)
    设计模式——策略模式(Strategy Pattern)
    设计模式——简单工厂模式(SimpleFactory Pattern)
    入博客园三周年记
    android+Service
    surfaceView+canvas+paint+bitmap
    Enable Sublime text 2 to support GBK in Mac
    androidstudio+opencv
    mac下的环境变量PATH
    Curl命令
  • 原文地址:https://www.cnblogs.com/lvcha001/p/14580288.html
Copyright © 2020-2023  润新知