Oracle shell安装,Oracle 11g R2 for Linux 自动安装配置---完整shell脚本

这两天一同事让帮忙搭建一个oracle环境,为了省事就写了一个oracle的安装脚本。该脚本在RHEL 6.X x64环境下安装oracle 11g R2 x64测试通过,参数设置参照oracle的oracle 11G for Linux安装向导.pdf设置。

注:如果安装Oracle_Linux,需要修改脚本中yum源的配置的公钥。

#!/bin/bash

# oracle 11g R2 for linux 安装辅助脚本

# Redkey

# version 1.2

# date 2013.08.27

#定义常量

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

}

#挂在光盘到/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 <> /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()

{

LANG=C yum -y groupinstall "X Window System" "Desktop"

if [ $? -eq 0 ];then

echo -e "\n\e[1;36m $package is already installed ... OK! \e[0m"

fi

}

# 设置内核参数

kernelset()

{

cp $SYSCTL{,.bak} && cat <>$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 <> $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 <>$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 <>$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 <> $BASH_PROFILE

umask 022

ORACLE_BASE=$1

ORACLE_HOME=$ORACLE_BASE/oracle

ORACLE_SID=$2

PATH=$ORACLE_HOME/bin/:$PATH

LANG=en_US.UTF-8

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

yum_repo

mount_cdrom

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 /oracle/db) \e[0m"

read oraclepath

if [ -z $oraclepath ];then

oraclepath=/oracle/db

fi

echo -e "\n\e[1;33m please input oracle_sid (default fxcx) \e[0m"

read orasid

if [ -z orasid ];then

orasid=fxcx

fi

setbash_profile $oraclepath $orasid

mkdir -p $oraclepath && chown -R oracle:oinstall $oraclepath && chmod -R 755 $oraclepath

unset i

echo -e "\n\e[1;35m Oracle install pre-setting finish! && please run oracle installer as user oracle \e[0m"

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值