Linux環境一鍵自動化安裝oracle軟件的構想(附shell腳本)

1、自動化批量安裝ORACLE軟件的構想
一、1構想從哪裏來?
熟悉PXE+KICKSTART一鍵批量安裝Liunx操做系統的童鞋都知道,該方式可實現快速定製,規範化,自動化的無人值守安裝。基於此方式,安裝oracle軟件也可經過相似方式實現。
一、2爲何要自動化安裝oracle軟件
 可實現自動化,批量化,省時省力快速安裝(如一次性安裝10個oracle客戶端)。
 使安裝軟件更加標準化,規範化(如UID,GID,安裝目錄等保持一致,便與管理)。
 oracle安裝介質同一存放,易於管理和維護。
2、自動化批量安裝ORACLE軟件的架構
二、1自動化批量安裝oracle軟件的大體架構
基本實現思路是:搭建軟件資源庫,提供HTTP或FTP服務,並提供YUM服務,而後下發安裝oracle軟件所須要的文件,所需安裝軟件的服務器做爲客戶端,接收文件,經過shell腳本實現自動化配置安裝的成所需的數據庫環境。node

111122.png

 

二、2搭建軟件資源庫服務
這裏經過tomcat搭建一個WEB站點,提供HTTP的服務(過程略,經過apache、vsftp等也是能夠實現相同功能的),搭建後的效果以下:
linux

1111232323.png

二、3製做響應RESPONSE文件模板
c++

20180122205238.png

 

3、實現自動化靜默安裝的SHELL腳本(LINUX平臺)shell


(腳本還存在還得須要調整的地方,但願有興趣的朋友一塊兒繼續完成,這裏先將我個思路分享出來,有興趣的童鞋,歡迎一塊兒研究,或者有好的方法一塊兒改寫)數據庫


三、1靜默安裝oracle軟件shell主體(install_oracle_main.sh)apache

#!/bin/sh -
#!/usr/bin/sh
#--------------------------------------------------------------------------------
# Install softeare -- Install oracle 11g database software
#
# History: 2018/01/14 zhuwei First release
#--------------------------------------------------------------------------------centos

# set a safe path before doing anything else
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATHtomcat

# This script must be executed as root
RUID=`/usr/bin/id|awk -F\( '{print $1}'|awk -F\= '{print $2}'`bash

if [ ${RUID} != "0" ] ; then
    echo "This script must be executed as root"
    exit 1
fi服務器

# Display a usage message and exit
usage() {
    cat >&2 <<EOF
Usage:
    ./install_oracle_main.sh  [options]

options:
    --client: version[11.2.0.3|11.2.0.4]
    --db: type[rac|signle] version[11.2.0.3|11.2.0.4]

examples:
    ./install_oracle_main.sh client
 ./install_oracle_main.sh db rac 11.2.0.4
 ./install_oracle_main.sh db signle 11.2.0.4
 
EOF
    exit 1
}

# Retrieve name of the platform
PLATFORM=`uname`
PWD=`pwd`
WEBSITE="http://172.16.1.20/zwdir"
NUM_OF_NODES=3
NODE1="node1"
NODE2="node2"
NODE3="node3"
PASSWD="Rootpasswd"

if [ ${PLATFORM} = "HP-UX" ] ; then
    echo "This script does not support HP-UX platform for the time being"
elif [ ${PLATFORM} = "SunOS" ] ; then
    echo "This script does not support SunOS platform for the time being"
elif [ ${PLATFORM} = "AIX" ] ; then
    echo "This script does not support AIX platform for the time being"
