1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
| #!/bin/bash
################################################################################################
# Install softeare -- Install oracle 11g database software
#
# History: 2016/01/25 zhuwei First release
################################################################################################
# set a safe path before doing anything else
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH
WEBSITE="http://192.168.1.10"
#-----------------------------------------------------------------------------------------------
# This script must be executed as root
RUID=`/usr/bin/id|awk -F\( '{print $1}'|awk -F\= '{print $2}'`
if [ ${RUID} != "0" ];then
$ECHO "This script must be executed as root"
exit 1
fi
#-----------------------------------------------------------------------------------------------
prepareSystem(){
# Set SElinux to disabled mode regardless of its initial value
sed -i -e 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
# stop iptables
/etc/init.d/iptables stop
# *** Chkconfig section
# Turn off unwanted services
chkconfig --level 0123456 iptables off
chkconfig --level 0123456 ip6tables off
}
#-----------------------------------------------------------------------------------------------
# Display an error and exit
errorExit() {
echo "$@" >&2
exit 1
}
#-----------------------------------------------------------------------------------------------
# Display the normal print
displayheader() {
echo -e "\033[32m*******************************************************************\033[0m"
echo -e "\033[32m*\033[0m"$@""
echo -e "\033[32m*******************************************************************\033[0m"
echo ""
}
#-----------------------------------------------------------------------------------------------
#download oracle software
download(){
wget -N -q -P /u $WEBSITE/oracle11g/p10404530_112030_Linux-x86-64_1of7.zip
wget -N -q -P /u $WEBSITE/oracle11g/p10404530_112030_Linux-x86-64_2of7.zip
unzip -q -d /u /u/p10404530_112030_Linux-x86-64_1of7.zip
unzip -q -d /u /u/p10404530_112030_Linux-x86-64_2of7.zip
rm -rf /u/p10404530_112030_Linux-x86-64_1of7.zip
rm -rf /u/p10404530_112030_Linux-x86-64_2of7.zip
chown -R oracle:oinstall /u/database
}
#-----------------------------------------------------------------------------------------------
#Configure the kernel params
Configure1(){
cat >> /etc/sysctl.conf <<EOF
fs.aio-max-nr = 1048576
fs.file-max = 6815744
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 = 1048576
EOF
if [ $? != 0 ]; then
errorExit 'Unable to configure sysctl settings for database'
fi
return 0
}
Configure2(){
cat >> /etc/security/limits.conf <<EOF
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
EOF
if [ $? != 0 ]; then
errorExit 'Unable to configure settings for database'
fi
return 0
}
Configure3(){
cat >> /etc/pam.d/login <<EOF
session required pam_limits.so
EOF
if [ $? != 0 ]; then
errorExit 'Unable to configure settings for database'
fi
return 0
}
#-----------------------------------------------------------------------------------------------
#In the table below for the list of users and user groups
#
# User Name Group Name
# --------- -------
# oracle dba,oinstall
# grid asmdba(If using the asm storage)
#
#Add Users and Groups
addUsers(){
GROUPEXIT1=`grep oinstall /etc/group|awk -F: '{print $1}'`
if [ -z ${GROUPEXIT1} ]; then
/usr/sbin/groupadd oinstall || errorExit 'Unable to add oinstall group'
fi
GROUPEXIT2=`grep dba /etc/group|awk -F: '{print $1}'`
if [ -z ${GROUPEXIT2} ]; then
/usr/sbin/groupadd dba || errorExit 'Unable to add dba group'
fi
USERSEXIT=`grep oracle /etc/shadow | awk -F: '{print $1}'`
if [ -z ${USERSEXIT} ]; then
/usr/sbin/useradd -d /home/oracle -g oinstall -G dba oracle && passwd -l oracle \
|| errorExit 'Unable to add oracle user'
#这里oracle用户是锁定的,不能通过ssh进行登录的,使用su - oracle切换用户之后操作是没有
#问题的,其实这里也可以使用usermod -L oracle && chage -d 0 oracle 让oracle用户第一次登录\
#时要求修改密码。
fi
return 0
}
#-----------------------------------------------------------------------------------------------
#Configure the oracle user's environment
profile(){
cat >> /home/oracle/.bash_profile <<EOF
export TMP=/tmp
export TMPDIR=\$TMP
export ORACLE_SID=test
export ORACLE_BASE=/u/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/db_1
export TNS_ADMIN=\$ORACLE_HOME/network/admin
export ORACLE_TERM=xterm
export PATH=/usr/sbin:\$PATH
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib:\$ORACLE_HOME/jdbc/lib
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
export NLS_LANG="AMERICAN_AMERICA.GB2312"
export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'
umask 022
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 [ $? != 0 ]; then
errorExit 'bash_profile this file does not exist'
fi
return 0
}
#-----------------------------------------------------------------------------------------------
#To establish the oracle software installation directory
directory(){
if [ ! -d "/u/app/oracle" ]; then
mkdir -p /u/app/oracle
fi
chown -R oracle:oinstall /u/app
chmod -R 775 /u/app
}
HOSTNAME=`hostname`
PATH1="/u/database/response"
#-----------------------------------------------------------------------------------------------
#Configure the oracle silent installation files
silent(){
ORACLE_BASE="\/u\/app\/oracle"
ORACLE_HOME=${ORACLE_BASE}"\/product\/11\.2\.0\/db_1"
A1="ORACLE_HOSTNAME\="
A2="INVENTORY_LOCATION\="
A3="ORACLE_HOME\="
A4="ORACLE_BASE\="
B1=${A1}${HOSTNAME}
B2=${A2}${ORACLE_BASE}"\/oraInventory"
B3=${A3}${ORACLE_HOME}
B4=${A4}${ORACLE_BASE}
mv -f $PATH1/db_install.rsp $PATH1/db_install.rsp.bak
wget -N -q -P $PATH1 $WEBSITE/oracle11g/db_install.rsp
sed -i -e "s/${A1}/${B1}/g" -e "s/${A2}/${B2}/g" -e "s/${A3}/${B3}/g" \
-e "s/${A4}/${B4}/g" $PATH1/db_install.rsp || errorExit "The configuration file failed!"
#这里的wget下载下来的db_install.rsp文件有一通用的部分我是处理过的,然后放到Web服务端
#提供下载,修改过的内容如下:
#oracle.install.option=INSTALL_DB_SWONLY
#UNIX_GROUP_NAME=oinstall
#SELECTED_LANGUAGES=en
#oracle.install.db.InstallEdition=EE
#oracle.install.db.DBA_GROUP=dba
#oracle.install.db.OPER_GROUP=dba
#DECLINE_SECURITY_UPDATES=true
}
################################################################################################
# Detect and install oracle rpm package you need
VERSION1=`sed -n '1p' /etc/issue|awk 'BEGIN{OFS=""} {print $1,$2,$7}'`
VERSION2=`sed -n '1p' /etc/issue|awk 'BEGIN{OFS=""} {print $1,$2,$7}'|awk -F. '{print $1}'`
VALUE=`/usr/bin/getconf LONG_BIT`
OSDIGIT=`/bin/uname -m`
P_YUM="/etc/yum.repos.d/"
#-----------------------------------------------------------------------------------------------
# Download yum client configure file
/usr/bin/wget -N -q -P $P_YUM $WEBSITE/rhelrepo/$VERSION2.repo \
|| errorExit 'Failed to download the yum client files,Please manually configure!'
/bin/sed -i 's/RedHat/'$VERSION1\_$OSDIGIT'/g' $P_YUM$VERSION2.repo \
|| errorExit 'Replace the files is not successful,Please manually configure!'
if [ -f $P_YUM$VERSION2.repo ]; then
displayheader "Successfully configured yum client, please continue"
fi
#-----------------------------------------------------------------------------------------------
# RedHat 5 and RedHat 6 install oracle software required RPM package
Red5=(binutils-2* compat-libstdc++-33* elfutils-libelf-0.* elfutils-libelf-devel-0.* \
elfutils-libelf-devel-static-0.* gcc-4.* gcc-c++-4* glibc-2.* glibc-common-2.* glibc-devel-2.* \
glibc-headers-2* kernel-headers-2.* libaio-0.* libaio-devel-0.* libgcc-4.* libgomp-4.* \
libstdc++-4.* libstdc++-devel-* make-* numactl-devel-* sysstat-* pdksh-* ksh-* \
unixODBC-* unixODBC-devel-*)
Red6=(binutils-2* compat-libstdc++-33* elfutils-libelf-0.* elfutils-libelf-devel-0.* \
gcc-4.* gcc-c++-4* glibc-2.* glibc-common-2.* glibc-devel-2.* glibc-headers-2* \
kernel-headers-2.* libaio-0.* libaio-devel-0.* libgcc-4.* libgomp-4.* libstdc++-4.* \
libstdc++-devel-* make-* numactl-devel-* sysstat-* pdksh-* unixODBC-* unixODBC-devel-*)
len5=${#Red5[@]}
len6=${#Red6[@]}
COUNT=0
#-----------------------------------------------------------------------------------------------
# Test your system has been installed the RPM package
displayheader "You have installed the required RPM package is as follows:"
if [ $VERSION2 == "RedHat5" ] ; then
for((i=0;i<len5;i++));
do
CHAR=${Red5[$i]}
rpm -qa | grep "^$CHAR"
if [ $? != 0 ] ; then
UNINSTALL[$COUNT]=${Red5[$i]}
COUNT=$(($COUNT+1))
fi
done
fi
if [ $VERSION2 == "RedHat6" ] ; then
for((i=0;i<len6;i++));
do
CHAR=${Red6[$i]}
rpm -qa | grep "^$CHAR"
if [ $? != 0 ] ; then
UNINSTALL[$COUNT]=${Red6[$i]}
COUNT=$(($COUNT+1))
fi
done
fi
printf '\n'
#-----------------------------------------------------------------------------------------------
# Will not install the RPM packages for installation
if [ $COUNT -gt "0" ];then
displayheader "Do you have "$COUNT" rpm package not installed,not installed patch is:"
len=${#UNINSTALL[@]}
for((j=0;j<len;j++));
do
echo "${UNINSTALL[$j]}"
done
printf '\n'
read -p "Are you sure to install the patch[yes or y]:" SELECT
printf '\n'
if [ $SELECT == "yes" -o $SELECT == "y" ]; then
for((l=0;l<len;l++));
do
VAR=${UNINSTALL[$l]}
if [ $VAR == "pdksh-5.2.14-36.el5.x86_64.rpm" ]; then
rpm -qa ksh-*
if [ $? == 0 ]; then
yum -q -y remove ksh-*
fi
fi
yum -q -y install $VAR
done
fi
else
displayheader "Required RPM packages have been installed"
fi
prepareSystem || errorExit 'Failed to prepare system'
Configure1 && displayheader "The configure1 successful execution" \
|| errorExit 'Failed to system'
Configure2 && displayheader "The configure2 successful execution" \
|| errorExit 'Failed to system'
Configure3 && displayheader "The configure1 successfu3 execution" \
|| errorExit 'Failed to system'
addUsers && displayheader "Building a successful oracle users and groups" \
|| errorExit 'Failed to system'
directory && displayheader "Building a successful directory" \
|| errorExit 'Failed to system'
profile || errorExit 'Failed to system'
displayheader "Is the download file, please wait a few minutes" && download
silent && displayheader "Modify db_install. RSP file successfully" \
|| errorExit 'Failed to system'
displayheader "Is database software installed, please wait"
chmod a+x ${PATH1}/db_install.rsp
chown oracle:oinstall ${PATH1}/db_install.rsp
su - oracle -c "/u/database/./runInstaller -silent -force -responseFile \
${PATH1}/db_install.rsp -ignoreSysPrereqs"
|