欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Oracle->oracle单实例Shell脚本[20180122]

程序员文章站 2022-04-11 08:37:47
脚本主要用于redhat平台安装11g和12c软件 依赖包检查与安装 用户、组检查与安装 系统内核、用户限制 防火墙、selinux关闭 注意,linux组脚本中只创建了dba,通常会创建oinstall和dba ################# # # #create : 2018/01/22 ......
脚本主要用于redhat平台安装11g和12c软件
    依赖包检查与安装
    用户、组检查与安装
    系统内核、用户限制
    防火墙、selinux关闭
    注意,linux组脚本中只创建了dba,通常会创建oinstall和dba
 
#################
#
#
#create : 2018/01/22
#version : v0.0
#describe : Oracle 11g/12c setup single instance install environment
#参考网址 http://blog.csdn.net/xcl168/article/details/19571443
http://blog.51cto.com/hxw168/1424626
#################
 
DATE=`date +%Y%m%d%H%M%S`
SYSCTLCONF="/etc/sysctl.conf"
LIMITSCONF="/etc/security/limits.conf"
LOGINFILE="/etc/pam.d/login"
PROFILE="/etc/profile"
YUMFILE="/etc/yum.repos.d/rhel-source.repo"
 
echo -e "\nTo determine the distribution and version of Linux installed.\n"
echo "`cat /proc/version`"
 
echo -e "\nTo determine whether the required kernel is installed.\n"
echo "`uname -a`"
 
echo -e  "\nLeast 4GB of RAM.\n"
echo "`grep MemTotal /proc/meminfo`"
 
echo -e "\nTo determine the size of the configured swap space,enter the following command.\n"
echo "`grep SwapTotal /proc/meminfo`"
 
echo -e "\nChecking the Software Requirements.\n"
yes|cp -p ${YUMFILE} ${YUMFILE}.bak.${DATE}
 
read -p "Enter installl oracle version:[12c]" ORA_VERSION
#echo "You have entered ${ORA_VERSION}"
 
if [ -z "${ORA_VERSION}" ];then
ORA_VERSION="12c"
fi
echo "You have entered ${ORA_VERSION}"
if [ ${ORA_VERSION} == "12c" ];then
rpmpack="
binutils
compat-libstdc++*
elfutils-libelf
elfutils-libelf-devel
gcc
gcc-c++
glibc
glibc-common
glibc-devel
glibc-headers
kernel-headers
ksh
libaio
libaio-devel
libgcc
libgomp
libstdc++
libstdc++-devel
make
sysstat
unixODBC
unixODBC-devel"
else
rpmpack="
binutils
compat-libstdc++*
elfutils-libelf
elfutils-libelf-devel
elfutils-libelf-devel-static
gcc
gcc-c++
glibc
glibc-common
glibc-devel
glibc-headers
kernel-headers
pdksh
libaio
libaio-devel
libgcc
libgomp
libstdc++
libstdc++-devel
make
sysstat
unixODBC
unixODBC-devel"
 
fi
 
