001.
#!/bin/bash
002.
# oracle 11g R2 for linux 安裝輔助腳本
003.
# Redkey
004.
# version 1.0
005.
# date 2013.08.26
006.
#定義常量
007.
SYSCTL=/etc/sysctl.conf
008.
LIMITS=/etc/security/limits.conf
009.
PAM=/etc/pam.d/login
010.
PROFILE=/etc/profile
011.
BASH_PROFILE=/home/oracle/.bash_profile
012.
#定義顯示顏色
013.
#顏色定義 資訊(33黃色) 警示(31紅色) 過程(36淺藍)
014.
#判斷執行使用者是否root
015.
isroot()
016.
{
017.
if [ $USER != "root" ];then
018.
echo -e "\n\e[1;31m the user must be root,and now you user is $USER,please su to root. \e[0m"
019.
exit4
020.
else
021.
echo -e "\n\e[1;36m check root ... OK! \e[0m"
022.
fi
023.
}
024.
#掛在光碟到/mnt/cdrom目錄下
025.
mount_cdrom()
026.
{
027.
echo -e "\n\e[1;31m please insert RHEL to CDROM,press any key ...\e[0m"
028.
read -n 1
029.
if [ -d /mnt/cdrom ];then
030.
umount /mnt/cdrom && mount -t auto -o ro /dev/cdrom /mnt/cdrom
031.
else
032.
mkdir -p /mnt/cdrom
033.
umount /mnt/cdrom && mount -t auto -o ro /dev/cdrom /mnt/cdrom
034.
fi
035.
if [ $? -eq 0 ];then
036.
echo -e "\n\e[1;36m CDROM mount on /mnt/cdrom ... OK! \e[0m"
037.
fi
038.
}
039.
#設置yum本地光碟源
040.
yum_repo()
041.
{
042.
rm -rf /etc/yum.repos.d/* && cat <<EOF >> /etc/yum.repos.d/Server.repo
043.
[Server]
044.
name=MyRPM
045.
baseurl=file:///mnt/cdrom/Server
046.
enabled=1
047.
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
048.
EOF
049.
if [ $? -eq 0 ];then
050.
echo -e "\n\e[1;36m /etc/yum.repos.d/Server.repo ... OK! \e[0m"
051.
fi
052.
}
053.
#添加oracle使用者,添加oracle使用者所屬組oinstall及附加組dba
054.
ouseradd()
055.
{
056.
if [[ `grep "oracle" /etc/passwd` != "" ]];then
057.
userdel -r oracle
058.
fi
059.
if [[ `grep "oinstall" /etc/group` = "" ]];then
060.
groupadd oinstall
061.
fi
062.
if [[ `grep "dba" /etc/group` = "" ]];then
063.
groupadd dba
064.
fi
065.
useradd oracle -g oinstall -G dba && echo $1 |passwd oracle --stdin
066.
if [ $? -eq 0 ];then
067.
echo -e "\n\e[1;36m oracle's pass<a href="HTTP://www.it165.net/edu/ebg/" target="_blank" class="keylink">word</a> updated successfully --- OK! \e[0m"
068.
fi
069.
}
070.
#檢查oracle所需套裝軟體並安裝
071.
packagecheck()
072.
{
073.
for package in binutils compat-libcap1 compat-libstdc++ gcc gcc-c++ glibc glibc-devel ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel make sysstat
074.
do
075.
rpm -q $package 2&gt; /dev/null
076.
if [ $? != 0 ];then
077.
yum -y install $package
078.
echo -e "\n\e[1;36m $package is already installed ... OK! \e[0m"
079.
fi
080.
done
081.
}
082.
# 設置內核參數
083.
kernelset()
084.
{
085.
cp $SYSCTL{,.bak} && cat &lt;&lt;EOF &gt;&gt;$SYSCTL
086.
fs.aio-max-nr = 1048576
087.
fs.file-max = 6815744
088.
kernel.shmall = 2097152
089.
kernel.shmmax = 4294967295
090.
kernel.shmmni = 4096
091.
kernel.sem = 250 32000 100 128
092.
net.ipv4.ip_local_port_range = 9000 65500
093.
net.core.rmem_default = 262144
094.
net.core.rmem_max = 4194304
095.
net.core.wmem_default = 262144
096.
net.core.wmem_max = 1048575
097.
EOF
098.
if [ $? -eq 0 ];then
099.
echo -e "\n\e[1;36m kernel parameters updated successfully --- OK! \e[0m"
100.
fi
101.
sysctl -p
102.
}
103.
#設置oracle資源限制
104.
oralimit()
105.
{
106.
cp $LIMITS{,.bak} && cat &lt;&lt;EOF &gt;&gt; $LIMITS
107.
oracle soft nproc 2047
108.
oracle hard nproc 16384
109.
oracle soft nofile 1024
110.
oracle hard nofile 65536
111.
oracle soft stack 10240
112.
EOF
113.
if [ $? -eq 0 ];then
114.
echo -e "\n\e[1;36m $LIMITS updated successfully ... OK! \e[0m"
115.
fi
116.
}
117.
#設置login檔
118.
setlogin()
119.
{
120.
cp $PAM{,.bak} && cat &lt;&lt;EOF &gt;&gt;$PAM
121.
session required pam_limits.so
122.
EOF
123.
if [ $? -eq 0 ];then
124.
echo -e "\n\e[1;36m $PAM updated successfully ... OK! \e[0m"
125.
fi
126.
}
127.
#設置profile檔
128.
setprofile()
129.
{
130.
cp $PROFILE{,.bak} && cat &lt;&lt;EOF &gt;&gt;$PROFILE
131.
if [ $USER = "oracle" ];then
132.
if [ $SHELL = "/bin/ksh" ];then
133.
ulimit -p 16384
134.
ulimit -n 65536
135.
else
136.
ulimit -u 16384 -n 65536
137.
fi
138.
fi
139.
EOF
140.
if [ $? -eq 0 ];then
141.
echo -e "\n\e[1;36m $PROFILE updated successfully ... OK! \e[0m"
142.
fi
143.
}
144.
#設置oracle的profile檔
145.
setbash_profile()
146.
{
147.
cp $BASH_PROFILE{,.bak} && cat &lt;&lt;EOF &gt;&gt; $BASH_PROFILE
148.
umask 022
149.
ORACLE_BASH=$1
150.
ORACLE_HOME=$ORACLE_BASE/oracle
151.
ORACLE_SID=$2
152.
PATH=$ORACLE_HOME/bin/:$PATH
153.
LANG=en_US.UTF-8
154.
export ORACLE_BASE ORACLE_HOME ORACLE_SID
155.
EOF
156.
if [ $? -eq 0 ];then
157.
echo -e "\n\e[1;36m $BASH_PROFILE updated successfully ... OK! \e[0m"
158.
fi
159.
. $BASH_PROFILE
160.
}
161.
#系統內容檢查
162.
oscheck()
163.
{
164.
#查看記憶體大小是否大於1G
165.
echo -e "\n check MEM Size ..."
166.
if [ `cat /proc/meminfo | grep MemTotal | awk '{print $2}'` -lt 1048576 ];then
167.
echo -e "\n\e[1;33m Memory Small \e[0m"
168.
exit 1
169.
else
170.
echo -e "\n\e[1;36m Memory checked PASS \e[0m"
171.
fi
172.
#查看tmp空間大小
173.
echo -e "\n check tmpfs Size ..."
174.
if [ `df | awk '/tmpfs/ {print $2}'` -lt 1048576 ];then

175.
echo -e "\n\e[1;33m tmpfs Smaill \e[0m"
176.
exit 1
177.
else
178.
echo -e "\n\e[1;36m tmpfs checked PASS \e[0m"
179.
fi
180.
}
181.
#停止防火牆IPTABLES
182.
service iptables stop
183.
chkconfig iptables off
184.
#關閉SELINUX
185.
cp /etc/selinux/config{,.bak} && sed -i '/SELINUX/s/enforcing/disabled/;/SELINUX/s/permissive/disabled/' /etc/selinux/config
186.
setenforce 0
187.
#執行以上函數
188.
isroot
189.
oscheck
190.
mount_cdrom
191.
yum_repo
192.
packagecheck
193.
ouseradd $oraclepw
194.
kernelset
195.
oralimit
196.
setlogin
197.
setprofile
198.
setbash_profile
199.
echo -e "\n\e[1;33m please input oracle's user passwd: \e[0m"
200.
read oraclepw
201.
echo -e "\n\e[1;33m please input oracle install PATH(default /oracle/db) \e[0m"
202.
read oraclepath
203.
if [ -z $oraclepath ];then
204.
oraclepath=/oracle/db
205.
fi
206.
echo -e "\n\e[1;33m please input oracle_sid (default fxcx) \e[0m"
207.
read orasid
208.
if [ -z orasid ];then
209.
orasid=fxcx
210.
fi
211.
setbash_profile $oraclepath $orasid
212.
mkdir -p $oraclepath && chown -R oracle:oinstall $oraclepath && chmod -R 755 $oraclepath
213.
echo -e "\n\e[1;35m Oracle install pre-setting finish! && please run oracle installer as user oracle \e[0m"

 

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()