Oracle Installation & Upgrade Standalone in Silent mode scripts on Redhat CentOS OracleLinux RockyLinux

This script need there files. You can adjust the parameters SOURCE_DBZIP, UPGRADE_DBZIP, UPGRADE_PATCHNUMBER, UPGRADE_OPATH to match your environment.

  • Oracle 19.3 LINUX.X64_193000_db_home.zip
  • Oracle 19.13 p33192793_190000_Linux-x86-64.zip
  • Oracle OPatch 12.2.0.1.27 p6880880_190000_Linux-x86-64.zip

Parameter Name

Description

SOURCE_PATH

Oracle Software Source Path

SOURCE_DBZIP

Oracle Software zip FileName

ROOT_PWD

Change ROOT user to Execute when installer finished

DEFAULT_ORAPWD

syssystem password

DEFAULT_CHARSET

Database NLS_LANG (Default: AL32UTF8)

DEFAULT_ORADATA

Database data path

DEFAULT_GLOBALNAME

Database Global Name

DEFAULT_SID

Instance Name

DEFAULT_REDOSIZE

redo size

DEFAULT_ARCHPATH

archivelog path

DEFAULT_TOTALMEMORY

total memory (sga using 3/4pga using 1/4)

UPGRADE_DBZIP

upgrade patch zip name

UPGRADE_PATCHNUMBER

upgrade patch directory name

UPGRADE_OPATH

opatch file name


# vim install_standalone.sh
#!/bin/sh
# Software PARAMETER
SOURCE_PATH=/u01/source
SOURCE_DBZIP=LINUX.X64_193000_db_home.zip
ROOT_PWD=123qweasdzxc
# DBCA PARAMETER
DEFAULT_ORAPWD=oracle
DEFAULT_CHARSET=AL32UTF8
DEFAULT_ORADATA=/u01/app/oradata
DEFAULT_GLOBALNAME=orcl
DEFAULT_SID=orcl1
DEFAULT_REDOSIZE=200
DEFAULT_ARCHPATH=/u01/archivelog
DEFAULT_PROCESSES=1000
# Auto Calc Memory
PHYSICAL_MEM=`free -m | grep "Mem:" | awk '{print $2}'`
DEFAULT_TOTALMEMORY=`echo | awk '{print int('$PHYSICAL_MEM'*0.4)}'`
# UPGRADE DB PARAMETER
UPGRADE_DBZIP=p33192793_190000_Linux-x86-64.zip
UPGRADE_PATCHNUMBER=33192793
UPGRADE_OPATH=p6880880_190000_Linux-x86-64.zip

HOSTNAME=`hostname`
if [ $HOSTNAME == 'localhost' ] || [ $ORACLE_HOSTNAME == 'localhost' ]; then
  echo `date '+%Y-%m-%d %H:%M:%S'` "Please Check .bash_profile $ORACLE_HOSTNAME & /etc/host is not 'localhost'."
  exit 0
fi

ORACLEHOME=`echo $ORACLE_HOME`
if [ -z $ORACLEHOME ]; then
  echo `date '+%Y-%m-%d %H:%M:%S'` "Please Check .bash_profile is setting ORACLE_HOME."
  exit 0
fi

if [ ! -d $ORACLE_HOME ]; then
  echo `date '+%Y-%m-%d %H:%M:%S'` "Create $ORACLE_HOME Directory."
  mkdir -p $ORACLE_HOME
fi

if [ ! "$(ls -A $ORACLE_HOME)" ]; then
  echo `date '+%Y-%m-%d %H:%M:%S'` "unzip $SOURCE_DBZIP"
  cd $SOURCE_PATH
  unzip $SOURCE_DBZIP -d $ORACLE_HOME > /dev/null
fi

# Install 19c on REDHAT 8 Bug
OSVERSION=`cat /etc/os-release | grep VERSION_ID | awk -F= '{ print $2 }' | sed -e 's/^"//' -e 's/"$//'`
case $OSVERSION in
  '8.1' | '8.2' | '8.3' | '8.4' | '8.5' | '8.6' | '8.7' | '8.8' | '8.9' | '8.10' | '8.11' | '8.12') export CV_ASSUME_DISTID=OEL7.8 ;;
  *) echo "Nothing to do on version $OSVERSION. Exiting." ;;
esac