elif [ ${PLATFORM} = "Linux" ] ; then
    TYPE1=$1
    TYPE2=$2
    VERSION=$3
    case ${TYPE1} in
    db|DB)
        case ${TYPE2} in
        rac|RAC)
            case ${VERSION} in
                11.2.0.3|11.2.0.4|12.1.0.2)
     sh ${PWD}/install_rpm.sh
                    sh ${PWD}/install_configure.sh ${TYPE2}
              sh ${PWD}/create_user.sh ${TYPE2} ${PASSWD}
     #如下兩個腳本暫未徹底調整好
           sh ${PWD}/ssh_setup.sh ${NUM_OF_NODES} ${NODE1} ${NODE2} ${PASSWD}
     sh ${PWD}/silent_install.sh ${TYPE2} ${VERSION}
     ;;
          *)
     usage
           ;;
             esac
   ;;
        signle|SIGNLE)
      case ${VERSION} in
                11.2.0.3|11.2.0.4|12.1.0.2)
        sh ${PWD}/install_rpm.sh
                    sh ${PWD}/install_configure.sh ${TYPE2}
     #如下兩個腳本暫未徹底調整好
              sh ${PWD}/create_user.sh ${TYPE2} ${PASSWD}
     sh ${PWD}/silent_install.sh ${TYPE2} ${VERSION}
     ;;
          *)
     usage
           ;;
             esac
   ;;
        *)
   usage
   ;;
     esac
  ;;
    client|CLIENT) #暫未將安裝客戶端的腳本考慮進來
     sh ${PWD}/install_rpm.sh
        sh ${PWD}/install_configure.sh
  sh ${PWD}/create_user.sh
  sh ${PWD}/silent_install.sh ${TYPE2} ${VERSION}
  ;;
    *)
  usage
        ;;
    esac
fi


三、2RPM包安裝及配置(install_rpm.sh)

#!/bin/sh -
#!/usr/bin/sh
#-----------------------------------------------------------------------------------------------
# Install softeare -- Install oracle 11g database software
#
# History: 2018/01/14 zhuwei First release
#-----------------------------------------------------------------------------------------------

# set a safe path before doing anything else
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH

# This script must be executed as root
RUID=`/usr/bin/id|awk -F\( '{print $1}'|awk -F\= '{print $2}'`

if [ ${RUID} != "0" ] ; then
    echo "This script must be executed as root"
    exit 1
fi

# Display an error and exit
errorExit() {
    echo "$@" >&2
    exit 1
}

# Display the normal print
displayheader() {
    echo -e "\033[32m********************************************************************\033[0m"
    echo -e "\033[32m*\033[0m"$@""
    echo -e "\033[32m********************************************************************\033[0m"
    echo ""
}

# Detect and install oracle rpm package you need

if [ -e "/etc/oracle-release" ] ; then
    VERSION1=`sed -n '1p' /etc/issue|awk 'BEGIN{OFS=""} {print $1,$2,$7}'`
    VERSION2=`sed -n '1p' /etc/issue|awk 'BEGIN{OFS=""} {print $1,$2,$7}'|awk -F. '{print $1}'`
elif [ -e "/etc/redhat-release" ] ; then
    VERSION1=`sed -n '1p' /etc/issue|awk 'BEGIN{OFS=""} {print $1,$2,$7}'`
    VERSION2=`sed -n '1p' /etc/issue|awk 'BEGIN{OFS=""} {print $1,$2,$7}'|awk -F. '{print $1}'`
elif [ -e "/etc/SuSE-release" ] ; then
    VERSION1=`sed  '/^$/d' /etc/issue|awk 'BEGIN{OFS=""} {print $3,$7,$8}'`
    VERSION2=`sed  '/^$/d' /etc/issue|awk 'BEGIN{OFS=""} {print $3,$7}'`
elif [ -e "/etc/centos-release" ] ; then
    VERSION1=`sed -n '1p' /etc/issue|awk 'BEGIN{OFS=""} {print $1,$2,$7}'`
    VERSION2=`sed -n '1p' /etc/issue|awk 'BEGIN{OFS=""} {print $1,$2,$7}'|awk -F. '{print $1}'`
fi


#VALUE=`/usr/bin/getconf LONG_BIT`
OSDIGIT=`/bin/uname -m`
YUM=`which yum`
P_YUM="/etc/yum.repos.d/"

#-----------------------------------------------------------------------------------------------
# Download yum client configure file
if [ -d $P_YUM ] ; then
   mv $P_YUM /etc/yum.repos.d.bak
   mkdir -p $P_YUM
fi
/usr/bin/wget -N -q -P $P_YUM $1/rhelrepo/$VERSION2.repo \
|| errorExit 'Failed to download the yum client files,Please manually configure!'
/bin/sed -i 's/RedHat/'$VERSION1\_$OSDIGIT'/g' $P_YUM$VERSION2.repo \
|| errorExit 'Replace the files is not successful,Please manually configure!'
if [ -f $P_YUM$VERSION2.repo ]; then
    displayheader "Successfully configured yum client, please continue"
fi

