oracledba.help
Scripts

initLnxOra18_3.sh

<- Scripts

#!/bin/bash
# initLnxOra18_3.sh

# Option Vars
optCopyFilesFromMedia=1
optGroupsUsers=0
optDirectories=0
#---Oracles Preinstallation rpm Installed Here---
optOSChanges=0
optInstallPkgs=0
optVBoxChanges=0

# User Vars
GRID_ENV=0
ORACLE_USR_PW="go";
GRID_USR_PW="$ORACLE_USR_PW";
VERSION="18.3.0.0.0";

RPMS_DIR="/media/sf_sw/Oracle/rpm"
#RPMS_DIR="/tmp/orasw/rpm"

SW_SRC_DIR="/media/sf_sw/Oracle/18c"
#SW_SRC_DIR="/tmp/orasw"

SW_DEST_DIR="/u01/orasw"

APP_DIR="/u01/app";
DB_HOME="$APP_DIR/oracle/product/$VERSION/dbhome_1"
GI_BASE="$APP_DIR/grid"
GI_HOME="$APP_DIR/$VERSION/grid"


# Confirmation
printf "+--------------------------------------------+\n" 
printf "| Init the oracle and grid User Environments |\n"
printf "+--------------------------------------------+\n"
printf "optCopyFilesFromMedia: $optCopyFilesFromMedia\n"
printf "optGroupsUsers:        $optGroupsUsers\n"
printf "optDirectories:        $optDirectories\n"
printf "optOSChanges:          $optOSChanges\n"
printf "\n"
printf "optInstallPkgs:        $optInstallPkgs\n"
printf "optVBoxChanges:        $optVBoxChanges\n"

printf "\n"
printf "GRID_ENV:              $GRID_ENV\n"
printf "DB_HOME:               $DB_HOME\n"
printf "GI_HOME:               $GI_HOME\n"
printf "GI_BASE:               $GI_BASE\n"
printf "\n"

if [[ $optOSChanges -eq 1 ]]; then
   printf "Ensure you have run Oracles Preinstallation rpm BEFORE running optOSChanges option here!\n\n"
fi

read -p "Are you sure want to continue [y\n]? " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    printf "\n"
    exit 1
fi
printf "\n"


printf "\nValidating Dirs...\n"
# Oracle Dirs\Volumes
if [[ ! -d "/u01" ]]; then
   printf "\nCreating Oracle Dirs\Volumes (\\\u01 &  \\\u02) \n"
   mkdir -p /u01
   mkdir -p /u02
fi

# Init SW Dir
if [[ ! -d $SW_DEST_DIR ]]; then
   printf "\nCreating $SW_DEST_DIR... \n"
   mkdir -p $SW_DEST_DIR
   mkdir -p $SW_DEST_DIR/rpm
   mkdir -p $SW_DEST_DIR/patches
fi


# CopyFilesFromMedia
if [[ $optCopyFilesFromMedia -eq 1 ]]; then
    printf "\nCopying Files\n"
    printf "From: $SW_SRC_DIR\n"
    printf "To:   $SW_DEST_DIR\n\n"

    cd $SW_SRC_DIR
    cp -f $SW_SRC_DIR/LINUX.X64_180000_db_home.zip $SW_DEST_DIR/
    cp -f $SW_SRC_DIR/LINUX.X64_180000_grid_home.zip $SW_DEST_DIR/ 
    read -p "Copy Files From Media: Completed - Press [Enter] to continue."
fi


# Create Groups, Users
if [[ $optGroupsUsers -eq 1 ]]; then
    printf "\nCreating Groups, Users...\n\n"
    groupadd --gid 54321 oinstall
    groupadd --gid 54322 dba
    groupadd --gid 54323 asmdba
    groupadd --gid 54324 asmoper
    groupadd --gid 54325 asmadmin
    groupadd --gid 54326 oper
    groupadd --gid 54327 backupdba
    groupadd --gid 54328 dgdba
    groupadd --gid 54329 kmdba
    groupadd --gid 54330 racdba

    printf "\nSetting User Passwords...\n\n"
    useradd --uid 54321 --gid oinstall --groups dba,oper,asmdba,asmoper,backupdba,dgdba,kmdba oracle
    #echo Enter oracle account password; passwd oracle
    echo "$ORACLE_USR_PW" | passwd --stdin oracle

    useradd --uid 54322 --gid oinstall --groups dba,asmadmin,asmdba,asmoper grid
    #echo Enter grid account password; passwd grid
    echo "$GRID_USR_PW" | passwd --stdin grid

    printf "Setting Directory Permissions\n"
    chown -R oracle:oinstall $SW_DEST_DIR
    chmod -R 775 /u01/

    read -p "Create Groups, Users: Completed - Press [Enter] to continue."
fi

# Create Home Directories
if [[ $optDirectories -eq 1 ]]; then
   printf "\nCreating Home and oraInventory Directories...\n\n"

   # Homes
   printf "\nCreating Home Dirs...\n\n"
   mkdir -p $DB_HOME
   cp $SW_DEST_DIR/LINUX.X64_180000_db_home.zip $DB_HOME/
   cd $DB_HOME
   unzip LINUX.X64_180000_db_home.zip
   rm -f LINUX.X64_180000_db_home.zip
   chown -R oracle:oinstall $APP_DIR

   if [[ $GRID_ENV -eq 1 ]]; then
      mkdir -p $GI_BASE
      mkdir -p $GI_HOME
      cp $SW_DEST_DIR/LINUX.X64_180000_grid_home.zip $GI_HOME/
      cd $GI_HOME
      unzip LINUX.X64_180000_grid_home.zip
      rm -f LINUX.X64_180000_grid_home.zip
      chown -R grid:oinstall /u01
      chown -R oracle:oinstall /u01/app/oracle
   fi

   # oraInventory
   printf "\nCreating oraInventory Dir...\n\n"
   mkdir /u01/app/oraInventory
   if [[ $GRID_ENV -eq 1 ]]; then
      chown grid:oinstall /u01/app/oraInventory
   else
      chown oracle:oinstall /u01/app/oraInventory
   fi
   chmod -R 775 /u01/app/oraInventory

   printf "\nCreating Home and oraInventory Directories: Completed - Press [Enter] to continue."
   printf "NEXT\n"
   printf "1. shutdown -r now\n"
   printf "2. Then Run Oracles Preinstallation rpm\n\n"
   read -p "Press [Enter] to continue."
