当前位置:Gxlcms > 数据库问题 > Linux环境一键自动化安装oracle软件的构想(附shell脚本)

Linux环境一键自动化安装oracle软件的构想(附shell脚本)

时间:2021-07-01 10:21:17 帮助过:22人阅读


3、1静默安装oracle软件shell主体(install_oracle_main.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 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


3、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、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


3、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


3、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


3、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


3、7 配置脚本执行用法

技术分享图片

因脚本化,需要考虑的问题还有很多,所以还有很多细节需要调整,脚本目前只给出的框架,有兴趣的童鞋,欢迎一起研究,或者有好的方法一起改写。


四、克隆安装ORACLE软件实现补丁一同安装
4、1 克隆安装ORACLE的可行性
通过上面的安装过程,细心的你一定发现,只是安装了oracle软件,而相应要打的PSU并没有打上,有没办法安装和打补丁一起呢?有,那就是克隆。为了保证克隆安装后,不出现问题,首先要保证tar包的准确性,这种安装方式用于生产环境是有一定风险的,但对于开发环境和测试环境,我觉得是可行的。
4、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目录是否一致等。
五、延伸扩展(定制ORACLE安装的ISO镜像文件)
熟悉操作系统安装和ORACLE的童鞋都知道,我们在Linux环境安装ORACLE的时候都知道,很多服务都是用 不到的,比如bluetooth蓝牙、cups打印服务这些都是不需要的,像这类服务如果在安装操作系统的时候多安装了,并开启了肯定是会占用一定的资源的。这里有个构想,使用UltraISO直接制作安装ORACLE的ISO镜像,去除不必要服务RPM包,将oracle安装包”database”加入到ISO镜像中,直接在安装操作系统的同时,一同安装数据库。有兴趣的童鞋可以研究一下。

 

Linux环境一键自动化安装oracle软件的构想(附shell脚本)

标签:function   安装过程   work   led   dba   installer   examples   mod   info   

人气教程排行