#-----------------------------------------------------------------------------------------------
# RedHat 5 and RedHat 6 install oracle software required RPM package
#-----------------------------------------------------------------------------------------------
#Red Hat Enterprise Linux 5:The following packages (or later versions) must be installed:
Red5=(binutils-2* compat-libstdc++-33* elfutils-libelf-0.* elfutils-libelf-devel-0.* \
elfutils-libelf-devel-static-0.* gcc-4.* gcc-c++-4*  glibc-2.* glibc-common-2.* glibc-devel-2.* \
glibc-headers-2* kernel-headers-2.* libaio-0.* libaio-devel-0.* libgcc-4.* libgomp-4.* \
libstdc++-4.* libstdc++-devel-* make-* numactl-devel-* sysstat-* pdksh-* ksh-* \
unixODBC-* unixODBC-devel-*)

#Red Hat Enterprise Linux 6:The following packages (or later versions) must be installed:
Red6=(binutils-2* compat-libstdc++-33* elfutils-libelf-0.* elfutils-libelf-devel-0.* \
gcc-4.* gcc-c++-4* glibc-2.* glibc-common-2.* glibc-devel-2.* glibc-headers-2* \
kernel-headers-2.* libaio-0.* libaio-devel-0.* libgcc-4.* libgomp-4.* libstdc++-4.* \
libstdc++-devel-* make-* numactl-devel-* sysstat-* ksh-* unixODBC-* unixODBC-devel-*)

#Red Hat Enterprise Linux 7:The following packages (or later versions) must be installed:
Red7=(binutils-2* compat-libstdc++-33* elfutils-libelf-0.* elfutils-libelf-devel-0.* \
gcc-4.* gcc-c++-4* glibc-2.* glibc-common-2.* glibc-devel-2.* glibc-headers-2* \
kernel-headers-2.* libaio-0.* libaio-devel-0.* libgcc-4.* libgomp-4.* libstdc++-4.* \
libstdc++-devel-* make-* numactl-devel-* sysstat-* ksh-* unixODBC-* unixODBC-devel-*)

#SUSE 11 packages: The following packages (or later versions) must be installed:
Suse11=(binutils-2.* gcc-4.* gcc-c++-4.* glibc-2.9* glibc-devel-2.9* ksh-* libstdc++33-* \
libstdc++43-* libstdc++43-devel-* libaio-* libaio-devel-* libgcc43-* libstdc++-devel-* \
make-* sysstat-*)