# edit slient install for standalone 
cat $ORACLE_HOME/install/response/db_install.rsp | grep -v "#" | grep -v '^[[:space:]]*$' | \
sed "s^oracle.install.option=^oracle.install.option=INSTALL_DB_SWONLY^" | \
sed "s^UNIX_GROUP_NAME=^UNIX_GROUP_NAME=oinstall^" | \
sed "s^INVENTORY_LOCATION=^INVENTORY_LOCATION=/u01/app/oraInventory^" | \
sed "s^ORACLE_HOME=^ORACLE_HOME=$ORACLE_HOME^" | \
sed "s^ORACLE_BASE=^ORACLE_BASE=$ORACLE_BASE^" | \
sed "s^oracle.install.db.InstallEdition=^oracle.install.db.InstallEdition=EE^" | \
sed "s^oracle.install.db.OSDBA_GROUP=^oracle.install.db.OSDBA_GROUP=dba^" | \
sed "s^oracle.install.db.OSOPER_GROUP=^oracle.install.db.OSOPER_GROUP=oper^" | \
sed "s^oracle.install.db.OSBACKUPDBA_GROUP=^oracle.install.db.OSBACKUPDBA_GROUP=backupdba^" | \
sed "s^oracle.install.db.OSDGDBA_GROUP=^oracle.install.db.OSDGDBA_GROUP=dgdba^" | \
sed "s^oracle.install.db.OSKMDBA_GROUP=^oracle.install.db.OSKMDBA_GROUP=kmdba^" | \
sed "s^oracle.install.db.OSRACDBA_GROUP=^oracle.install.db.OSRACDBA_GROUP=racdba^" | \
sed "s^oracle.install.db.rootconfig.executeRootScript=^oracle.install.db.rootconfig.executeRootScript=true^" | \
sed "s^oracle.install.db.rootconfig.configMethod=^oracle.install.db.rootconfig.configMethod=ROOT^" > ~/db_install.rsp

CKINSTALL=0
which sqlplus > /dev/null 2>&1
if [ $? = 1 ]; then
  cd $ORACLE_HOME
  echo `date '+%Y-%m-%d %H:%M:%S'` "Install Oracle Software Only..."
  echo -e "$ROOT_PWD\n" | ./runInstaller -silent -responseFile `echo $HOME`/db_install.rsp -ignorePrereqFailure
  echo `date '+%Y-%m-%d %H:%M:%S'` "Install Oracle Software Only Successful."
  echo `date '+%Y-%m-%d %H:%M:%S'` "Install Listner..."
  netca -silent -responseFile $ORACLE_HOME/assistants/netca/netca.rsp
  echo `date '+%Y-%m-%d %H:%M:%S'` "Install Listner Successful."
  CKINSTALL=1
else
  echo `date '+%Y-%m-%d %H:%M:%S'` "Oracle Software already install."
fi

if [ -f ~/db_install.rsp ]; then
  rm -f ~/db_install.rsp
fi

#Upgrade when Oracle Install
if [ $CKINSTALL=1 ];then
  cd $SOURCE_PATH
  if [ ! -d $SOURCE_PATH/$UPGRADE_PATCHNUMBER ]; then
    echo `date '+%Y-%m-%d %H:%M:%S'` "unzip $UPGRADE_DBZIP"
    unzip $UPGRADE_DBZIP > /dev/null
  fi
  echo `date '+%Y-%m-%d %H:%M:%S'` "unzip $UPGRADE_OPATH and remove old \$ORACLE_HOME/OPatch"
  mv $ORACLE_HOME/OPatch $ORACLE_HOME/OPatch.bak
  unzip $UPGRADE_OPATH -d $ORACLE_HOME > /dev/null

CKLISTENER=`ps -ef | grep -v grep | grep LISTENER | wc -l`
  if [ $CKLISTENER = 1 ]; then
    echo `date '+%Y-%m-%d %H:%M:%S'` "Stop Listener..."
    lsnrctl stop
    echo `date '+%Y-%m-%d %H:%M:%S'` "Stop Listener Successful."
  fi
  #Upgrade
  echo `date '+%Y-%m-%d %H:%M:%S'` "Upgrade DB PATCH $UPGRADE_DBZIP"
  cd $UPGRADE_PATCHNUMBER
  $ORACLE_HOME/OPatch/opatch apply -silent
  echo `date '+%Y-%m-%d %H:%M:%S'` "Start Listener..."
  lsnrctl start
  echo `date '+%Y-%m-%d %H:%M:%S'` "Start Listener Successful."
fi

