init sys

yhj20041128001發表於2012-04-13
#!/bin/bash
002#
003# Script. Name: oracle_install.sh
004# Description: This program is used for helping you install oracle10g automatically.Be used in Redhat 5 enterprise.
005#
006# Statment: Before installing oracle10g by this program,you should prepare oracle10g tar.gz file, rlwrap and redhat install CD path.If you have any question about this program,you could contact me by the following email address.
007#
008# Author: Xinggang Wang - OpsEye.com
009# Create Date: 2009/11/21
010# Last Modified: 2009/11/24
011 
012# Set trap,so you can interrupt the program when it is running.
013trap 'echo;exit 0;' 2
014 
015# Set the argument "shmmax" according to the memory size of your computer.
016shmmax=$(($(free |awk 'NR==2{print $2}')*1024/2))
017 
018read -p "Please input the oracle username that you want to create:" ooname
019read -p "Please verify the oracle username:" oname
020 
021# Make judgment about if the variable $oname you given is null.
022until [ ! -z "$oname" ]
023do
024 read -p "Please verify the oracle username:" oname
025done
026 
027username=$(awk -F: '{print $1}' /etc/passwd)
028# Judge about if $oname already exists in your system.
029for i in $username
030do
031 if [ $oname = $i ]
032 then
033 echo "Error!The username you input is already exists in your system."; exit 1
034 fi
035done
036 
037# Make sure that the input is the very one which you want.
038until [ ${oname}x = ${ooname}x ]
039do
040 read -p "Please input the oracle username that you want to create:" ooname
041 read -p "Please verify the oracle username:" oname
042 
043 # If $oname is still null,then exit this program.
044 if [ -z "$oname" ]
045 then
046 echo "Error!"
047 exit 1
048 fi
049done
050 
051read -p "Please input rlwrap path:" rlpath
052 
053read -p "Please input the path of CD:" cdpath
054 
055# Make sure the path that you given is right.
056until [ -e "$cdpath"/Server ]
057do
058 read -p "Wrong path of CD,please retry:" cdpath
059done
060 
061read -p "Please input your oracle tar.gz package name(include path) :" opackage
062 
063if [ ! -f "$opackage" ]
064then
065 echo "The package is wrong!"
066 exit 1
067fi
068 
069{
070groupadd oinstall
071groupadd dba
072useradd -m -g oinstall -G dba $oname
073mkdir -p /u01/app/$oname
074chown -R $oname:oinstall /u01/app/$oname
075chmod -R 775 /u01/app/$oname
076}&>/dev/null
077 
078tar -zxf $opackage -C /home/$oname &>/dev/null
079 
080# Make sure that the package you given is absolutely right.
081until [ "$?" -eq "0" ]
082do
083 read -p "Wrong package,please retry:" opachage
084 tar -zxf $opackage -C /home/$oname &>/dev/null
085done
086 
087pushd $cdpath/Server &>/dev/null
088{
089rpm -Uvh compat-db-4*
090rpm -Uvh libaio-0*
091rpm -Uvh compat-libstdc++-33-3*
092rpm -Uvh compat-gcc-34-3*
093rpm -Uvh compat-gcc-34-c++-3*
094rpm -Uvh libXp-1*
095rpm -Uvh openmotif-2*
096rpm -Uvh gcc-4*
097}&>/dev/null
098#rpm -Uvh glibc-2.5-12.i686.rpm
099popd &>/dev/null
100 
101flag=0
102{
103pushd $rlpath
104$rlpath/configure
105make && make install
106popd
107}&>/dev/null
108 
109# Be used for judging if rlwrap was compiled successfully.
110if [ "$?" -eq "1" ]
111then
112 flag=1
113fi
114 
115grep 'fs.file-max' /etc/sysctl.conf &>/dev/null
116 
117# Make jugdement if the configure file was already configured.
118if [ "$?" -eq "1" ]
119then
120 
121 # Delete the argument "kernerl.shmmax" in the configure file.
122 sed -i '/^kernel.shmmax/d' /etc/sysctl.conf
123 # Delete the argument "kernel.shmall" in the configure file
124 sed -i '/^kernel.shmall/d' /etc/sysctl.conf
125 
126 cat >> /etc/sysctl.conf <
127kernel.shmall = 2097152
128kernel.shmmax = $shmmax
129kernel.shmmni = 4096
130kernel.sem = 250 32000 100 128
131fs.file-max = 65536
132net.ipv4.ip_local_port_range = 1024 65000
133net.core.rmem_default=262144
134net.core.rmem_max=262144
135net.core.wmem_default=262144
136net.core.wmem_max=262144
137#signaturelevin
138EOF
139fi
140 
141# Make the configured file come into effect immediately.
142sysctl -p &>/dev/null
143 
144grep 'soft nproc' /etc/security/limits.conf &>/dev/null
145if [ "$?" -eq "1" ]
146then
147 cat >> /etc/security/limits.conf <
148soft nproc 2047
149hard nproc 16384
150soft nofile 1024
151hard nofile 65536
152#signaturelevin
153EOF
154fi
155 
156grep 'pam_limits.so' /etc/pam.d/login &>/dev/null
157if [ "$?" -eq "1" ]
158then
159 cat >> /etc/pam.d/login <
160session required pam_limits.so
161#signaturelevin
162EOF
163fi
164 
165grep 'ORACLE_SID=orcl' /home/$oname/.bash_profile &>/dev/null
166if [ "$?" -eq "1" ]
167then
168 cat >>/home/$oname/.bash_profile <
169export TMP=/tmp
170export ORACLE_BASE=/u01/app/$oname
171export ORACLE_HOME=\$ORACLE_BASE/product/10g
172export ORACLE_SID=orcl
173export PATH=\$ORACLE_HOME/bin:\$PATH
174export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
175export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
176alias sqlplus="rlwrap sqlplus"
177alias rman="rlwrap rman"
178alias fox="firefox"
179#signaturelevin
180EOF
181fi
182 
183. /home/$oname/.bash_profile
184 
185# Resovling the problems brought by the version of your system.
186sed -i 's/5/4/' /etc/redhat-release
187 
188xhost + &>/dev/null
189 
190echo -e "\a"
191if [ "$flag" -eq "1" ]
192then
193 echo -e "Configure successful but the rlwrap was not compiled successfully.You should compile it by your own after finishing installs of oracle10g.Now,the following steps are your own work.\n \n 1.export LANG=C \n 2.cd database/\n 3../runInstaller\n 4.Configure according to the Oracle GUI information.\n"
194else
195 echo -e "Configure successful!The following steps are your own work.Just do it.\n \n 1.export LANG=C \n 2.cd database/\n 3../runInstaller\n 4.Configure according to the Oracle GUI information.\n"
196fi
197 
198su - $oname
199 
200exit 0

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23757700/viewspace-721078/,如需轉載,請註明出處,否則將追究法律責任。