用shell脚本配置Oracle安装需求

用shell脚本配置Oracle安装需求

1.配置好yum
yum -y install libXp
yum -y install libaio

2.按照自己的需求修改chprofile文件内的SID

3.rpm -ivh rlwrap-0.30-1.el5.i386.rpm

4.执行脚本  #install目录下存放了一下脚本:adduser.sh、chprofile.sh、install.sh、limits.sh、mkdir.sh、sysctl.sh
./install

adduser脚本内容

#/bin/bash
ADDGROUPS="oinstall dba"
ADDUSERS="oracle"
for group in $ADDGROUPS ; do
        if [ -z "$( awk -F: '{print $1}' /etc/group |grep $group)" ]; then
                groupadd  $group
                echo " Add new group $group"
        else
                echo " Group $group already existed"
        fi 
done
for user in $ADDUSERS ; do
        if [ -z "$( awk -F: '{print $1}' /etc/passwd |grep $user)" ]; then
                useradd  $user
                echo " Add new user $user"
        else
                echo " User $user already existed"
        fi
done
if $(usermod -g oinstall -G dba oracle) ;  then
  echo " Modify user oracle account success"
else
  echo " Modify user oracle account failure"
fi
chprofile脚本内容
#/bin/bash
PROFILES="/home/oracle/.bashrc"
for PROFILE in $PROFILES ; do
if [ -f "$PROFILE" ] ; then
        if [ -z "$(grep "Oracle" $PROFILE)" ] ; then
                cat >>$PROFILE << END
# Oracle configure profile parameters success
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/10.2.0/db_1
export PATH=\$ORACLE_HOME/bin:\$PATH
export ORACLE_OWNER=oracle
export ORACLE_SID=cctv
export ORACLE_TERM=vt100
export THREADS_FLAG=native
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$LD_LIBRARY_PATH
export PATH=\$ORACLE_HOME/bin:\$PATH
export SQLPATH=/home/oracle
export EDITOR=vi
alias sqlplus='rlwrap sqlplus'
#
# change this NLS settings to suit your country:
# example:
# german_germany.we8iso8859p15, american_america.we8iso8859p2 etc.
#
export LANG=en_US
END
                echo " Add Oracle configure $PROFILE parameters success"
        else
                echo " Oracle configure $PROFILE parameters already existed"
        fi
else
        echo "$0: $PROFILE not found "
fi
done
install脚本内容
#/bin/bash
. ./adduser.sh
. ./sysctl.sh
. ./limits.sh
. ./mkdir.sh
. ./chprofile.sh
limits脚本内容
#/bin/bash
LIMITS_FILE="/etc/security/limits.conf"
if [ -f "$LIMITS_FILE" ] ; then
        if [ -z "$(grep "Oracle" $LIMITS_FILE)" ] ; then
                cat >>$LIMITS_FILE << END
#Oracle configure  shell parameters
oracle soft nofile 65536
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
END
                echo " Add Oracle configure  shell parameters success"
        else
                echo " Oracle configure  shell parameters already existed"
        fi
else
        echo "$0: $LIMITS_FILE not found "
fi
mkdir脚本内容
#/bin/bash
ORACLE_FILE_BASE="/u01/app/oracle"
ORACLE_FILE_VAR="/var/opt/oracle"
ORACLE_FILE_HOME="$ORACLE_FILE_BASE/product/10.2.0/db_1"
for directory in $ORACLE_FILE_BASE $ORACLE_FILE_VAR $ORACLE_FILE_HOME ; do
        if [ -d $directory ]; then
                echo " Directory $directory  already existed"
        else
                mkdir -p $directory
                chown -R oracle.dba $directory
                echo " Change directory $directory owner and group success"
        fi
done     
sysctl脚本内容
#/bin/bash
# echo 250 32000 100 128 > /proc/sys/kernel/sem
# echo 536870912 > /proc/sys/kernel/shmmax
# echo 4096 > /proc/sys/kernel/shmmni
# echo 2097152 > /proc/sys/kernel/shmall
# echo 65536 > /proc/sys/fs/file-max
# echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range
SYSCTL_FILE="/etc/sysctl.conf"
RCLOCAL_FILE="/etc/rc.local"
if [ -f "$SYSCTL_FILE" ] ; then
        if [ -z "$(grep "Oracle" $SYSCTL_FILE)" ] ; then
                cat >>$SYSCTL_FILE << END
#Oracle configure kernel parameters
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 262144
net.core.rmem_max = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 262144
END
                /sbin/sysctl -p
                echo " Add Oracle configure kernel parameters success"
        else
                echo " Oracle configure kernel parameters already existed"
        fi
else
        if [ -z "$(grep "Oracle" $RCLOCAL_FILE)" ] ; then
                cat >>$RCLOCAL_FILE << END
#Oracle configure kernel parameters
echo 536870912 > /proc/sys/kernel/shmmax
echo 4096 > /proc/sys/kernel/shmmni
echo 2097152 > /proc/sys/kernel/shmall
echo 250 32000 100 128 > /proc/sys/kernel/sem
echo 65536 > /proc/sys/fs/file-max
echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range
END
                . $RCLOCAL_FILE
                echo " Add Oracle configure kernel parameters success"
        else
                echo " Oracle configure kernel parameters already existed"
        fi
fi

推荐阅读:

相关推荐