Thứ Ba, 1 tháng 12, 2020

Quy trình bật, tắt Oracle Clusterware 10g

I. Khởi động
1. Start các dịch vụ cluster
(root)#$ORA_CRS_HOME/bin/crsctl start crs
(Thường khi khởi động lại service crs sẽ tự lên)
(hoặc Start  CRS # /etc/init.d/init.ohas d start)
2. Startup oracle instance
$sqlplus / as sysdba;
SQL>startup

3. Kiểm tra trạng thái của Oracle RAC
(oracle)#$ORA_CRS_HOME/bin/crs_stat –t

II. Tắt
1. Stop oracle instance
(oracle)#sqlplus / as sysdba;
SQL>shutdown immediate

2. Shutdown các dịch vụ cluster (gsd, ons, vip, lsnr sẽ offline)
(oracle)#srvctl stop nodeapps -n <node_name>

- Kiểm tra lại trạng thái các service của cluster:
(oracle)#$ORA_CRS_HOME/bin/crs_stat –t

- Kết nối vào user root thực hiện:
#$ORA_CRS_HOME/bin/crsctl stop crs  // stop ch.tr cluster
(hoặcStop CRS: # /etc/init.d/init.crs stop)

Help
$ crsctl help

== File init.ohasd ==
more /etc/init.d/init.ohasd 
#!/bin/sh
#
# Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 
#
# init.ohasd - Control script for the Oracle HA services daemon
# This script is invoked by the init system
#
# Note:
#   For security reason,  all cli tools shipped with Clusterware should be
# executed as HAS_USER in init.ohasd and ohasd rc script for SIHA. (See bug
# 9216334 for more details)

######### Shell functions #########
tolower_host()
{
  #If the hostname is an IP address, let hostname
  #remain as IP address
  H1=`$HOSTN`
  len1=`$EXPRN "$H1" : '.*'`
  len2=`$EXPRN match $H1 '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'`

  # Strip off domain name in case /bin/hostname returns
  # FQDN hostname
  if [ $len1 != $len2 ]; then
   H1=`$ECHO $H1 | $CUT -d'.' -f1`
  fi
  
  $ECHO $H1 | $TR '[:upper:]' '[:lower:]'
}

# Invoke crsctl as root in case of clusterware, and HAS_USER in case of SIHA.
# Note: Argument with space might be problemactic (my_crsctl 'hello world')
my_crsctl()
{
  if [ root = "root" ]; then
    $CRSCTL $*
  else
    $SU root -c "$CRSCTL $*"
  fi
}

# Invoke clsecho as root in case of clusterware, and HAS_USER in case of SIHA.
# Note: Argument with space might be problemactic (my_clsecho 'hello world')
my_clsecho()
{
  if [ root = "root" ]; then
    $CLSECHO $*
  else
    $SU root -c "$CLSECHO $*"
  fi
}

# Invoke clsecho as root in case of clusterware, and HAS_USER in case of SIHA.
# Note: Argument with space might be problemactic (my_logsys 'hello world')
my_logsys()
{
  if [ root = "root" ]; then
    $LOGSYS $*
  else
    $SU root -c "$LOGSYS $*"
  fi
}
###################################

######### Instantiated Variables #########
ORA_CRS_HOME=/u01/grid
export ORA_CRS_HOME

HAS_USER=root
SCRBASE=/var/opt/oracle/scls_scr

#limits
CRS_LIMIT_CORE=unlimited
CRS_LIMIT_MEMLOCK=unlimited
CRS_LIMIT_OPENFILE=65536
##########################################

### Restart related variables
# Max. # of restart before checking restart time window
RESTART_LIMIT=10
# Time window in which RESTART_LIMIT # of restarts allowed without
# abort auto-restarting (in sec).
RESTART_TIME_WINDOW=60
# Internal variables.
CURR_TIME=0
TIME_ELAPSE=0
PREV_RESTART_TIME=0
RESTART_COUNTER=0

# How long to wait (in seconds) before rechecking a dependency,
# and printing out messages about it.
DEP_CHECK_WAIT=60

NAMEDPIPE=/var/tmp/.oracle/npohasd

### CLI tools
BASENAME=/bin/basename
HOSTN=/bin/hostname
SU=/bin/su
CHOWN=/bin/chown
ECHO=/bin/echo
SLEEP=/bin/sleep
EXPRN=/usr/bin/expr
CUT=/usr/bin/cut
CAT=/bin/cat
GREP=/bin/grep

# Location to TR differs in diff. platforms.
TR=/bin/tr
#solaris location (for both SPARC and amd)
[ 'SunOS' = `/bin/uname` ] && TR=/usr/xpg4/bin/tr 
#on linux tr is at /usr/bin/tr
[ 'Linux' = `/bin/uname` ] && TR=/usr/bin/tr

CLSECHO="/u01/grid/bin/clsecho"
LOGSYS="$CLSECHO -s $0:"
PERL="/u01/grid/perl/bin/perl -I${ORA_CRS_HOME}/perl/lib"
CRSCTL=/u01/grid/bin/crsctl

### Main ###
# Retrieve name of the platform
PLATFORM=`/bin/uname`
MY_HOST=`tolower_host`

# Default path for SCR control files.
AUTORUNFILE=/var/opt/oracle/scls_scr/$MY_HOST/root/ohasdrun

LOGMSG="/bin/logger -puser.err"
LOGERR="/bin/logger -puser.alert"

case $PLATFORM in
Linux) LOGGER="/usr/bin/logger"
       if [ ! -f "$LOGGER" ];then
       LOGGER="/bin/logger"
       fi
       LOGMSG="$LOGGER -puser.err"
       LOGERR="$LOGGER -puser.alert"
       CUT="/bin/cut"
       ;;
HP-UX)
       NAMEDPIPE=/tmp/.oracle/npohasd
       ;;
