设为首页 收藏本站
查看: 1420|回复: 0

使用Shell脚本实现自动化静默安装Oracle软件

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-5-3 09:42:56 | 显示全部楼层 |阅读模式
1、首先需要搭建一个Web站点,用于提供yum服务和oracle软体下载,类似软件资料库一样。(也可使用Ftp服务代替Web服务,看自己的选择)
2、Oracle软件安装时,建议不要安装在根目录下,所以此脚本中/u 目录为一个分区,若无/u分区,则相关目录会在根目录下。此脚本还可以结合PXE+KICKSTART无人值守安装实现批量部署。
3、脚本内容如下:
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"




执行以上脚本后还需要执行$ORACLE_BASE/oraInventory/orainstRoot.sh和$ORACLE_HOME/root.sh两个脚本。




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-212008-1-1.html 上篇帖子: Powershell集成OPENSSL客户端 下篇帖子: shell结合expect的非交互式脚本 Oracle 软件
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表