静默安装oracle脚本

#!/bin/bash
#----------install packages----------
echo 'multilib_policy=all' >> /etc/yum.conf
yum install -y binutils compat-libstdc++ elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-devel glibc-common glibc-headers ksh libaio \
libaio-devel libgcc libstdc++ libstdc++-devel make numactl-devel sysstat unixODBC unixODBC-devel elfutils-libelf-devel-static libgomp
#----------settiing the runInstaller file directory----------
staller_file='/home/linux.x64_11gR2/database'

#----------add oracle user and group----------
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
passwd -d oracle

#----------Modify kernel parameters----------
declare -i n1
declare -i n2
declare -i n3
declare -i n4
declare -i n5
declare -i n6
declare -i n7
declare -i n8
n1=`awk '/kernel.sem/{print NR}' /etc/sysctl.conf`
if [ $n1 -eq 0 ]
then
   echo 'kernel.sem=250 32000 100 128'>> /etc/sysctl.conf
else
    sed -i '/kernel.sem/d' /etc/sysctl.conf
    echo 'kernel.sem=250 32000 100 128'>> /etc/sysctl.conf
fi

n2=`awk '/fs.file-max/{print NR}' /etc/sysctl.conf`
if [ $n2 -eq 0 ]
then
   echo 'fs.file-max=6815744'>> /etc/sysctl.conf
else
    sed -i '/fs.file-max/d' /etc/sysctl.conf
    echo 'fs.file-max=6815744'>> /etc/sysctl.conf
fi

n3=`awk '/net.ipv4.ip_local_port_range/{print NR}' /etc/sysctl.conf`
if [ $n3 -eq 0 ]
then
   echo 'net.ipv4.ip_local_port_range = 9000 65500'>> /etc/sysctl.conf
else
    sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
    echo 'net.ipv4.ip_local_port_range = 9000 65500'>> /etc/sysctl.conf
fi

n4=`awk '/net.core.rmem_default/{print NR}' /etc/sysctl.conf`
if [ $n4 -eq 0 ]
then
   echo 'net.core.rmem_default = 262144'>> /etc/sysctl.conf
else
    sed -i '/net.core.rmem_default/d' /etc/sysctl.conf
    echo 'net.core.rmem_default = 262144'>> /etc/sysctl.conf
fi

n5=`awk '/net.core.rmem_max/{print NR}' /etc/sysctl.conf`
if [ $n5 -eq 0 ]
then
   echo 'net.core.rmem_max = 4194304'>> /etc/sysctl.conf
else
    sed -i '/net.core.rmem_max/d' /etc/sysctl.conf
    echo 'net.core.rmem_max = 4194304'>> /etc/sysctl.conf
fi

n6=`awk '/net.core.wmem_default/{print NR}' /etc/sysctl.conf`
if [ $n6 -eq 0 ]
then
   echo 'net.core.wmem_default = 262144'>> /etc/sysctl.conf
else
    sed -i '/net.core.wmem_default/d' /etc/sysctl.conf
    echo 'net.core.wmem_default = 262144'>> /etc/sysctl.conf
fi

n7=`awk '/net.core.wmem_max/{print NR}' /etc/sysctl.conf`
if [ $n7 -eq 0 ]
then
   echo 'net.core.wmem_max = 1048586'>> /etc/sysctl.conf
else
    sed -i '/net.core.wmem_max/d' /etc/sysctl.conf
   echo 'net.core.wmem_max = 1048586'>> /etc/sysctl.conf
fi

n8=`awk '/fs.aio-max-nr/{print NR}' /etc/sysctl.conf`
if [ $n8 -eq 0 ]
then
   echo 'fs.aio-max-nr = 1048576'>> /etc/sysctl.conf
else
    sed -i '/fs.aio-max-nr/d' /etc/sysctl.conf
    echo 'fs.aio-max-nr = 1048576'>> /etc/sysctl.conf
fi

/sbin/sysctl -p

#----------Modify user restrictions----------
echo 'oracle soft nofile 1024' >> /etc/security/limits.conf
echo 'oracle hard nofile 65536' >> /etc/security/limits.conf
echo 'oracle soft nproc 2047' >> /etc/security/limits.conf
echo 'oracle hard nproc 16384' >> /etc/security/limits.conf

echo 'session required /lib/security/pam_limits.so'>>/etc/pam.d/login
echo 'session required pam_limits.so'>>/etc/pam.d/login

#----------Modify /etc/profile----------
echo 'if [ $USER = "oracle" ]; then' >> /etc/profile
    echo 'if [ $SHELL = "/bin/ksh" ]; then' >> /etc/profile
        echo 'ulimit -p 16384' >> /etc/profile
        echo 'ulimit -n 65536' >> /etc/profile
    echo 'else ulimit -u 16384 -n 65536' >> /etc/profile
    echo 'fi' >> /etc/profile
