#!/bin/bash
ip=ifconfig|grep 'inet addr:'|grep -v '127.0.0.1'|cut -d: -f2 |awk '{ print $1}'
hostname=echo $HOSTNAME
echo "$ip $hostname ">>/etc/hosts
mem=grep MemTotal /proc/meminfo|awk '{print $2}'
shmmax=$(($mem/2*1024))
service iptables stop
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0
#install packages
yum -y install readline unzip binutilsx86_64 glibcx86_64 compat-libstdc++x86_64 elfutils-libelfx86_64 gccx86_64 ksh-x86_64 libaiox86_64 libgccx86_64 libstdc++x86_64 makex86_64 numactl-develx86_64 sysstat-9x86_64 compat-libstdc++i686 compat-libcap libXp libaio
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
echo oracle123|passwd oracle --stdin
mkdir -p /data/oracle //$ORACLE_BASE
mkdir -p /data/oracle/product/112010/db_1 //$ORACLE_HOME
mkdir /data/oracle/inventory
mkdir /data/oracle/oradata //存放数据库目录
mkdir /data/oracle/flash_recovery_area
chown -R oracle.oinstall /data/oracle
chmod -R 775 /data/oracle
mkdir /data/packages
ora_dir=/data/packages
mv /tmp/oraclepackages.zip $ora_dir
chown -R oracle.oinstall $ora_dir
##############################################
#modify sysctl.conf #
##############################################
sed -i -e "s/kernel.shmall./kernel.shmall = 2097152/" -e "s/kernel.shmmax./kernel.shmmax = $shmmax/" /etc/sysctl.conf
cat >> /etc/sysctl.conf <<done
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
fs.aio-max-nr = 1048576
done
sysctl -p
###############################################
#modify /etc/security/limits.conf #
###############################################
cat >> /etc/security/limits.conf << done
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
done
################################################
#modify /etc/pam.d/login #
################################################
echo "session required pam_limits.so">>/etc/pam.d/login
################################################
setting root env
################################################
cat >> /etc/profile <<done
if [ \$USER = "oracle" ]; then
if [ \$SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
done
source /etc/profile
################################################
setting user oracle env
################################################
cat >> /home/oracle/.bash_profile <<done
export ORACLE_BASE=/data/oracle;
export ORACLE_HOME=/data/oracle/product/112010/db_1
export ORACLE_SID=orcl;
export PATH=\$PATH:\$HOME/bin:\$ORACLE_HOME/bin
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/usr/lib
if [ \$USER = "oracle" ]; then
if [ \$SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
done
source /home/oracle/.bash_profile
################################################
upload install package and file
################################################
su - oracle -c "cd $ora_dir&&unzip $ora_dir/oraclepackages.zip&&unzip -q $ora_dir/linux.x64_11gR2_database_2of1.zip -d /data/oracle&&unzip -q $ora_dir/linux.x64_11gR2_database_2of2.zip -d /data/oracle"
cd $ora_dir&&tar -zxvf rlwrap-0.43.tar.gz&&cd rlwrap-0.43&&./configure&&make&&make install
su - oracle -c "mv $ora_dir/.rsp /data/oracle/database/response/"
su - oracle -c "sed -i 's/ORACLE_HOSTNAME./ORACLE_HOSTNAME=echo $RANDOM
' /data/oracle/database/response/db_install.rsp"
su - oracle -c "cd /data/oracle/database/&&./runInstaller -silent -responseFile /data/oracle/database/response/db_install.rsp -ignorePrereq"
cat << EOF
###########################################################################
安装完oracle,在root用户执行下面2条命令.
/data/oracle/inventory/orainstRoot.sh
/data/oracle/product/112010/db_1/root.sh
su - oracle
netca /silent /responseFile /data/oracle/database/response/netca.rsp
dbca -silent -responseFile /data/oracle/database/response/dbca.rsp
############################################################################
EOF