oracledba.help
Scripts

initLnxOra12_1.sh

<- Scripts

#!/bin/bash
# initLnxOra12_1.sh

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

# User Vars
GRID_ENV=1
ORACLE_USR_PW="go";
GRID_USR_PW="$ORACLE_USR_PW";
VERSION="12.1.0.2";

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

SW_SRC_DIR="/media/sf_software/Oracle/$VERSION/Linux"
#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 "optUnzipInstallFiles:  $optUnzipInstallFiles\n"
printf "optHomeDirectories:    $optHomeDirectories\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 "\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... \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/linuxamd64_12102_database* $SW_DEST_DIR/
    cp -f $SW_SRC_DIR/linuxamd64_12102_grid* $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

    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/rpm
    chown oracle:oinstall    $SW_DEST_DIR/patches
    chmod -R 775 /u01/

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


# Unzip Files
if [[ $optUnzipInstallFiles -eq 1 ]]; then
   printf "\nUnzipping Files...\n\n"
   cd $SW_DEST_DIR
   unzip linuxamd64_12102_database_1of2.zip
   unzip linuxamd64_12102_database_2of2.zip
   chown -R oracle:oinstall $SW_DEST_DIR/database

   if [[ $GRID_ENV -eq 1 ]]; then
      cd $SW_DEST_DIR
      unzip linuxamd64_12102_grid_1of2.zip
      unzip linuxamd64_12102_grid_2of2.zip
      chown -R grid:oinstall $SW_DEST_DIR/grid
   fi

   chmod -R 775 /u01/
   read -p "Unzip Files: Completed - Press [Enter] to continue."
fi

# Create App Home Directories
if [[ $optHomeDirectories -eq 1 ]]; then
   printf "\nCreating Home Directories...\n\n"

   mkdir -p $DB_HOME
   chown -R oracle:oinstall $APP_DIR

   if [[ $GRID_ENV -eq 1 ]]; then
      # Note GI_HOME and GI_BASE in 12.1 cannot be in same path.
      mkdir -p $GI_HOME
      #chown -R grid:oinstall $GI_HOME
      chown -R grid:oinstall $APP_DIR/$VERSION

      mkdir -p $GI_BASE
      chown -R grid:oinstall $GI_BASE
   fi

   chmod -R 775 $APP_DIR

   printf "Create App Home Directories: Completed \n\n"
   printf "NEXT\n"
   printf "1. Reboot\n"
   printf "2. 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. Reboot\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 = Reboot\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"