问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

linux下编写一个shell脚本,实现自动安装软件

发布网友 发布时间:2022-04-23 04:40

我来回答

5个回答

懂视网 时间:2022-05-02 16:26


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 "33[32m********************************************************************33[0m"
    echo -e "33[32m*33[0m"$@""
    echo -e "33[32m********************************************************************33[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 ' '

#-----------------------------------------------------------------------------------------------
# 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 ' '
     #read -p  "Are you sure to install the patch[yes or y]:" SELECT
     #printf ' '
     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 "33[32m**********************************************************33[0m"
    echo -e "33[32m*33[0m"$@""
    echo -e "33[32m**********************************************************33[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 "33[32m********************************************************************33[0m"
    echo -e "33[32m*33[0m"$@""
    echo -e "33[32m********************************************************************33[0m"
    echo ""
}
#-----------------------------------------------------------------------------------------------
CheckPath(){
    if [ ! -n "$path" ]; then
       printf " You input is invalid! "
       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! "
    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 ' please 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 ' please 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 ' please 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 " " " "| while read LINE
#do
# EXPECT <<EOF
# spawn sh ./sshUserSetup.sh -user $LINE -hosts $NODES -verify -advanced
#        expect {
#        "yes/no" { send "yes ";exp_continue }
#  "yes' or 'no" { send "yes ";exp_continue }
#        "password:"{send "$PASSWORD ";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 " " " "| 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 "

expect "*?assword:*"

send -- "$PASSWD "

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

expect "$USER_PROMPT"

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

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

send -- "yes "

} "$USER_PROMPT" {send -- " "}

expect "$USER_PROMPT"

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

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

send -- "yes "

expect "*?assword:*"

send -- "$PASSWD "

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

expect "$USER_PROMPT"

send -- "exit "

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 "

expect "$USER_PROMPT"

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

expect "*?assword:*"

send -- "$PASSWD "

expect "$USER_PROMPT"

send -- "exit "

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   

热心网友 时间:2022-05-02 13:34

yum clean all
yum install -y binutils compat-db compat-libstdc++* control-center \
gcc gcc-c++ glibc glibc-common libstdc++ libstdc++-devel libXp make \
ksh sysstat setarch
if [ $? -eq 0 ];then
echo "Software is ready for install oracle!"
fi

热心网友 时间:2022-05-02 14:52

Linux下Oracle的自动安装脚本,基本上就是yes和no

分享一个Linux下安装ASM+ORACLE的自动化脚本
http://blog.csdn.net/johnlongyuan/article/details/48416019

热心网友 时间:2022-05-02 16:26

不知道

热心网友 时间:2022-05-02 18:18

晕。。。要不要懒到这种程度啊?
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
...下图方式对折一分为二裁开成为A2纸(如图(2) 明信片怎么样固定 为什么我的高考录取通知书还没有到? 梦见我孙女光秃秃的躺在路上的预兆 师兄请按剧本来分集剧情介绍(第1-40全集)大结局,几点更新,在哪个台播出... 发挥什么优势 三合一烤肠机接煤气罐接口可以换方向吗 关于福睿斯4年,3万公里保养问题请教? 福睿斯水箱加水在哪里 福睿斯水箱加水在哪里加 CSGO武器箱怎么获得 CSGO武器箱钥匙在哪买便宜 linux怎么执行一键安装脚本 怎么在linux下创建一个可运行脚本? 在Linux shell脚本中,安装过程中如何实现自动选择安装选项? linux中怎样执行脚本? 如何在redhat Linux中安装脚本程序 linux如何用脚本安装需要交互的软件 腾讯大王卡在腾讯视频下载视频免流吗? 跪求腾讯视频免费看的电视剧,【免费高清】在线观看百度网盘资源 【合集】腾讯视频的电视剧大全免费,【免费高清】在线观看百度网盘资源 盘点腾讯视频2021年新版,【在线观看】免费百度云资源 跪求腾讯视频大全免费观看,【在线观看】免费百度云资源 腾讯王卡用腾讯视频下载视频免流量吗? 下载腾讯视频收费吗? linux下进程如何查看什么时候停止,哪个用户停止的 linux系统下用jps命令查看java进程,提示process information unavailab... linux环境下ps命令查看找不到java进程是为什么? 如何查看java进程及服务? 冰箱制冷不好 压缩机上面热下面冷 是怎么回事? 家里洗澡间用浴霸上面暖和下面冷怎么办? 怎么做凉拌? linux上多个软件顺序安装的脚本怎么写 枕头发黄怎么洗?3种方法轻松解决 如何理解儿童的先天素质是遗传基因和胎儿发育过程的环境因素之间复杂的相互作 少儿先天畸形是怎样引起的? 儿童先天性听力损失是什么原因造成的? 你认为儿童的语言是先天的还是后天的? 标题儿童先天出生缺陷这一学科形成的标志性事件是什么? 小儿先天性腱鞘炎如何治疗? 儿童先天大散光怎么改善? 儿童得了先天性侏儒症能治好吗? 天才儿童,是先天遗传还是后天塑造? 买二套房,宁波各大银行的贷款利率是多少 宁波购买第二套房政策 今日起!宁波四大行房贷利率全部上调,二套房上浮15% 支付宝刷脸登录在哪怎么用,支付宝没有刷脸登录 支付宝刷脸在哪 支付宝刷脸登录怎么设置 得了雷诺综合征怎么治?得了雷诺氏综合征该怎么治疗? 支付宝刷脸认证在哪里,怎么设置 雷诺综合征的治疗 雷诺氏症怎么样治疗,是吃药还是手术