read -p "Enter yum source address:" URL_PTAH
#echo "You have entered ${URL_PTAH}"
echo ${#URL_PTAH}
 
if [ ${#URL_PTAH} -gt 0 ];then
echo "You have entered ${URL_PTAH}"
`grep ${URL_PTAH} ${YUMFILE} > /dev/null`
if [ $? -ne 0 ];then
echo "#add yum resouce ${DATE}" >${YUMFILE}
echo "[rhel-source]" >>${YUMFILE}
echo "name=Red Hat Enterprise Linux \$releasever - \$basearch - Source" >>${YUMFILE}
echo "baseurl=${URL_PTAH}" >>${YUMFILE}
echo "enabled=1" >>${YUMFILE}
echo "gpgcheck=0" >>${YUMFILE}
echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release" >>${YUMFILE}
fi
yum grouplist
fi
 
for pack in $rpmpack; do
        rpm -qa | grep  $pack > /dev/null
        if [ $? -eq 1 ];then
                echo "$pack not install"
                yum -y install $pack
        fi
        echo "rpm -qa | grep  $pack  is already install."
#read -p "Enter yum source address:" URL_PTAH
#echo "You have entered ${URL_PTAH}"
 
 
done
 
echo -e  "\nTo determine if the Oracle Inventory group exit.\n"
echo "  `grep oinstall /etc/group`"
echo "  `grep dba /etc/group`"
 
echo -e "\nTo determine whether the oraInstall.loc file exists.\n"
echo "`cat /etc/oraInst.loc`"
#################################
 
#################################
 
echo -e "\nCreating Required Operating System Groups and Users.\n"
`grep dba /etc/group > /dev/null`
if [ $? -ne 0 ];then
echo "groupadd dba"
`groupadd dba`
fi
 
`grep oracle /etc/passwd > /dev/null`
if [ $? -ne 0 ]; then
echo "useradd -g dba oracle"
`useradd -g dba oracle`
echo "oracle#1234" | `passwd --stdin oracle`
fi
 
echo "`id oracle`"
 
if [ ! -d "/u01/app/oracle" ];then
echo -e  "\nmkdir -p /u01/app/oracle\nmkdir -p /u01/app/oraInventory\nmkdir -p /u01/app/oracle/product/11.2.0/dbhome_1\nchown -R oracle.dba /u01\nchmod -R 775 /u01\n"
mkdir -p /u01/app/oracle
mkdir -p /u01/app/oraInventory
if [ ${ORA_VERSION} == "12c" ];then
mkdir -p /u01/app/oracle/product/12.2.0/dbhome_1
else
mkdir -p /u01/app/oracle/product/11.2.0/dbhome_1
fi
chown -R oracle.dba /u01
chmod -R 775 /u01
fi
ls -al /u01
 
#############################
 
#SYSCTLCONF="/etc/sysctl.conf"
#LIMITSCONF="/etc/security/limits.conf"
#LOGINFILE="/etc/pam.d/login"
#PROFILE="/etc/profile"
 
#############################
echo -e  "\nCheckResource Limits for the Oracle Software Installation Users.\n"
yes|cp -p ${LIMITSCONF} ${LIMITSCONF}.bak.${DATE}
 
echo -e "\nInstallation Owner Resource Limit Recommended Ranges.\n"
`grep "#add limit" ${LIMITSCONF}  > /dev/null`
if [ $? -ne 0 ];then
echo "#add limit  ${DATE}" >>${LIMITSCONF}
fi
 
`grep "oracle soft nproc 2047" ${LIMITSCONF}  > /dev/null`
if [ $? -ne 0 ];then
echo "oracle soft nproc 2047" >> ${LIMITSCONF}
fi
 
`grep "oracle hard nproc 16384" ${LIMITSCONF}  > /dev/null`
if [ $? -ne 0 ];then
echo "oracle hard nproc 16384" >> ${LIMITSCONF}
fi
 
`grep "oracle soft nofile 1024" ${LIMITSCONF}  > /dev/null`
if [ $? -ne 0 ];then
echo "oracle soft nofile 1024" >> ${LIMITSCONF}
fi
 
`grep "oracle hard nofile 65536" ${LIMITSCONF}  > /dev/null`
if [ $? -ne 0 ];then
echo "oracle hard nofile 65536" >> ${LIMITSCONF}
fi
 
echo "`tail -n 5 /etc/security/limits.conf`"
########################
 
########################
echo -e "\nConfiguring Kernel Parameters for Linux.\n"
yes|cp -p ${SYSCTLCONF} ${SYSCTLCONF}.bak.${DATE}
 
`grep "#add sysctl" ${SYSCTLCONF} > /dev/null`
if [ $? -ne 0 ];then
echo "#add sysctl ${DATE}" >> ${SYSCTLCONF}
fi
 
`grep "kernel.shmmni = 4096" ${SYSCTLCONF} > /dev/null`
if [ $? -ne 0 ];then
echo "kernel.shmmni = 4096" >> ${SYSCTLCONF}
fi
`grep "kernel.sem = 250 32000 100 142" ${SYSCTLCONF} > /dev/null`
if [ $? -ne 0 ];then
echo "kernel.sem = 250 32000 100 142" >> ${SYSCTLCONF}
fi
`grep "fs.aio-max-nr = 1048576" ${SYSCTLCONF} > /dev/null`
if [ $? -ne 0 ];then
echo "fs.aio-max-nr = 1048576" >> ${SYSCTLCONF}
fi
`grep "fs.file-max = 6815744" ${SYSCTLCONF} > /dev/null`
if [ $? -ne 0 ];then
echo "fs.file-max = 6815744" >> ${SYSCTLCONF}
fi
`grep "net.ipv4.ip_local_port_range = 9000 65000" ${SYSCTLCONF} > /dev/null`
if [ $? -ne 0 ];then
echo "net.ipv4.ip_local_port_range = 9000 65000" >> ${SYSCTLCONF}
fi
`grep "net.core.rmem_default = 262144" ${SYSCTLCONF} > /dev/null`
if [ $? -ne 0 ];then
echo "net.core.rmem_default = 262144" >> ${SYSCTLCONF}
fi
`grep "net.core.rmem_max = 4194304" ${SYSCTLCONF} > /dev/null`
if [ $? -ne 0 ];then
echo "net.core.rmem_max = 4194304" >> ${SYSCTLCONF}
fi
`grep "net.core.wmem_default =262144" ${SYSCTLCONF} > /dev/null`
if [ $? -ne 0 ];then
echo "net.core.wmem_default =262144" >> ${SYSCTLCONF}
fi
`grep "net.core.wmem_max = 1048576" ${SYSCTLCONF} > /dev/null`
if [ $? -ne 0 ];then
echo "net.core.wmem_max = 1048576" >> ${SYSCTLCONF}
fi
/sbin/sysctl -p
########################
 
#######################
echo -e "\nedit /etc/pam.d/login file:\n"
yes|cp -p ${LOGINFILE} ${LOGINFILE}.bak.${DATE}
 
`grep "session    required     pam_limits.so" ${LOGINFILE} >/dev/nulll`
if [ $? -ne 0 ];then
echo "#add login ${DATE}" >>${LOGINFILE}
echo "session    required     pam_limits.so" >> ${LOGINFILE}
fi
echo "`tail -n 2 ${LOGINFILE}`"
#######################
 
######################
echo -e "\nedit /etc/pfole file:\n"
yes|cp -p ${PROFILE} ${PROFILE}.bak.${DATE}
 
`grep "#add ulimit profile" ${PROFILE} >/dev/null`
if [ $? -ne 0 ];then
echo "#add ulimit profile ${DATE}" >>${PROFILE}
echo "if [ \$USER = \"oracle\" ]; then" >>${PROFILE}
echo " if [ \$SHELL = \"/bin/ksh\" ]; then" >>${PROFILE}
echo " ulimit -p 16384" >>${PROFILE}
echo " ulimit -n 65536" >>${PROFILE}
echo " else" >>${PROFILE}
echo " ulimit -u 16384 -n 65536" >>${PROFILE}
echo " fi" >> ${PROFILE}
echo "fi" >>${PROFILE}
fi
echo "`tail -n 9 ${PROFILE}`"
######################
 
#####################
echo -e "\nDisabled system firewall.\n"
`chkconfig iptables off&&chkconfig ip6tables off&&service iptables stop&&service ip6tables stop`
echo `chkconfig --list|grep iptables`
echo `chkconfig --list|grep ip6tables`
#####################
 
 
#####################
echo -e "\nDisabled system selinux.\n"
`sed -i 's/^SELINUX=enforcing/#SELINUX=enforcing/g' /etc/selinux/config`
`grep "^SELINUX=disabled" /etc/selinux/config >/dev/null`
if [ $? -ne 0 ];then
echo "SELINUX=disabled" >> /etc/selinux/config
fi
echo "`cat -n /etc/selinux/config|grep SELINUX`"
#####################