oracledba.help
Scripts

initLnxOra12_2.sh

<- Scripts

#!/bin/bash
# 2017.11.03a: Fixed bug in creating GRID_HOME.
# 2017.06.02a: Improved support for optGridEnv=0.
# 2017.03.20a: Updated for 12.2.0.1 
#              Changed ORACLE_HOME to .../dbhome_1
#              Added vm.min_free_kbytes
# 2016.01.27a: Commented out tempfs.
#              Enabled Linux HugePages in /etc/sysctl.conf
#              Added user vars (APP_DEST_DIR etc.) to make usage more flexible.
# 2016.01.25a: Changed ORACLE_HOME to .../db_1
# 2016.12.14a: Added yum install of NTP
# 2016.12.13a: Added rlwrap support.
# 2016.12.05a: Initial Version
clear

# User Vars
optGridEnv=1

optCopyFilesFromMedia=1
optUnzipInstallFiles=1
optGroupsUsers=1
optDirectories=1
optOSChanges=1

# Do these after above done (reboot before running)
optInstallPkgs=0
optCvuqdisk=0
optVBoxChanges=0

INTERFACES=(ens160 ens192); # example: (enp0s3 endp0s8)
RDBS_VERSION="12.2.0.1"
GRID_VERSION="12.2.0.1"

SYSTEM_NAME="orlldnatv01";
SYSTEM_IP="10.4.0.165"; 

SW_SRC_DIR="/tmp"; # "/media/sf_software/Oracle/12.2"
SW_DEST_DIR="/u01/orasw"
GRID_HOME="/u01/app/12.2.0.1/grid"

APP_DEST_DIR="/u01/app"



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

read -p "Are you sure want to continue [y\n]? " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    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
fi
if [ $optGridEnv -eq 1 ]; then
   printf "\nCreating $GRID_HOME \n"
   mkdir -p $GRID_HOME
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 linuxx64_12201_database.zip $SW_DEST_DIR/
    if [ $optGridEnv -eq 1 ]; then  
       cp -f linuxx64_12201_grid_home.zip $GRID_HOME/
    fi
    read -p "Copy Files From Media: Completed - Press [Enter] to continue."
fi

# Unzip Install Files
if [ $optUnzipInstallFiles -eq 1 ]; then
    printf "\nUnziping Install Files... \n\n"
    #rm -rf $SW_DEST_DIR/database
    #rm -rf $SW_DEST_DIR/grid

    cd $SW_DEST_DIR
    #for f in *.zip; do unzip $f; done
    unzip linuxx64_12201_database.zip

    if [ $optGridEnv -eq 1 ]; then
       cd $GRID_HOME
       unzip linuxx64_12201_grid_home.zip
    fi
    read -p "Unzip Install Files: Completed - Press [Enter] to continue."
fi

# Create Groups and Users
if [ $optGroupsUsers -eq 1 ]; then
    printf "\nCreating Groups and 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

    useradd --uid 54321 --gid oinstall --groups dba,oper,asmdba,asmoper,backupdba,dgdba,kmdba oracle
    echo Enter password for oracle account;passwd oracle

    if [ $optGridEnv -eq 1 ]; then
       useradd --uid 54322 --gid oinstall --groups dba,asmadmin,asmdba,asmoper grid
       echo Enter password for grid account;passwd grid
    fi

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

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

    # Software
    mkdir -p $SW_DEST_DIR/rpm
    chown -R oracle:oinstall $SW_DEST_DIR

    # Base Dirs
    mkdir -p $APP_DEST_DIR
    if [ $optGridEnv -eq 1 ]; then
       mkdir -p $APP_DEST_DIR/grid
    fi
    mkdir -p $APP_DEST_DIR/oracle
    mkdir -p $APP_DEST_DIR/cfgtoollogs
    mkdir -p $APP_DEST_DIR/oraInventory
    chown oracle:oinstall $APP_DEST_DIR
    chown oracle:oinstall $APP_DEST_DIR/cfgtoollogs
    chown oracle:oinstall $APP_DEST_DIR/oracle
    if [ $optGridEnv -eq 1 ]; then
       chown grid:oinstall $APP_DEST_DIR/grid
       chown grid:oinstall $APP_DEST_DIR/oraInventory
    fi
    if [ $optGridEnv -eq 0 ]; then
       chown oracle:oinstall $APP_DEST_DIR/oraInventory
    fi

    # RDBMS HOME
    mkdir -p $APP_DEST_DIR/oracle/product/$RDBS_VERSION/dbhome_1
    chown -R oracle:oinstall $APP_DEST_DIR/oracle/product
    chown -R oracle:oinstall $APP_DEST_DIR/oracle/product/$RDBS_VERSION
    chown -R oracle:oinstall $APP_DEST_DIR/oracle/product/$RDBS_VERSION/dbhome_1

    # GI HOME
    if [ $optGridEnv -eq 1 ]; then 
       mkdir -p /u01/app/$GRID_VERSION/grid
       chown -R grid:oinstall $APP_DEST_DIR/$GRID_VERSION
       chown -R grid:oinstall $APP_DEST_DIR/$GRID_VERSION/grid
    fi

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