AIX)
       NAMEDPIPE=/tmp/.oracle/npohasd
       ;;
SunOS)
       ;;
OSF1)
       ;;
*)     /bin/echo "ERROR: Unknown Operating System"
       exit -1
       ;;
esac

# enable HA by default on most unix platforms
case $PLATFORM in
  Linux)
    GIPCD_PASSTHROUGH=false
    export GIPCD_PASSTHROUGH
    ;;
  HP-UX)
    GIPCD_PASSTHROUGH=false
    export GIPCD_PASSTHROUGH
    ;;
  SunOS)
    GIPCD_PASSTHROUGH=false
    export GIPCD_PASSTHROUGH
    ;;
  AIX)
    GIPCD_PASSTHROUGH=false
    export GIPCD_PASSTHROUGH
    ;;
  OSF1)
    ;;
esac

case $1 in

'run')

   # we set the hard and soft limit here as root
   # these limits will be reset in ohasd wrapper.
   # Nevertheless, we need to set them here in the
   # case of SIHA since the wrapper will not get
   # called as root
   case $PLATFORM in
   Linux) 
       # MEMLOCK limit is for Bug 9136459
       ulimit -l unlimited
       ulimit -c unlimited
       ulimit -n 65536
       ;;
   *) 
       ulimit -c unlimited
       ulimit -n 65536
       ;;
   esac
   
   # Handle reboot of system or restarted init script
   STARTUP_LOOP="true"
   while ($STARTUP_LOOP)
   do
     if [ -r $AUTORUNFILE ]
     then
      case `$CAT $AUTORUNFILE` in
       restart*)
         OUTPUT=`my_crsctl check has | $GREP 4638`
         case "$OUTPUT" in
          CRS*)
            # Sync with ohasd and restart after crash
            read junk < $NAMEDPIPE
            STARTUP_LOOP="false"
            ;;
          *)
           # Stale restart at boot time, wait for restart
           $SLEEP 10
           ;;
         esac
         ;;
       *)
         STARTUP_LOOP="false"
         ;;
      esac
     else
      STARTUP_LOOP="false"
     fi
   done

   # Wait until clusterware home is mounted.
   while [ ! -r $CLSECHO ] 
   do
     $LOGMSG "Waiting for filesystem containing $CLSECHO."
     $SLEEP $DEP_CHECK_WAIT
   done

   # Try to create named pipe.
   if [ root = "root" ]; then
     OUTPUT=`mkfifo $NAMEDPIPE 2>&1`
   else
     OUTPUT=`$SU root -c "mkfifo $NAMEDPIPE" 2>&1`
   fi

   if [ ! -p $NAMEDPIPE ]; then
     # Print an alert entry regarding failure to create named pipe.
     # Note: Cannot use my_clsecho since OUTPUT has newline and white spaces
     if [ root = "root" ]; then
       $CLSECHO -l -p has -f crs -m 10131 $NAMEDPIPE "$OUTPUT"
     else
       $SU root -c "$CLSECHO -l -p has -f crs -m 10131 $NAMEDPIPE '$OUTPUT'"
     fi

     # Stop ohasd restart.
     $ECHO "stop" > $AUTORUNFILE
   fi
   
   # Main loop
   while (true)
   do
     # Should ohasd be run or restarted?
     if [ -r $AUTORUNFILE ]
     then
       case `$CAT $AUTORUNFILE` in
        reboot*)
          # Sync with ohasd and restart after crash
          $ECHO "restart" > $AUTORUNFILE
          read junk < $NAMEDPIPE
          ;;
        restart*)
          ### Bug 6956719. Prevent ohasd from crashing and restarting too
          ### rapidly in a short period of time.
          RESTART_COUNTER=`$EXPRN $RESTART_COUNTER + 1`

          if [ $RESTART_COUNTER -gt $RESTART_LIMIT ]; then
            # Obtain current epoch time.
            if [ root = "root" ]; then
              CURR_TIME=`$PERL -e 'print time'`
            else
              CURR_TIME=`$SU root -c "$PERL -e 'print time'"`
            fi

            if [ "$?" -eq "0" ]; then
              TIME_ELAPSE=`$EXPRN $CURR_TIME - $PREV_RESTART_TIME`
  
              my_logsys "Ohasd restarts $RESTART_COUNTER times in $TIME_ELAPSE seconds."
              
              # Stop restarting if ohasd restarts more than RESTART_LIMIT times
              # within RESTART_TIME_WINDOW.
              if [ $TIME_ELAPSE -lt $RESTART_TIME_WINDOW ]; then
                my_logsys "Ohasd restarts too rapidly. Stop auto-restarting."
                my_clsecho -l -p has -f crs -m 10132 $RESTART_LIMIT $RESTART_TIME_WINDOW
  
                # Stop ohasd restart.
                $ECHO "stop" > $AUTORUNFILE
  
                # Reset RESTART_COUNTER and PREV_RESTART_TIME to default values.
                RESTART_COUNTER=0
                PREV_RESTART_TIME=0
  
                continue
              else
                # Reset the counter if ohasd does not restart more than
                # RESTART_LIMIT times in the last RESTART_TIME_WINDOW secs.
                RESTART_COUNTER=1
                my_logsys "Resetting RESTART_COUNTER to 1."
              fi
  
              PREV_RESTART_TIME=$CURR_TIME
            else
              # Let ohasd restart if failed to obtain current time.
              my_logsys "Unable to obtain current time. $PERL -e 'print time' failed."
            fi
          fi
          ############################################

          my_logsys "ohasd is restarting $RESTART_COUNTER/$RESTART_LIMIT."

          # Restart ohasd and sync with it
          if [ root = "root" ]; then
            /u01/grid/bin/ohasd restart &
          else
            $SU root -c "/u01/grid/bin/ohasd restart &"
          fi
          read junk < $NAMEDPIPE
          ;;
        stop*)
          $SLEEP 10
          ;;
        *)
          $LOGERR 'autorun file for ohasd has unknown value'
          $SLEEP 10
          ;;
      esac
      else
       $LOGERR 'autorun file for ohasd is missing'
       $SLEEP 10
    fi
  done

;;
esac


KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH: 📧 Mail: binhoracle@gmail.com ☎️ Mobile: 0902912888 ⚡️ Skype: tranbinh48ca 👨 Facebook: https://www.facebook.com/BinhOracleMaster 👨 Inbox Messenger: https://m.me/101036604657441 (profile) 👨 Fanpage: https://www.facebook.com/tranvanbinh.vn 👨 Inbox Fanpage: https://m.me/tranvanbinh.vn 👨👩 Group FB: https://www.facebook.com/groups/OracleDBAVietNam 👨 Website: http://www.tranvanbinh.vn 👨 Blogger: https://tranvanbinhmaster.blogspot.com 🎬 Youtube: http://bit.ly/ytb_binhoraclemaster 👨 Tiktok: https://www.tiktok.com/@binhoraclemaster?lang=vi 👨 Linkin: https://www.linkedin.com/in/binhoracle 👨 Twitter: https://twitter.com/binhoracle 👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội #OracleTutorial #OracleDBA #OracleDatabaseAdministration #học oracle database #oca #ocp #oce #ocm

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master