rlen5=${#Red5[@]}
rlen6=${#Red6[@]}
rlen7=${#Red7[@]}
slen11=${#Suse11[@]}

COUNT=0

#-----------------------------------------------------------------------------------------------
# Test your system has been installed the RPM package
displayheader "You have installed the required RPM package is as follows:"
if [ $VERSION2 == "RedHat5" or  $VERSION2 == "Centos5" or  $VERSION2 == "Oracle5" ] ; then
for((i=0;i<rlen5;i++));
do
        CHAR=${Red5[$i]}
        rpm -qa | grep "^$CHAR"
        if [ $? != 0 ] ; then
                UNINSTALL[$COUNT]=${Red5[$i]}
                COUNT=$(($COUNT+1))
        fi
done
fi

if [ $VERSION2 == "RedHat6" or $VERSION2 == "Centos6" or $VERSION2 == "Oracle6" ] ; then
for((i=0;i<len6;i++));
do
        CHAR=${Red6[$i]}
        rpm -qa | grep "^$CHAR"
        if [ $? != 0 ] ; then
                UNINSTALL[$COUNT]=${Red6[$i]}
                COUNT=$(($COUNT+1))
        fi
done
fi

if [ $VERSION2 == "RedHat7" or $VERSION2 == "Centos7" or $VERSION2 == "Oracle7" ] ; then
for((i=0;i<len7;i++));
do
        CHAR=${Red7[$i]}
        rpm -qa | grep "^$CHAR"
        if [ $? != 0 ] ; then
                UNINSTALL[$COUNT]=${Red7[$i]}
                COUNT=$(($COUNT+1))
        fi
done
fi

if [ $VERSION2 == "SUSE11" ] ; then
for((i=0;i<slen11;i++));
do
        CHAR=${Suse11[$i]}
        rpm -qa | grep "^$CHAR"
        if [ $? != 0 ] ; then
                UNINSTALL[$COUNT]=${Suse11[$i]}
                COUNT=$(($COUNT+1))
        fi
done
fi

printf '\n'

#-----------------------------------------------------------------------------------------------
# Will not install the RPM packages for installation
if [ $COUNT -gt "0" ];then
     displayheader "Do you have "$COUNT" rpm package not installed,not installed patch is:"
     len=${#UNINSTALL[@]}
     for((j=0;j<len;j++));
     do
         echo "${UNINSTALL[$j]}"
     done
     printf '\n'
     #read -p  "Are you sure to install the patch[yes or y]:" SELECT
     #printf '\n'
     if [ $SELECT == "yes" -o $SELECT == "y" ]; then
         for((l=0;l<len;l++));
         do
             VAR=${UNINSTALL[$l]}
    #         if [ $VAR == "pdksh-5.2.14-36.el5.x86_64.rpm" ]; then
    #            rpm -qa ksh-*
    #            if [ $? == 0 ]; then
    #              yum -q -y remove ksh-* >/dev/null 2 > &1
    #            fi
    #         fi
             yum -q -y install $VAR  >/dev/null 2 > &1
         done
     fi
else
    displayheader "Required RPM packages have been installed"
fi


三、3系統配置及yum服務配置(install_configure.sh)


#!/bin/sh -
#!/usr/bin/sh
#--------------------------------------------------------------------------------
# Install softeare -- Install oracle 11g database software
#
# History: 2018/01/14 zhuwei First release
#--------------------------------------------------------------------------------

# set a safe path before doing anything else
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH

# This script must be executed as root
RUID=`/usr/bin/id|awk -F\( '{print $1}'|awk -F\= '{print $2}'`

if [ ${RUID} != "0" ] ; then
    echo "This script must be executed as root"
    exit 1
fi

# Display an error and exit
errorExit() {
    echo "$@" >&2
    exit 1
}

# Display the normal print
displayheader() {
    echo -e "\033[32m**********************************************************\033[0m"
    echo -e "\033[32m*\033[0m"$@""
    echo -e "\033[32m**********************************************************\033[0m"
    echo ""
}

prepareSystem(){
# Set SElinux to disabled mode regardless of its initial value
  sed -i -e 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
  setenforce 0
# stop iptables
  /etc/init.d/iptables stop > /dev/null 2>&1
# *** Chkconfig section
# Turn off unwanted services
  chkconfig --level 0123456 iptables off
  chkconfig --level 0123456 ip6tables off
}

#Configure the kernel params
Configure1(){
    cat >> /etc/sysctl.conf <<EOF
fs.aio-max-nr = 1048576
fs.file-max = 6815744
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
EOF
    if [ $? != 0 ]; then
        errorExit 'Unable to configure sysctl settings for database'
    fi

 return 0
}

Configure_signle(){
    cat >> /etc/security/limits.conf <<EOF
oracle   soft  nproc   2047
oracle   hard  nproc   16384
oracle   soft  nofile  1024
oracle   hard  nofile  65536
EOF
   if [ $? != 0 ]; then
        errorExit 'Unable to configure settings for database'
   fi
  
   return 0
}

Configure_rac(){
    cat >> /etc/security/limits.conf <<EOF
oracle   soft  nproc   2047
oracle   hard  nproc   16384
oracle   soft  nofile  1024
oracle   hard  nofile  65536
grid   soft  nproc   2047
grid   hard  nproc   16384
grid   soft  nofile  1024
grid   hard  nofile  65536
EOF
   if [ $? != 0 ]; then
        errorExit 'Unable to configure settings for database'
   fi
  
   return 0
}

Configure3(){
    cat >> /etc/pam.d/login <<EOF
session    required     pam_limits.so
EOF
   if [ $? != 0 ]; then
        errorExit 'Unable to configure settings for database'
   fi
  
   return 0
}

if [ $1 == "rac" ] || [ $1 == "RAC" ] ; then
  prepareSystem Configure1 && Configure_rac && Configure3 || errorExit ""
  if [ -f /etc/ntp.conf ]; then
    mv /etc/ntp.conf /etc/ntp.conf.bak
   /etc/init.d/ntpd stop > /dev/null 2>&1
    chkconfig --level 0123456 ntpd off
  fi
elif [ $1 == "signle" ] || [ $1 == "SIGNLE" ] ; then
  prepareSystem Configure1 && Configure_signle && Configure3 || errorExit ""
fi


三、4軟件安裝用戶創建及用戶環境配置(create_user.sh)

#!/bin/sh -
#!/usr/bin/sh
#-----------------------------------------------------------------------------------------------
# Install softeare -- Install oracle 11g database software
#
# History: 2018/01/14 zhuwei First release
#-----------------------------------------------------------------------------------------------

# set a safe path before doing anything else
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH

# This script must be executed as root
RUID=`/usr/bin/id|awk -F\( '{print $1}'|awk -F\= '{print $2}'`

if [ ${RUID} != "0" ] ; then
    echo "This script must be executed as root"
    exit 1
fi

upassword=$2

# Display an error and exit
errorExit() {
    echo "$@" >&2
    exit 1
}

# Display the normal print
displayheader() {
    echo -e "\033[32m********************************************************************\033[0m"
    echo -e "\033[32m*\033[0m"$@""
    echo -e "\033[32m********************************************************************\033[0m"
    echo ""
}
#-----------------------------------------------------------------------------------------------
CheckPath(){
    if [ ! -n "$path" ]; then
       printf "\n\tYou input is invalid!\n"
       GetPath $1
    fi
    if [ ! -d "$path" ]; then
    mkdir -p $path
    pathsize=`df "$path"|sed '1d' |awk '{print $4}'`
       if [ $pathsize -lt 31457820 ] ; then
       printf "The path -ge 30gb will be created! \n"
    rm -rf $path
          GetPath $1
       else 
          return 0
       fi
    else
    #path=`echo "$path"|awk -F "/" '{print $NF}'`
 pathsize=`df "$path"|sed '1d' |awk '{print $4}'`
       if [ $pathsize -lt 31457820 ] ; then
          GetPath $1
       else
          return 0
       fi
 fi
}

AuzPath(){
    if [ $i == "oracle_base" ] ; then
   chown -R oracle:oinstall $path
   chmod -R 775 `dirname $path`
 elif [ $i == "grid_base" ] ; then
   chown -R grid:oinstall $path
   chmod -R 775 `dirname $path`
 elif [ $i == "grid_home" ] ; then
   chown -R root:oinstall `dirname $path`
   chmod -R 775 `dirname $path`
 fi
}

GetPath(){
  paths=(oracle_base grid_base grid_home)
  printf '\nplease input the path of '${paths[0]}':'
  read install_path
  path=$install_path
  if CheckPath $path
  then
    i=${paths[0]}
    AuzPath $i $path
  fi
  obase=`grep -w "ORACLE_BASE=" /home/oracle/.bash_profile |awk -F"=" '{print $2}'`
  sed -i "s#${obase}#$path#" /home/oracle/.bash_profile
  if [ $1 == "rac" ] || [ $1 == "RAC" ] ; then
    printf '\nplease input the path of '${paths[1]}':'
    read install_path
    path=$install_path
    if CheckPath $path
    then
    i=${paths[1]}
       AuzPath $i $path
    fi
 gbase=`grep -w "ORACLE_BASE=" /home/grid/.bash_profile |awk -F"=" '{print $2}'`
 sed -i "s#${gbase}#$path#" /home/grid/.bash_profile
 printf '\nplease input the path of '${paths[2]}':'
    read install_path
    path=$install_path
    if CheckPath $path
    then
   i=${paths[2]}
      AuzPath $i $path
    fi
 ghome=`grep -w "ORACLE_HOME=" /home/grid/.bash_profile |awk -F"=" '{print $2}'`
 sed -i "#${ghome}#$path#" /home/grid/.bash_profile
  fi
}

#-----------------------------------------------------------------------------------------------
#Configure the oracle user's environment
profile(){
    cat > /home/${user[j]}/.bash_profile <<EOF
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
 . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
export TMP=/tmp
export TMPDIR=\$TMP
export ORACLE_SID=test
export ORACLE_BASE=/u/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/db_1
export TNS_ADMIN=\$ORACLE_HOME/network/admin
export ORACLE_TERM=xterm
export PATH=/usr/sbin:\$PATH
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib:\$ORACLE_HOME/jdbc/lib
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
export NLS_LANG="AMERICAN_AMERICA.ZHT16BIG5"
export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'
umask 022
if [ $USER = "oracle" ]; then
  if [ $SHELL = "/bin/ksh" ]; then
    ulimit -p 16384
    ulimit -n 65536
  else
    ulimit -u 16384 -n 65536
  fi
fi
EOF
    if [ $? != 0 ]; then
       errorExit 'bash_profile this file does not exist'
 fi
 
 return 0
}
#-----------------------------------------------------------------------------------------------
#In the table below for the list of users and user groups
#
#   User Name          User ID
#   ---------          -------
#   oracle             601
#   grid               602
#
#   Group Name         Group ID
#   ---------          -------
#   oinstall           601
#   dba                602
#   asmadmin           603
#   asmdba             604
#   oper               605
#   asmoper            606
#Add Users and Groups
adduser_rac(){
  group=(oinstall dba asmadmin asmdba oper asmoper)
  user=(oracle grid)
  groups=`echo ${group[@]:1:4}|tr " " ","`
  for((i=0;i<${#group[@]};i++));
  do
    groupexit=`grep -w ${group[i]} /etc/group | awk -F: '{print $1}'`
 if [ -z ${groupexit} ]; then
   groupadd -g `expr 600 + $i + 1` ${group[i]} || errorExit ""
 else
   groupmod -g `expr 600 + $i + 1` ${group[i]} || errorExit ""
 fi
  done
  for((j=0;j<${#user[@]};j++));
  do
    userexit=`grep -w ${user[j]} /etc/shadow | awk -F: '{print $1}'`
 if [ -z ${userexit} ]; then
   useradd -d /home/${user[j]} -u `expr 600 + $j + 1` -g ${group[0]} \
   -G ${groups} ${user[j]} && echo ${user[j]}:${upassword}|chpasswd \
   && profile ${user[j]} || errorExit ""
 else
   usermod -u `expr 600 + $j + 1` ${user[j]} && echo ${user[j]}:${upassword}|chpasswd \
   && profile ${user[j]} || errorExit ""
 fi
  done
}

adduser_sigle(){
  group=(oinstall dba)
  for((i=0;i<${#group[@]};i++));
  do
    groupexit=`grep -w ${group[i]} /etc/group | awk -F: '{print $1}'`
 if [ -z ${groupexit} ]; then
   groupadd -g `expr 600 + $i + 1` ${group[i]} || errorExit ""
 else
   groupmod -g `expr 600 + $i + 1` ${group[i]} || errorExit ""
 fi
  done
  userexit=`grep -w oracle /etc/shadow | awk -F: '{print $1}'`
  if [ -z ${userexit} ]; then
 useradd -d /home/oracle -u `expr 600 + $j + 1` -g oinstall \
 -G oracle && echo oracle:${upassword}|chpasswd && profile ${user[j]} || errorExit ""
  else
 usermod -u `expr 600 + $j + 1` oracle && echo oracle:${upassword}|chpasswd \
 && profile ${user[j]} || errorExit ""
  fi 
}
#-----------------------------------------------------------------------------------------------
if [ $1 == "rac" ] || [ $1 == "RAC" ] ; then
  adduser_rac $upassword && GetPath $1 || errorExit ""
elif [ $1 == "signle" ] || [ $1 == "SIGNLE" ] ; then
  adduser_sigle $upassword && GetPath $1 || errorExit ""
fi


三、5 RAC安裝的SSH等效配置(sshUserSetup.sh)

#!/bin/bash

#--------------------------------------------------------------------------------------
#這裏原本是想着調用oracle安裝包裏面的sshUserSetup.sh進行SSH配置的,發現存在問題
#echo $USER | tr " " "\n"| while read LINE
#do
# EXPECT <<EOF
# spawn sh ./sshUserSetup.sh -user $LINE -hosts $NODES -verify -advanced
#        expect {
#        "yes/no" { send "yes\r";exp_continue }
#  "yes' or 'no" { send "yes\r";exp_continue }
#        "password:"{send "$PASSWORD\r";exp_continue }
#              }
# EXPECT eof
#EOF
#done
#---------------------------------------------------------------------------------------

NUM_OF_NODES=$1
NODE1=$2
NODE2=$3
NODE3=$4
LINE="root oracle grid"
EXPECT=/usr/bin/expect
PASSWD=$5
#USER_PROMPT="*$ "
USER_PROMPT="*# "

#如下腳本還未進行大批量的測試,有興趣的童鞋歡迎一塊兒研究
echo $LINE | tr " " "\n"| while read USER
do
if [ "x${NODE1}" == "x" -o "x${USER}" == "x" -o "x${PASSWD}" == "x" ]; then

echo ""

echo "Please set the NODE INFO, USER and PASSWD"

echo "then $0 to start..."

exit 1

fi

declare -i l_i=1

while [ $l_i -le $NUM_OF_NODES ]

do

eval l_current_node=\$NODE$l_i

$EXPECT <<EOF

spawn ssh $USER@$l_current_node

expect "*(yes/no)?*" {

send -- "yes\r"

expect "*?assword:*"

send -- "$PASSWD\r"

} "*?assword:*" {send -- "$PASSWD\r"}

expect "$USER_PROMPT"

send -- "ssh-keygen -t rsa -q -f ~/.ssh/id_rsa -P '' \r"

expect "*Overwrite (yes/no)? " {

send -- "yes\r"

} "$USER_PROMPT" {send -- "\r"}

expect "$USER_PROMPT"

send -- "cat ~/.ssh/id_rsa.pub | ssh $USER@$NODE1 'cat - >> ~/.ssh/authorized_keys' \r"

expect "*(yes/no)?*" {

send -- "yes\r"

expect "*?assword:*"

send -- "$PASSWD\r"

} "*?assword:*" {send -- "$PASSWD\r"}

expect "$USER_PROMPT"

send -- "exit\r"

EOF

((l_i++))

done

declare -i l_n=1

while [ $l_n -le $NUM_OF_NODES ]

do

eval l_current_node=\$NODE$l_n

$EXPECT <<EOF

spawn ssh $USER@$NODE1

expect "*?assword:*" {

send -- "$PASSWD\r"

expect "$USER_PROMPT"

} "$USER_PROMPT" {send -- "scp ~/.ssh/authorized_keys $l_current_node:~/.ssh/ \r"}

expect "*?assword:*"

send -- "$PASSWD\r"

expect "$USER_PROMPT"

send -- "exit\r"

EOF

((l_n++))

done
done


三、6安裝介質下載並執行靜默安裝(silent_install.sh)

#!/bin/sh -
#!/usr/bin/sh
#-----------------------------------------------------------------------------------------------
# Install softeare -- Install oracle 11g database software
#
# History: 2018/01/14 zhuwei First release
#-----------------------------------------------------------------------------------------------
#暫時未調整好以下的腳本
# set a safe path before doing anything else
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH

# This script must be executed as root
RUID=`/usr/bin/id|awk -F\( '{print $1}'|awk -F\= '{print $2}'`

if [ ${RUID} != "0" ] ; then
    echo "This script must be executed as root"
    exit 1
fi

WEBSITE=$1
HOSTNAME=`hostname`
PATH1="/u/database/response"
ORACLE_BASE=`grep -w "ORACLE_BASE=" /home/oracle/.bash_profile |awk -F"=" '{print $2}'`
GRID_BASE=`grep -w "ORACLE_BASE=" /home/grid/.bash_profile |awk -F"=" '{print $2}'`
GRID_HOME=`grep -w "ORACLE_HOME=" /home/grid/.bash_profile |awk -F"=" '{print $2}'`

#-----------------------------------------------------------------------------------------------
#Configure the oracle silent installation files
#暫時未調整好以下的腳本
silent_oracle(){
 ORACLE_BASE="\/u\/app\/oracle"
 ORACLE_HOME=${ORACLE_BASE}"\/product\/11\.2\.0\/db_1"
 A1="ORACLE_HOSTNAME\="
 A2="INVENTORY_LOCATION\="
 A3="ORACLE_HOME\="
 A4="ORACLE_BASE\="
 B1=${A1}${HOSTNAME}
 B2=${A2}${ORACLE_BASE}"\/oraInventory"
 B3=${A3}${ORACLE_HOME}
 B4=${A4}${ORACLE_BASE}
 mv -f $PATH1/db_install.rsp $PATH1/db_install.rsp.bak
 wget -N -q -P  $PATH1 $WEBSITE/oracle11g/db_install.rsp
 sed -i -e "s/${A1}/${B1}/g" -e "s/${A2}/${B2}/g" -e "s/${A3}/${B3}/g" \
 -e "s/${A4}/${B4}/g" $PATH1/db_install.rsp || errorExit "The configuration file failed!"
}
#暫時未調整好以下的腳本
silent_grid(){
 ORACLE_BASE="\/u\/app\/oracle"
 ORACLE_HOME=${ORACLE_BASE}"\/product\/11\.2\.0\/db_1"
 A1="ORACLE_HOSTNAME\="
 A2="INVENTORY_LOCATION\="
 A3="ORACLE_HOME\="
 A4="ORACLE_BASE\="
 B1=${A1}${HOSTNAME}
 B2=${A2}${ORACLE_BASE}"\/oraInventory"
 B3=${A3}${ORACLE_HOME}
 B4=${A4}${ORACLE_BASE}
 mv -f $PATH1/db_install.rsp $PATH1/db_install.rsp.bak
 wget -N -q -P  $PATH1 $WEBSITE/oracle11g/db_install.rsp
 sed -i -e "s/${A1}/${B1}/g" -e "s/${A2}/${B2}/g" -e "s/${A3}/${B3}/g" \
 -e "s/${A4}/${B4}/g" $PATH1/db_install.rsp || errorExit "The configuration file failed!"
}

#download oracle software
download(){

    wget -N -q -P $ORACLE_BASE  $WEBSITE/$2/p*_[1-3]of7.zip
 
    unzip -q -d $ORACLE_BASE $ORACLE_BASE/p*_1of7.zip
    unzip -q -d $ORACLE_BASE $ORACLE_BASE/p*_2of7.zip
 unzip -q -d $ORACLE_BASE $ORACLE_BASE/p*_3of7.zip
 
    rm -rf /u/p*_[1-3]of7.zip
 
    chown -R oracle:oinstall $ORACLE_BASE/database
}
#暫時未調整好以下的腳本
if [ $1 == "rac" ] || [ $1 == "RAC" ] ; then
  chmod a+x ${PATH1}/db_install.rsp
  chown oracle:oinstall ${PATH1}/db_install.rsp
  su - oracle -c "/u/database/./runInstaller -silent -force -responseFile \
  ${PATH1}/db_install.rsp -ignoreSysPrereqs" >>/dev/null
elif [ $1 == "signle" ] || [ $1 == "SIGNLE" ] ; then
  chmod a+x ${PATH1}/db_install.rsp
  chown oracle:oinstall ${PATH1}/db_install.rsp
  su - oracle -c "/u/database/./runInstaller -silent -force -responseFile \
  ${PATH1}/db_install.rsp -ignoreSysPrereqs" >>/dev/null
fi


三、7 配置腳本執行用法

20180122205403.png

因腳本化,須要考慮的問題還有不少,因此還有不少細節須要調整,腳本目前只給出的框架,有興趣的童鞋,歡迎一塊兒研究,或者有好的方法一塊兒改寫。

4、克隆安裝ORACLE軟件實現補丁一同安裝四、1 克隆安裝ORACLE的可行性經過上面的安裝過程,細心的你必定發現,只是安裝了oracle軟件,而相應要打的PSU並無打上,有沒辦法安裝和打補丁一塊兒呢?有,那就是克隆。爲了保證克隆安裝後,不出現問題,首先要保證tar包的準確性,這種安裝方式用於生產環境是有必定風險的,但對於開發環境和測試環境,我以爲是可行的。四、2 克隆安裝ORACLE的大概步驟系統環境準備,ip、/etc/hosts等這些配置,以後再執行其它環境配置的腳本克隆安裝oracle軟件shell主體(install_oracle_main.sh)系統配置及tar安裝介質下載(install_configure.sh)RPM包安裝及配置(install_rpm.sh)軟件安裝用戶創建及用戶環境配置(create_user.sh)RAC安裝的SSH等效配置(ssh_setup.sh)進行克隆安裝,這裏考慮的地方仍是蠻多的,難點也在於ASM的克隆,如果RAC,OCR的註冊這些。用戶的uid、gid是否一致,須要安裝的oracle home目錄是否一致等。5、延伸擴展(定製ORACLE安裝的ISO鏡像文件)熟悉操做系統安裝和ORACLE的童鞋都知道,咱們在Linux環境安裝ORACLE的時候都知道,不少服務都是用 不到的,好比bluetooth藍牙、cups打印服務這些都是不須要的,像這類服務若是在安裝操做系統的時候多安裝了,並開啓了確定是會佔用必定的資源的。這裏有個構想,使用UltraISO直接製做安裝ORACLE的ISO鏡像,去除沒必要要服務RPM包,將oracle安裝包」database」加入到ISO鏡像中,直接在安裝操做系統的同時,一同安裝數據庫。有興趣的童鞋能夠研究一下。

相關文章
相關標籤/搜索