CentOS 6.9下Oracle 11gR2 静默安装单实例(待优化版)

功能:实现环境的修改和补丁的补全

#!/bin/bash
# oracle 11g R2 for linux 安装辅助脚本
# Redkey
# version 1.3
# date 2017.10.19
#定义常量
SYSCTL=/etc/sysctl.conf
LIMITS=/etc/security/limits.conf
PAM=/etc/pam.d/login
PROFILE=/etc/profile
BASH_PROFILE=/home/oracle/.bash_profile
#循环变量
i=1
#定义显示颜色
#颜色定义 信息(33黄色) 警示(31红色) 过程(36浅蓝)
#判断执行用户是否root
isroot()
{
if [ $USER != "root" ];then
echo -e "\n\e[1;31m the user must be root,and now you user is $USER,please su to root. \e[0m"
exit4
else
echo -e "\n\e[1;36m check root ... OK! \e[0m"
fi
}
yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-common glibc-devel gcc gcc-c++ libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pdksh compat-db control-center libstdc++ libstdc++-devel xscreensaver openmotif21 ksh* compat-libcap* zip unzip
#挂在光盘到/mnt/cdrom目录下
#mount_cdrom()
#{
#echo -e "\n\e[1;31m please insert RHEL to CDROM,press any key ...\e[0m"
#read -n 1
#if [ -d /mnt/cdrom ];then
# mount -t auto -o ro /dev/cdrom /mnt/cdrom
#else
# mkdir -p /mnt/cdrom
# mount -t auto -o ro /dev/cdrom /mnt/cdrom
#fi
#if [ $? -eq 0 ];then
# echo -e "\n\e[1;36m CDROM mount on /mnt/cdrom ... OK! \e[0m"
#fi
#}
#设置yum本地光盘源
#yum_repo()
#{
# rm -rf /etc/yum.repos.d/* && cat <<EOF >> /etc/yum.repos.d/Server.repo
#[Server]
#name=MyRPM
#baseurl=file:///mnt/cdrom/Server
#enabled=1
#gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-RedHat-release
#EOF
#if [ $? -eq 0 ];then
#echo -e "\n\e[1;36m /etc/yum.repos.d/Server.repo ... OK! \e[0m"
#fi
#}
#添加oracle用户,添加oracle用户所属组oinstall及附加组dba
ouseradd()
{
if [[ `grep "oracle" /etc/passwd` != "" ]];then
userdel -r oracle
fi
if [[ `grep "oinstall" /etc/group` = "" ]];then
groupadd oinstall
fi
if [[ `grep "dba" /etc/group` = "" ]];then
groupadd dba
fi
useradd oracle -g oinstall -G dba && echo $1 |passwd oracle --stdin
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m oracle's password updated successfully --- OK! \e[0m"
else
echo -e "\n\e[1;31m oracle's password set faild. --- NO!\e[0m"
fi
}
#检查oracle所需软件包并安装
packagecheck()
{
for package in binutils compat-libcap1 compat-libstdc++ gcc gcc-c++ glibc glibc-devel ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel make sysstat
do
rpm -q $package 2> /dev/null
if [ $? != 0 ];then
yum -y install $package
echo -e "\n\e[1;36m $package is already installed ... OK! \e[0m"
fi
done
}
#安装桌面套件 X Window System / Desktop
#xdesk()
#{
# yum -y groupinstall "X Window System" "Desktop"
#}
# 设置内核参数