echo 'fi' >> /etc/profile

#----------Modify selinux disabled----------

sed  's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux

#----------create oracle install dir----------
function input_install_dir(){
        echo 'Please input oracle install directory:'
        read arg1
if [ -z $arg1 ]
then
        echo '[error]:install directory cannot empty,please retry'
        input_install_dir
else
        mkdir -p $arg1
        chown -R oracle:oinstall $arg1
        chmod -R 755 $arg1
fi
}
input_install_dir

#----------oracle hostname----------
function input_hostname(){
        echo 'Plase input oracle hostname[localhost or hostname]:'
        read arg2
if [ -z $arg2 ]
then
        echo '[error]:ORACLE_HOSTNAME Cannot Empty,please retry'
        input_hostname
fi
}
input_hostname

#----------oracle sid name----------
function oracle_sid(){
        echo 'Plase input SID name:'
        read arg3
if [ -z $arg3 ]
then
        echo '[error]:SID Name cannot empty,please retry'
        oracle_sid
fi
}
oracle_sid

#----------setting oracle environment variable----------
#su - oracle -c "sed -i '/umask/d' ~/.bash_profile;sed -i '/export ORACLE_BASE/d' ~/.bash_profile;sed -i '/export ORACLE_SID/d' ~/.bash_profile"
su - oracle -c "echo '# .bash_profile'>~/.bash_profile; echo '# Get the aliases and functions' >> ~/.bash_profile;echo 'if [ -f ~/.bashrc ]; then' >> ~/.bash_profile;echo '. ~/.bashrc' >> ~/.bash_profile;echo 'fi' >> ~/.bash_profile;echo '# User specific environment and startup programs' >> ~/.bash_profile;echo 'PATH=\$PATH:\$HOME/bin' >> ~/.bash_profile;echo 'export PATH' >> ~/.bash_profile;echo 'umask 022' >> ~/.bash_profile;echo 'export ORACLE_BASE='$arg1'/oracle' >> ~/.bash_profile;echo 'export ORACLE_SID='$arg3 >> ~/.bash_profile;source ~/.bash_profile;unset ORACLE_HOME;unset TNS_ADMIN;unset DISPLAY"
#----------create oraInst.loc----------
rm -rf /etc/oraInst.loc
touch /etc/oraInst.loc
sed -i '/inventory_loc/d' /etc/oraInst.loc;sed -i '/inst_group/d' /etc/oraInst.loc
echo 'inventory_loc='$arg1'/oracle/oraInventory' >> /etc/oraInst.loc;echo 'inst_group=oinstall' >> /etc/oraInst.loc; chown oracle:oinstall /etc/oraInst.loc;chmod 664 /etc/oraInst.loc