CKDB=`ps -ef | grep -v grep | grep ora_pmon_$DEFAULT_SID | wc -l`
if [ $CKDB = 1 ]; then
  echo `date '+%Y-%m-%d %H:%M:%S'` "Oracle Database SID: $DEFAULT_SID already install."
else
  echo `date '+%Y-%m-%d %H:%M:%S'` "Install nonContainer Database..."
dbca -silent -createDatabase \
-templateName General_Purpose.dbc \
-gdbname $DEFAULT_GLOBALNAME -sid $DEFAULT_SID -responseFile NO_VALUE \
-characterSet $DEFAULT_CHARSET \
-sysPassword $DEFAULT_ORAPWD \
-systemPassword $DEFAULT_ORAPWD \
-createAsContainerDatabase false \
-numberOfPDBs 0 \
-databaseType MULTIPURPOSE \
-memoryMgmtType auto_sga \
-totalMemory $DEFAULT_TOTALMEMORY \
-storageType FS \
-datafileDestination "$DEFAULT_ORADATA" \
-useOMF true \
-redoLogFileSize $DEFAULT_REDOSIZE \
-emConfiguration NONE \
-ignorePreReqs
  echo `date '+%Y-%m-%d %H:%M:%S'` "Install nonContainer Database Successful."
fi

echo `date '+%Y-%m-%d %H:%M:%S'` "Starting Database archive log mode..."
if [ ! -d $DEFAULT_ARCHPATH ]; then
  echo `date '+%Y-%m-%d %H:%M:%S'` "mkdir $DEFAULT_ARCHPATH..."
  mkdir $DEFAULT_ARCHPATH
fi

echo `date '+%Y-%m-%d %H:%M:%S'` "Setting log_archive_dest_1=$DEFAULT_ARCHPATH..."
sqlplus / as sysdba > /dev/null << EOF
alter system set log_archive_dest_1='LOCATION=$DEFAULT_ARCHPATH' scope=both;
exit
EOF
echo `date '+%Y-%m-%d %H:%M:%S'` "Setting log_archive_dest_1=$DEFAULT_ARCHPATH Successful."

echo `date '+%Y-%m-%d %H:%M:%S'` "Setting processes=$DEFAULT_PROCESSES..."
sqlplus / as sysdba > /dev/null << EOF
alter system set processes=$DEFAULT_PROCESSES scope=spfile;
exit
EOF
echo `date '+%Y-%m-%d %H:%M:%S'` "Setting processes=$DEFAULT_PROCESSES Successful."

echo `date '+%Y-%m-%d %H:%M:%S'` "Shutdown Database..."
sqlplus / as sysdba > /dev/null << EOF
shutdown immediate;
exit
EOF
echo `date '+%Y-%m-%d %H:%M:%S'` "Shutdown Database Successful."

echo `date '+%Y-%m-%d %H:%M:%S'` "Restart Database..."
sqlplus / as sysdba > /dev/null << EOF
startup mount;
alter database archivelog;
alter database open;
alter system switch logfile;
exit
EOF
echo `date '+%Y-%m-%d %H:%M:%S'` "Restart Database Successful."

sleep 1

ls -l $DEFAULT_ARCHPATH

echo `date '+%Y-%m-%d %H:%M:%S'` "Install system oracle-db.service ..."
echo "$ROOT_PWD" | su root -c "echo '[Unit]
Description=a service to start databases and listener automatically
After=syslog.target network.target

[Service]
LimitNOFILE=1024:65536
LimitNPROC=2047:16384
LimitSTACK=10485760:33554432
LimitMEMLOCK=infinity

Type=forking

User=oracle
Group=oinstall
Environment=ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1

ExecStart=/u01/app/oracle/product/19.0.0/dbhome_1/bin/dbstart \${ORACLE_HOME}
ExecStop=/u01/app/oracle/product/19.0.0/dbhome_1/bin/dbshut \${ORACLE_HOME}

RemainAfterExit=True
Restart=no

[Install]
WantedBy=multi-user.target'> /etc/systemd/system/oracle-db.service"
echo "$ROOT_PWD" | su root -c "systemctl daemon-reload && systemctl enable oracle-db.service"
cp /etc/oratab /tmp && sed -i 's/:N/:Y/g' /tmp/oratab && cat /tmp/oratab > /etc/oratab && cat /etc/oratab
echo `date '+%Y-%m-%d %H:%M:%S'` "Install system oracle-db.service Successful."

echo `date '+%Y-%m-%d %H:%M:%S'` "Script Finished."

張貼留言

0 留言