kernelset()
{
cp $SYSCTL{,.bak} && cat <<EOF >>$SYSCTL
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
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 = 1048575
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m kernel parameters updated successfully --- OK! \e[0m"
fi
sysctl -p
}
#设置oracle资源限制
oralimit()
{
cp $LIMITS{,.bak} && cat <<EOF >> $LIMITS
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m $LIMITS updated successfully ... OK! \e[0m"
fi
}
#设置login文件
setlogin()
{
cp $PAM{,.bak} && cat <<EOF >>$PAM
session required pam_limits.so
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m $PAM updated successfully ... OK! \e[0m"
fi
}
#设置profile文件
setprofile()
{
cp $PROFILE{,.bak} && cat <<EOF >>$PROFILE
if [ $USER = "oracle" ];then
if [ $SHELL = "/bin/ksh" ];then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m $PROFILE updated successfully ... OK! \e[0m"
fi
}
#设置oracle的profile文件
setbash_profile()
{
cp $BASH_PROFILE{,.bak} && cat <<EOF >> $BASH_PROFILE
umask 022
ORACLE_BASE=/home/oracle/app
ORACLE_HOME=/home/oracle/app/product/11.2.0/db_1
ORACLE_SID=orcl
PATH=$ORACLE_HOME/bin/:$PATH
LANG=en_US.UTF-8
stty erase ^H
export ORACLE_BASE ORACLE_HOME ORACLE_SID
EOF
if [ $? -eq 0 ];then
echo -e "\n\e[1;36m $BASH_PROFILE updated successfully ... OK! \e[0m"
fi
. $BASH_PROFILE
}
#系统环境检查
oscheck()
{
#查看内存大小是否大于1G
echo -e "\n check MEM Size ..."
if [ `cat /proc/meminfo | grep MemTotal | awk '{print $2}'` -lt 1048576 ];then
echo -e "\n\e[1;33m Memory Small \e[0m"
exit 1
else
echo -e "\n\e[1;36m Memory checked PASS \e[0m"
fi
#查看tmp空间大小
echo -e "\n check tmpfs Size ..."
cp /etc/fstab{,.bak}
while true;do
if [ `df | awk '/tmpfs/ {print $2}'` -lt 1048576 ];then
echo -e "\n\e[1;33m tmpfs Smaill \e[0m"
sed -i '/tmpfs/s/defaults/defaults,size=1G/' /etc/fstab && mount -o remount /dev/shm
if [ $? != 0 ];then
i=i+1
if [ $i -eq 3 ];then
echo -e "\n\e[1;31m set tmpfs faild. \e[0m"
exit 3
fi
else
echo -e "\n\e[1;36 tmpfs updated successfully. \e[0m"
break
fi
else
echo -e "\n\e[1;36m tmpfs checked PASS \e[0m"
break
fi
done
}
#停止防火墙IPTABLES
service iptables stop
chkconfig iptables off
#关闭SELINUX
cp /etc/selinux/config{,.bak} && sed -i '/SELINUX/s/enforcing/disabled/;/SELINUX/s/permissive/disabled/' /etc/selinux/config
setenforce 0
#执行以上函数
isroot
oscheck
packagecheck
xdesk
kernelset
oralimit
setlogin
setprofile
echo -e "\n\e[1;33m please input oracle's user passwd: \e[0m"
read oraclepw
ouseradd $oraclepw
setbash_profile
echo -e "\n\e[1;33m please input oracle install PATH(default /home/oracle/app) \e[0m"
read oraclepath
if [ -z $oraclepath ];then
oraclepath=/home/oracle/app
fi
echo -e "\n\e[1;33m please input oracle_sid (default orcl) \e[0m"
read orasid
if [ -z orasid ];then
orasid=orcl
fi
setbash_profile $oraclepath $orasid
mkdir -p $oraclepath && chown -R oracle:oinstall $oraclepath && chmod -R 755 $oraclepath && mkdir -p /home/oracle/app/oraInventory && chown -R oracle:oinstall /home/oracle/
unset i
echo -e "\n\e[1;35m Oracle install pre-setting finish! && please run oracle installer as user oracle \e[0m"

1、首先复制上面的文本进行创建脚本文件并授可执行权限,并执行脚本

[root@oracle ~]vim oracleinstall.sh  复制脚本粘贴进来

[root@oracle ~]chmod +x  oracleinstall.sh  &&  ./oracleinstall.sh

2、执行脚本需要输入oracle用户密码,其它的两个可以保持默认

3、然后切换到oracle账户

[root@oracle ~] su - oracel

4、新建一个soft文件夹

[oracle@oracle ~]mkdir soft

切换到目录

我实际上是建在home目下面的

需要在root用户下授于oracle:orinstall的权限

[root@oracle ~]chown -R oracle:oinstall /home/soft

[root@oracle ~]cd /home/soft/

4、上传并解压db_112040_Linux-x86-64_1of7.zip;db_112040_Linux-x86-64_2of7.zip

推荐使用rz上传命令(在初始化脚本时已安装)

解压命令:unzip  db_112040_Linux-x86-64_1of7.zip && unzip db_112040_Linux-x86-64_2of7.zip

二、安装数据库软件

静默安装脚本内容:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/3d4d7f3162da94254882e22747bd8302.html