#----------create response file----------
chown -R oracle:oinstall ../database
chmod -R 755 ../database
mkdir -p /home/oracle/etc
chown -R oracle:oinstall /home/oracle/etc
chmod -R 755 /home/oracle/etc
rm -rf /home/oracle/etc/*
cp -R response/* /home/oracle/etc

argtt1=$arg1'/oracle/oraInventory'
argtt2=$arg1'/oracle/product/11.2.0/dbhome_1'
argtt3=$arg1'/oracle'
sed  -i 's/oracle.install.option=/oracle.install.option=INSTALL_DB_SWONLY/' /home/oracle/etc/db_install.rsp
sed  -i 's/ORACLE_HOSTNAME=/ORACLE_HOSTNAME='$arg2'/' /home/oracle/etc/db_install.rsp
sed  -i 's/UNIX_GROUP_NAME=/UNIX_GROUP_NAME=oinstall/' /home/oracle/etc/db_install.rsp
sed  -i 's#INVENTORY_LOCATION=#INVENTORY_LOCATION='$argtt1'#' /home/oracle/etc/db_install.rsp
sed  -i 's/SELECTED_LANGUAGES=/SELECTED_LANGUAGES=zh_CN,en,zh_TW/' /home/oracle/etc/db_install.rsp
sed  -i 's#ORACLE_HOME=#ORACLE_HOME='$argtt2'#' /home/oracle/etc/db_install.rsp
sed  -i 's#ORACLE_BASE=#ORACLE_BASE='$argtt3'#' /home/oracle/etc/db_install.rsp
sed  -i 's/oracle.install.db.InstallEdition=/oracle.install.db.InstallEdition=EE/' /home/oracle/etc/db_install.rsp
sed  -i 's/oracle.install.db.DBA_GROUP=/oracle.install.db.DBA_GROUP=dba/' /home/oracle/etc/db_install.rsp
sed  -i 's/oracle.install.db.OPER_GROUP=/oracle.install.db.OPER_GROUP=dba/' /home/oracle/etc/db_install.rsp
sed  -i 's/DECLINE_SECURITY_UPDATES=/DECLINE_SECURITY_UPDATES=true/' /home/oracle/etc/db_install.rsp
#----------create dbca response file----------
sed  -i 's/GDBNAME = "orcl11.us.oracle.com"/GDBNAME =orcl/' /home/oracle/etc/dbca.rsp
sed  -i 's/SID = "orcl11g"/SID = '$arg3'/' /home/oracle/etc/dbca.rsp
argt1=$arg1'/oracle/oradata'
argt2=$arg1'/oracle/flash_recovery_area'
sed  -i 's#\#DATAFILEDESTINATION =#DATAFILEDESTINATION ='$argt1'#' /home/oracle/etc/dbca.rsp
sed  -i 's#\#RECOVERYAREADESTINATION=#RECOVERYAREADESTINATION='$argt2'#' /home/oracle/etc/dbca.rsp
sed  -i 's/\#CHARACTERSET = "US7ASCII"/#CHARACTERSET = "AL32UTF8"/' /home/oracle/etc/dbca.rsp
sed  -i 's/\#NATIONALCHARACTERSET= "UTF8"/NATIONALCHARACTERSET= "UTF8"/' /home/oracle/etc/dbca.rsp
#----------setting oracle environment variable----------
function set_env(){
echo 'start setting oracle environment variable......'
su - oracle -c "echo 'export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/dbhome_1' >> ~/.bash_profile;echo 'export TNS_ADMIN=\$ORACLE_HOME/network/admin' >> ~/.bash_profile;echo 'export PATH=.:\${PATH}:\$HOME/bin:\$ORACLE_HOME/bin' >> ~/.bash_profile;echo 'export PATH=\${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin' >> ~/.bash_profile;echo 'export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\$ORACLE_HOME/lib' >> ~/.bash_profile;echo 'export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\$ORACLE_HOME/oracm/lib' >> ~/.bash_profile;echo 'export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib' >> ~/.bash_profile;echo 'export CLASSPATH=\${CLASSPATH}:$ORACLE_HOME/JRE' >> ~/.bash_profile;echo 'export CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/JRE/lib' >> ~/.bash_profile;echo 'export CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/jlib' >> ~/.bash_profile;echo 'export CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/rdbms/jlib ' >> ~/.bash_profile;echo 'export CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/network/jlib' >> ~/.bash_profile;echo 'export LIBPATH=\${CLASSPATH}:\$ORACLE_HOME/lib:\$ORACLE_HOME/ctx/lib' >> ~/.bash_profile;echo 'export ORACLE_OWNER=oracle' >> ~/.bash_profile;echo 'export SPFILE_PATH=\$ORACLE_HOME/dbs' >> ~/.bash_profile;echo 'export ORA_NLS10=\$ORACLE_HOME/nls/data ' >> ~/.bash_profile;source ~/.bash_profile"
env
echo 'setting oracle environment variable successfull!'
}
#----------setting network start----------
function netca(){
echo 'start setting network ......'
su - oracle -c $argtt2"/bin/netca /silent /responseFile /home/oracle/etc/netca.rsp"
declare -i p2
sum2=0
while(($sum2<=10))
do
    sleep 1
        if [ $sum2 -gt 3 ]
        then
            p1=`ps -ef|grep netca |grep -v "grep" |awk '{print $2}'`
            if [ $p2 -eq 0 ]
            then
                echo 'Setting Network Successfull!'
                sleep 3
                dbca
                break
            fi
            sum2=1
    fi
let "sum2++"
done
}
#----------run dbca----------
function dbca(){
echo 'Create Database Now[Y|Ctr+C exit]?'
read answer
if [ -z $answer ]
then
    echo '[error]:install directory cannot empty,please retry'
    dbca
elif [ $answer == 'Y' ]
then
    echo 'start create database ......'
    su - oracle -c $argtt2"/bin/dbca -silent -responseFile /home/oracle/etc/dbca.rsp"
    echo 'create database Successfull!'
else
    dbca
fi
}
#----------install database start----------
echo 'start install database......'
su - oracle -c $staller_file"/runInstaller -silent -debug -force -responseFile /home/oracle/etc/db_install.rsp"
declare -i p1
sum=0
while(($sum<=10))
do
    sleep 1
        if [ $sum -gt 3 ]
        then
            echo 'ok' >> /home/oracle/1.txt
            p1=`ps -ef|grep oracle.installer |grep -v "grep" |awk '{print $2}'`
            if [ $p1 -eq 0 ]
            then
                echo 'Oracle Database Install Successfull'
                sleep 1
                set_env
                sleep 30
                netca
                break
            fi
            sum=1
    fi
    echo $sum >> /home/oracle/1.txt
let "sum++"
done

 

posted @ 2017-05-03 15:22  杯中红茶  阅读(1081)  评论(1编辑  收藏  举报