备注:
机器配置不限,本脚本只是帮助把软件安装好及配置好监听和库,保证能用的前提,具体参数需要自行根据实际情况进行调整。
安装时必须提前配置好yum环境,如需查看如何配置yum请看:http://www.cnblogs.com/zhushenke/articles/8966262.html
机器的系统必须为6.x或者7.x版本
如需博主提供的安装包,请移步:链接:https://pan我是点baidu.com/s/1vhzzs42v3MHC2XF3xzgjew 密码:kxqv
####################Steup 1 Install oracle software
1 #!/bin/bash
2 export PATH=$PATH 3
4 ###set firewalld&selinux 5 os=`cat /etc/redhat-release|awk '{print $4}'|awk -F'.' '{print $1}'` 6 if [ ${os} == "7" ];then
7 systemctl disable firewalld && systemctl stop firewalld 8 systemctl disable abrt-ccpp 9 systemctl disable abrtd 10 systemctl disable atd 11 systemctl disable auditd 12 systemctl disable cpuspeed 13 systemctl disable cups 14 systemctl disable dnsmasq 15 systemctl disable firstboot 16 systemctl disable lvm2-monitor 17 systemctl disable netconsole 18 systemctl disable netfs 19 systemctl disable ntpd 20 systemctl disable ntpdate 21 systemctl disable portreserve 22 systemctl disable postfix 23 systemctl disable rdisc 24 systemctl disable restorecond 25 systemctl disable saslauthd 26 systemctl disable wdaemon 27 systemctl disable wpa_supplicant 28 systemctl disable NetworkManager 29 systemctl disable blk-availability 30 systemctl disable cpuspeed 31 systemctl disable lvm2-monitor 32 systemctl disable restorecond 33 systemctl disable netconsole 34 if [ `getenforce` == "Enforcing" ];then
35 setenforce 0
36 sed -i "s!SELINUX=enforcing!SELINUX=disabled!g" /etc/selinux/config 37 elif [ `getenforce` == "Permissive" ];then
38 sed -i "s!SELINUX=enforcing!SELINUX=disabled!g" /etc/selinux/config 39 else
40 continue 41 fi
42 else
43 chkconfig iptables off && chkconfig ip6tables off && service iptables stop && service ip6tables stop 44 chkconfig abrt-ccpp off 45 chkconfig abrtd off 46 chkconfig atd off 47 chkconfig auditd off 48 chkconfig cpuspeed off 49 chkconfig cups off 50 chkconfig dnsmasq off 51 chkconfig firstboot off 52 chkconfig lvm2-monitor off 53 chkconfig netconsole off 54 chkconfig netfs off 55 chkconfig ntpd off 56 chkconfig ntpdate off 57 chkconfig portreserve off 58 chkconfig postfix off 59 chkconfig rdisc off 60 chkconfig restorecond off 61 chkconfig saslauthd off 62 chkconfig wdaemon off 63 chkconfig wpa_supplicant off 64 chkconfig NetworkManager off 65 chkconfig blk-availability off 66 chkconfig cpuspeed off 67 chkconfig lvm2-monitor off 68 chkconfig restorecond off 69 chkconfig netconsole off 70 if [ `getenforce` == "Enforcing" ];then
71 setenforce 0
72 sed -i "s!SELINUX=enforcing!SELINUX=disabled!g" /etc/selinux/config 73 elif [ `getenforce` == "Permissive" ];then
74 sed -i "s!SELINUX=enforcing!SELINUX=disabled!g" /etc/selinux/config 75 else
76 continue 77 fi
78 fi
79
80 ###set the ip in hosts 81 hostname=`hostname` 82 ip=`ip a|grep 'inet '|grep -v '127.0.0.1'|awk '{print $2}'|awk -F '/' '{print $1}'` 83 for i in ${ip} 84 do
85 a=`grep "${i}" /etc/hosts` 86 if [ ! -n "${a}" ];then
87 echo "${i} ${hostname}" >> /etc/hosts 88 else
89 break 90 fi
91 done
92
93 ###create group&user 94 ora_user=oracle 95 ora_group=('oinstall' 'dba' 'oper') 96 for i in ${ora_group[@]} 97 do
98 a=`grep '${i}' /etc/group` 99 if [ ! -n ${a} ];then
100 groupdel ${i} && groupadd ${i} 101 else
102 groupadd ${i} 103 fi
104 done
105 a=`grep 'oracle' /etc/passwd` 106 if [ ! -n ${a} ];then
107 userdel -r ${ora_user} && useradd -u 501 -g ${ora_group[0]} -G ${ora_group[1]},${ora_group[2]} ${ora_user} 108 else
109 useradd -u 501 -g ${ora_group[0]} -G ${ora_group[1]},${ora_group[2]} ${ora_user} 110 fi
111 echo "wincenter" | passwd --stdin ${ora_user} 112 ###create directory and grant priv 113 count=0
114 while [ $count -lt 3 ] 115 do
116 read -p "Please input the ORACLE_SID(e.g:orcl):" S1 117 read -p "Please input the ORACLE_SID again(e.g:orcl):" S2 118 if [ "${S1}" == "${S2}" ];then
119 export ORACLE_SID=${S1} 120 break 121 else
122 echo "You input ORACLE_SID not same."
123 count=$[${count}+1] 124 fi
125 done
126 count=0
127 while [ $count -lt 3 ] 128 do
129 read -p "Please input the ORACLE_BASE(e.g:/oracle/app):" S1 130 read -p "Please input the ORACLE_BASE again(e.g:/oracle/app):" S2 131 if [ "${S1}" == "${S2}" ];then
132 export ORACLE_BASE=${S1} 133 break 134 else
135 echo "You input ORACLE_BASE not same."
136 count=$[${count}+1] 137 fi
138 done
139 count=0
140 while [ $count -lt 3 ] 141 do
142 read -p "Please input the ORACLE_HOME(e.g:/oracle/app/db):" S1 143 read -p "Please input the ORACLE_HOME again(e.g:/oracle/app/db):" S2 144 if [ "${S1}" == "${S2}" ];then
145 export ORACLE_HOME=${S1} 146 break 147 else
148 echo "You input ORACLE_HOME not same."
149 count=$[${count}+1] 150 fi
151 done
152 if [ ! -d ${ORACLE_HOME} ];then
153 mkdir -p ${ORACLE_HOME} 154 else
155 continue 156 fi
157 if [ ! -d ${ORACLE_BASE}/data ];then
158 mkdir -p ${ORACLE_BASE}/data 159 else
160 continue 161 fi
162 if [ ! -d ${ORACLE_BASE}/recovery ];then
163 mkdir -p ${ORACLE_BASE}/recovery 164 else
165 continue 166 fi
167 ora_dir=`echo ${ORACLE_HOME}|awk -F '/' '{print $2}'` 168 last_dir=`echo ${ORACLE_HOME}|awk -F '/' '{print $NF}'` 169
170 ###install require packages 171 yum -y install elfutils-libelf-devel binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel zip unzip tree 172
173 ###set the sysctl,limits and profile 174 a=`grep 'fs.aio-max-nr' /etc/sysctl.conf` 175 if [ ! -n "${a}" ];then
176 cat << EOF >> /etc/sysctl.conf 177 fs.aio-max-nr = 1048576
178 fs.file-max = 6815744
179 kernel.shmall = 2097152
180 kernel.shmmax = 4294967295
181 kernel.shmmni = 4096
182 kernel.sem = 250 32000 100 128
183 net.ipv4.ip_local_port_range = 9000 65500
184 net.core.rmem_default = 262144
185 net.core.rmem_max = 4194304
186 net.core.wmem_default = 262144
187 net.core.wmem_max = 1048576
188 EOF 189 else
190 continue 191 fi
192 a=`grep 'oracle' /etc/security/limits.conf` 193 if [ ! -n "${a}" ];then
194 cat << EOF >> /etc/security/limits.conf 195 oracle soft nproc 2047
196 oracle hard nproc 16384
197 oracle soft nofile 1024
198 oracle hard nofile 65536
199 oracle soft stack 10240
200 EOF 201 else
202 continue 203 fi
204 a=`grep 'ORACLE_SID' /home/${ora_user}/.bash_profile` 205 if [ ! -n "${a}" ];then
206 cat << EOF >> /home/${ora_user}/.bash_profile 207 export ORACLE_SID=${ORACLE_SID} 208 export ORACLE_BASE=${ORACLE_BASE} 209 export ORACLE_HOME=\$ORACLE_BASE/${last_dir} 210 export PATH=\$PATH:\$ORACLE_HOME/bin 211 EOF 212 else
213 continue 214 fi
215 a=`grep 'oracle' /etc/profile` 216 if [ ! -n "${a}" ];then
217 cat << EOF >> /etc/profile 218 if [ \$USER = "oracle" ];then
219 if [ \$SHELL = "/bin/ksh" ];then
220 ulimit -p 16384
221 ulimit -n 65536
222 else
223 ulimit -u 16384 -n 65536
224 fi
225 else
226 continue 227 fi
228 EOF 229 else
230 continue 231 fi
232 a=`grep 'pam_limits.so' /etc/pam.d/login` 233 if [ ! -n "${a}" ];then
234 cat << EOF >> /etc/pam.d/login
235 session required /lib/security/pam_limits.so 236 session required pam_limits.so 237 EOF 238 else
239 continue 240 fi
241 sysctl -p && source /home/${ora_user}/.bash_profile 242
243 ###unzip the install package and set response file
244 count=0
245 while [ $count -lt 3 ] 246 do
247 read -p "Please input the zip file location(e.g:/oracle/db.zip):" zfile 248 if [ ! -f ${zfile} ];then
249 echo "You input location not found zip file."
250 count=$[${count}+1] 251 else
252 export zfile=${zfile} 253 break 254 fi
255 done
256 unzip ${zfile} -d /${ora_dir} && chown -R ${ora_user}:${ora_group[0]} /${ora_dir} && chmod -R 775 /${ora_dir} 257
258 free_m=`free -m | grep 'Mem:'|awk '{print $2}'` 259 db_response_file=`find / -type f -name db_install.rsp` 260 data_dir=${ORACLE_BASE}/data 261 recovery_dir=${ORACLE_BASE}/recovery 262 cd `find / -type f -name db_install.rsp | sed -n 's:/[^/]*$::p'` && cd ../
263 install_dir=`pwd` 264 sed -i "s!oracle.install.option=!oracle.install.option=INSTALL_DB_SWONLY!g" ${db_response_file} 265 sed -i "s!ORACLE_HOSTNAME=!ORACLE_HOSTNAME=${hostname}!g" ${db_response_file} 266 sed -i "s!UNIX_GROUP_NAME=!UNIX_GROUP_NAME=${ora_group[0]}!g" ${db_response_file} 267 sed -i "s!INVENTORY_LOCATION=!INVENTORY_LOCATION=${ORACLE_BASE}/oraInventory!g" ${db_response_file} 268 sed -i "s!SELECTED_LANGUAGES=en!SELECTED_LANGUAGES=en,zh_CN!g" ${db_response_file} 269 sed -i "s!ORACLE_HOME=!ORACLE_HOME=${ORACLE_HOME}!g" ${db_response_file} 270 sed -i "s!ORACLE_BASE=!ORACLE_BASE=${ORACLE_BASE}!g" ${db_response_file} 271 sed -i "s!oracle.install.db.InstallEdition=!oracle.install.db.InstallEdition=EE!g" ${db_response_file} 272 sed -i "s!oracle.install.db.DBA_GROUP=!oracle.install.db.DBA_GROUP=${ora_group[1]}!g" ${db_response_file} 273 sed -i "s!oracle.install.db.OPER_GROUP=!oracle.install.db.OPER_GROUP=${ora_group[2]}!g" ${db_response_file} 274 sed -i "s!oracle.install.db.config.starterdb.type=!oracle.install.db.config.starterdb.type=GENERAL_PURPOSE!g" ${db_response_file} 275 sed -i "s!oracle.install.db.config.starterdb.globalDBName=!oracle.install.db.config.starterdb.globalDBName=${ORACLE_SID}!g" ${db_response_file} 276 sed -i "s!oracle.install.db.config.starterdb.SID=!oracle.install.db.config.starterdb.SID=${ORACLE_SID}!g" ${db_response_file} 277 sed -i "s!oracle.install.db.config.starterdb.characterSet=AL32UTF8!oracle.install.db.config.starterdb.characterSet=ZHS16GBK!g" ${db_response_file} 278 sed -i "s!oracle.install.db.config.starterdb.memoryLimit=!oracle.install.db.config.starterdb.memoryLimit=$[free_m*8/10]!g" ${db_response_file} 279 sed -i "s!oracle.install.db.config.starterdb.password.ALL=!oracle.install.db.config.starterdb.password.ALL=wincenter!g" ${db_response_file} 280 sed -i "s!oracle.install.db.config.starterdb.storageType=!oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE!g" ${db_response_file} 281 sed -i "s!oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=!oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=${data_dir}!g" ${db_response_file} 282 sed -i "s!oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=!oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=${recovery_dir}!g" ${db_response_file} 283 sed -i "s!oracle.installer.autoupdates.option=!oracle.installer.autoupdates.option=SKIP_UPDATES!g" ${db_response_file} 284 sed -i "s!SECURITY_UPDATES=!SECURITY_UPDATES=true!g" ${db_response_file} 285 su - oracle -c "${install_dir}/runInstaller -silent -ignoreDiskWarning -ignoreSysPrereqs -ignorePrereq -responseFile ${db_response_file}"
####################Steup 2 Confiture oracle listener&dbca
1 #!/bin/bash
2 export PATH=$PATH
3
4 PASSWORD="wincenter"
5 ORACLE_SID=`su - oracle -c 'source ~/.bash_profile && echo $ORACLE_SID'`
6 ORACLE_BASE=`su - oracle -c 'source ~/.bash_profile && echo $ORACLE_BASE'`
7 ORACLE_HOME=`su - oracle -c 'source ~/.bash_profile && echo $ORACLE_HOME'`
8
9 temp=`ls ${ORACLE_BASE}|grep 'data'`
10 if [ ! -n ${temp} ];then
11 mkdir ${ORACLE_BASE}/data
12 export DATAFILE=${ORACLE_BASE}/data
13 else
14 export DATAFILE=${ORACLE_BASE}/data
15 fi
16 temp=`ls ${ORACLE_BASE}|grep 'area'`
17 if [ ! -n ${temp} ];then
18 mkdir ${ORACLE_BASE}/flash_recovery_area
19 export RECOVERY=${ORACLE_BASE}/flash_recovery_area
20 else
21 export RECOVERY=${ORACLE_BASE}/flash_recovery_area
22 fi
23 NETCA=`find / -type f -name netca.rsp`
24 sed -i "s!INSTALL_TYPE=""typical""!INSTALL_TYPE=""custom""!g" ${NETCA}
25 MEM=`free -m|grep 'Mem:'|awk '{print $2}'`
26 TOTAL=$[MEM*8/10]
27
28 ###set listener&tnsnames
29 su - oracle << EOF
30 source ~/.bash_profile
31 ${ORACLE_HOME}/bin/netca -silent -responsefile ${NETCA}
32 dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname ${ORACLE_SID} -sid ${ORACLE_SID} -sysPassword ${PASSWORD} -systemPassword ${PASSWORD} -responseFile NO_VALUE -datafileDestination ${DATAFILE} -redoLogFileSize 1000 -recoveryAreaDestination ${RECOVERY} -storageType FS -characterSet ZHS16GBK -nationalCharacterSet AL16UTF16 -sampleSchema false -memoryPercentage 80 -totalMemory $TOTAL -databaseType OLTP -emConfiguration NONE
33 EOF