#!/bin/bash
MEM_SIZE=$(grep MemTotal /proc/meminfo | awk '{print $2}')
SWAP_SIZE=$(grep SwapTotal /proc/meminfo | awk '{print $2}')
TMP_DIR="/tmp"
ORA_INSTALL_DIR="/"
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db
ORACLE_SID=orcl
function die()
{
echo "[ERROR ]:$*"
exit 1
}
function check_software_requirements()
{
#check Software Requirements
local rpm_err=0
local rpms="libXp binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel \
glibc glibc-common glibc-devel gcc gcc-c++ libaio-devel libaio libgcc \
libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pdksh \
setarch"
for pkg in $rpms;do
rpm -q $pkg || rpm_err=$(expr $rpm_err + 1)
done
[ $rpm_err -eq 0 ] && return 0 || return 1
}
function check_hardware_requirements()
{
local mem_size=$MEM_SIZE
local swap_size=$SWAP_SIZE
local tmpdir_size=$(df -m "$TMP_DIR" | awk '/\/$/{print $4}')
local oracledir_size=$(df -m "$ORA_INSTALL_DIR" | awk '/\/$/{print $4}')
#check mem size and swap size
if [ $mem_size -ge 1048576 -a $mem_size -lt 2072576 ];then
expswapsize=$( awk "BEGIN{m=$mem_size * 1.5;printf \"%.f\",m}" )
[ $swap_size -lt $expswapsize ] && echo "[WARNING]:men_size=$mem_size,swap_size=$swap_size,swap is less than mem * 1.5."
elif [ $mem_size -ge 2072576 -a $mem_size -lt 16580608 ];then
expswapsize="$mem_size"
[ $swap_size -lt $expswapsize ] && echo "[WARNING]:men_size=$mem_size,swap_size=$swap_size,swap is less than mem"
elif [ $mem_size -ge 16580608 ];then
expswapsize=$(expr $mem_size * 0.75 )
[ $swap_size -lt $expswapsize ] && echo "[WARNING]:men_size=$mem_size,swap_size=$swap_size,swap is less than mem * 0.75."
else
die "physical RAM is less than 1024M."
fi
#check tmp and oracle install directory size
[ -z $tmpdir_size ] && die "get tmp dir size fail."
[ $tmpdir_size -lt 400 ] && die "tmp dir size is less than 400M."
[ -z $oracledir_size ] && die "get oracle install dir size fail."
[ $oracledir_size -lt 3584 ] && die "oracle install dir size is less than 3.5G."
}function check_network()
{
local temp=$(cat /etc/nsswitch.conf | grep "^hosts")
[ -z "$temp" ] && die "nsswitch.conf file isn't contain hosts."
local temp=$(cat /etc/hosts | grep `eval hostname`)
[ -z "$temp" ] && die "hosts file isn't contain hostname."
}
function cfg_kernel_parameter()
{
sed -ri '/kernel.sem/d;
/kernel.shmall/d;
/kernel.shmmax/d;
/kernel.shmmni/d;
/fs.file-max/d;
/net.ipv4.ip_local_port_range/d;
/net.core.rmem_default/d;
/net.core.rmem_max/d;
/net.core.wmem_default/d;
/net.core.wmem_max/d' /etc/sysctl.conf
echo "kernel.sem=250 32000 100 128
kernel.shmall=2097152
kernel.shmmax=2147483648
kernel.shmmni=4096
fs.file-max=65536
net.ipv4.ip_local_port_range=1024 65000
net.core.rmem_default=1048576
net.core.rmem_max=1048576
net.core.wmem_default=262144
net.core.wmem_max=262144" >> /etc/sysctl.conf
}
function create_user_group()
{
[ -f /etc/oraInst.loc ] && die "/etc/oraInst.loc is exists."
groupadd -g 111 dba
groupadd -g 110 oinstall
useradd oracle -u 110 -g 110 -G 111
echo oracle | passwd oracle --stdin
}
function cfg_ora_env()
{
mkdir -p $ORACLE_BASE
chown -R oracle.oinstall $ORACLE_BASE
echo "ORACLE_BASE=$ORACLE_BASE
ORACLE_HOME=$ORACLE_HOME
ORACLE_SID=$ORACLE_SID
PATH=$ORACLE_HOME/BIN:$PATH
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
" >> /home/oracle/.bash_profile
}
xhost +
check_software_requirements
check_hardware_requirements
check_network
cfg_kernel_parameter
create_user_group
cfg_ora_env
阅读(2546) | 评论(0) | 转发(0) |