fi


# OS Configuration Changes
if [[ $optOSChanges -eq 1 ]]; then
   printf "\nOS Configuration Changes...\n"
   printf "\nOnly making changes Oracles Preinstallation rpm does not do.\n\n"

   # Stop Firewall
   printf "\nFirewall Changes\n\n"
   service iptables stop
   chkconfig iptables off
   systemctl disable firewalld
   systemctl stop firewalld

   # Kernel Parameters: /etc/sysctl.conf
   printf "\nKernal Params...\n\n"
   if ! grep -q vm.nr_hugepages "/etc/sysctl.conf"; then
      echo "vm.swappiness = 1"                  >> /etc/sysctl.conf
      echo "vm.dirty_background_ratio = 3"      >> /etc/sysctl.conf
      echo "vm.dirty_ratio = 80"                >> /etc/sysctl.conf
      echo "vm.dirty_expire_centisecs = 500"    >> /etc/sysctl.conf
      echo "vm.dirty_writeback_centisecs = 100" >> /etc/sysctl.conf
      #echo "vm.nr_hugepages = 39953"            >> /etc/sysctl.conf
   fi

    # Limits File: 99-grid-oracle-limits.conf
    printf "\n99-grid-oracle-limits.conf...\n"
    fLimits="/etc/security/limits.d/99-grid-oracle-limits.conf";
    touch $fLimits
    if ! grep -q oracle "$fLimits"; then
       echo "oracle soft nproc 2047" >> $fLimits
       echo "oracle hard nproc 16384" >> $fLimits
       echo "oracle soft nofile 1024" >> $fLimits
       echo "oracle hard nofile 65536" >> $fLimits
       echo "oracle soft stack 10240" >> $fLimits
       echo "oracle hard stack 32768" >> $fLimits

       echo "grid soft nproc 2047" >> $fLimits
       echo "grid hard nproc 16384" >> $fLimits
       echo "grid soft nofile 1024" >> $fLimits
       echo "grid hard nofile 65536" >> $fLimits
       echo "grid soft stack 10240" >> $fLimits
       echo "grid hard stack 32768" >> $fLimits
    fi

    # Disable SELINUX
    printf "\nDisable SELINUX \n"
    if grep -q SELINUX=enforcing "/etc/sysconfig/selinux"; then
       sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
    fi
    if grep -q SELINUX=enforcing "/etc/selinux/config"; then
       sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    fi

    # Disable avahi Daemon Service
    printf "\nDisabling avahi Daemon Service...\n"
    systemctl stop avahi-dnsconfd
    systemctl stop avahi-daemon
    rm '/etc/systemd/system/dbus-org.freedesktop.Avahi.service'
    rm '/etc/systemd/system/multi-user.target.wants/avahi-daemon.service'
    rm '/etc/systemd/system/sockets.target.wants/avahi-daemon.socket'

    printf "OS Configuration Changes: Completed\n\n"
    printf "NEXT\n"
    printf "1. shutdown -r now\n"
    printf "2. Install LINUX Packages\n\n"
    read -p "Press [Enter] to continue."
fi

# Install LINUX Packages
if [[ $optInstallPkgs -eq 1 ]]; then
    printf "\nInstalling LINUX Packages...\n\n"
    for PKG in binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33.i686 gcc gcc-c++ glibc glibc.i686 glibc-devel glibc-devel.i686 ksh libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel libstdc++-devel.i686 libaio libaio.i686 libaio-devel libaio-devel.i686 libXext libXext.i686 libXtst libXtst.i686 libX11 libX11.i686 libXau libXau.i686 libxcb libxcb.i686 libXi libXi.i686 make sysstat unixODBC unixODBC-devel
    do 
        yum install $PKG -y
    done

    for PKG in libXmu libXxf86dga nfs-utils libXau libdmx xorg-x11-utils xorg-x11-xauth libXv libXi libXt libXxf86misc LibXxf86vm
    do
        yum install $PKG -y
    done

    yum install device-mapper-multipath -y
    yum install dnsmasq -y
    yum install -y ntp

    # rlwrap
    yum install perl-Data-Dumper-2.145-3.el7.x86_64 -y
    if [[ -f $RPMS_DIR/rlwrap-0.42-1.fc22.x86_64.rpm ]]; then
       printf "\nInstalling rlwrap...\n"
       cd $RPMS_DIR
       rpm -ivh rlwrap-0.42-1.fc22.x86_64.rpm
    fi

    printf "Install LINUX Packages: Completed\n\n\n"
    printf "NEXT\n"
    printf "shutdown -r now\n"
    read -p "Press [Enter] to continue."
fi


# optVBoxChanges
if [[ $optVBoxChanges -eq 1 ]]; then
    printf "\nMaking VirtualBox Changes \n\n"
    usermod -aG vboxsf oracle
    if [[ $GRID_ENV -eq 1 ]]; then
       usermod -aG vboxsf grid
    fi
    chmod 755 $SW_SRC_DIR
    read -p "VirtualBox Changes: Completed - Press [Enter] to continue."
fi


# END
printf "\n*** Process Ended ***\n\n"