# OS Configuration Changes: Start  ==========
if [ $optOSChanges -eq 1 ]; then
    printf "\nChecking\setting OS Values \n\n"

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

    systemctl disable firewalld
    systemctl stop firewalld
    read -p "Press [Enter] to continue."

    # /etc/pam.d/login
    printf "\n/etc/pam.d/login \n\n"
    if ! grep -q pam_limits.so "/etc/pam.d/login"; then
        echo 'session required pam_limits.so' >>/etc/pam.d/login
        echo 'session required /lib64/security/pam_limits.so' >>/etc/pam.d/login
    fi
    read -p "Press [Enter] to continue."

    # Set hostname and make hosts Entry
    printf "\n/etc/hosts \n\n"
    if ! grep -q $SYSTEM_NAME "/etc/hosts"; then
        echo -e "$SYSTEM_IP\t$SYSTEM_NAME" >>/etc/hosts
        hostnamectl set-hostname $SYSTEM_NAME
    fi
    if ! grep -q $SYSTEM_NAME "/etc/sysconfig/network"; then
        echo -e "HOSTNAME=$SYSTEM_NAME" >>/etc/sysconfig/network
        echo -e "NOZEROCONF=yes" >>/etc/sysconfig/network
    fi
    read -p "Press [Enter] to continue."

    # Kernel Parameters: /etc/sysctl.conf
    printf "\nKernal Params...\n\n"
    if ! grep -q fs.aio-max-nr "/etc/sysctl.conf"; then
cat <<EOF >> /etc/sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.panic_on_oops = 1
kernel.shmall = 1073741824
kernel.shmmax = 4398046511104
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
vm.swappiness = 1
vm.dirty_background_ratio = 3
vm.dirty_ratio = 80
vm.dirty_expire_centisecs = 500
vm.dirty_writeback_centisecs = 100
vm.min_free_kbytes = 524288
# HUGEPAGES SETTING FOR ORACLE
# vm.nr_hugepages = 94597
EOF
    fi
    /sbin/sysctl -p
    read -p "Press [Enter] to continue."

    # Reverse Path Filtering: /etc/sysctl.conf
    printf "\nReverse Path Filtering...\n\n"
    if ! grep -q rp_filter "/etc/sysctl.conf"; then
       for n in "${INTERFACES[
}"
       do
          echo -e "net.ipv4.conf.$n.rp_filter = 2" >>/etc/sysctl.conf
       done
    fi
    if ! grep -q rp_filter "/etc/sysctl.d/98-oracle.conf"; then
       for n in "${INTERFACES
]}"
       do
          echo -e "net.ipv4.conf.$n.rp_filter = 2" >>/etc/sysctl.d/98-oracle.conf
       done
    fi
    read -p "Press [Enter] to continue."

    # Limits File: /etc/security/limits.conf
    printf "\nLimits.conf...\n"
    if ! grep -q oracle "/etc/security/limits.conf"; then
cat <<EOF >> /etc/security/limits.conf 
grid          soft    nproc   2047
grid          hard    nproc   16384
grid          soft    nofile  1024
grid          hard    nofile  65536
grid          soft    stack   10240
grid          hard    stack   32768
oracle        soft    nproc   2047
oracle        hard    nproc   16384
oracle        soft    nofile  1024
oracle        hard    nofile  65536
oracle        soft    stack   10240
oracle        hard    stack   32768
oracle        soft    memlock 3145728
oracle        hard    memlock 3145728
EOF
    fi
    read -p "Press [Enter] to continue."

    # 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
    read -p "Press [Enter] to continue."

    # Edit nproc: /etc/security/limits.d/90-nproc.conf
    printf "\nEdit nproc...\n"
    if [ ! -f /etc/security/limits.d/90-nproc.conf ]; then
       echo '* - nproc 16384' >/etc/security/limits.d/90-nproc.conf    
    fi
    read -p "Press [Enter] to continue."

    # 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'
    read -p "Press [Enter] to continue."

    # TBD # echo deadline > /sys/block/${ASM_DISK}/queue/scheduler
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

    # Required for rlwrap
    yum install perl-Data-Dumper-2.145-3.el7.x86_64 -y

    printf "For rlwrap: rpm -ivh rlwrap-0.42-1.fc22.x86_64.rpm \n"

    read -p "Install LINUX Packages: Completed - Press [Enter] to continue."
fi


# optCvuqdisk
if [ $optCvuqdisk -eq 1 ]; then
    printf "\nGet Install cvuqdisk...\n\n"
    cd $SW_DEST_DIR/grid/rpm
    rpm -iv cvuqdisk-1.0.9-1.rpm
    read -p "Install cvuqdisk: Completed - Press [Enter] to continue."
fi


# optVBoxChanges
if [ $optVBoxChanges -eq 1 ]; then
    printf "\nMaking VirtualBox Changes \n\n"
    usermod -aG vboxsf oracle
    if [ $optGridEnv -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"
printf "Uncomment out vm.nr_hugepages /etc/sysctl.conf and add\n"
printf "the value specified by Doc ID 401749.1's hugepages_settings.sh\n"
printf "\n*** Process Ended ***\n"