Thursday, April 22, 2010

Automated Installation Script for Oracle

Scenario : In my cuurent project i had to work a lot on Oracle installlation and configuration stuff, so before installing oracle a lot of parameter needed to be changed and all which is a time consuming work, as a lazy admin i wrote this script..If you want to make some changes please do and share too :)

#!/bin/bash
#..................................................................................#
####### Oracle Installation Script ########
###This is the script which will tune the OS and install the required packages ###
####### Created By Pradyumna [Copyleft ;)] #######
####### This Script should run as root User #######
#..................................................................................#

DATE=$(date +"%Y%m%d")
echo "Installing Required packages,Make sure YUM is configured neither install manually "
yum install binutils elfutils elfutils-libelf gcc gcc-c++ glibc glibc-common glibc-devel compat-libstdc++-33 cpp make compat-db sysstat libaio libaio-devel unixODBC unixODBC-devel
echo "Package Installation is done"

#This lines needed to be added to the limits.conf file

echo "Changing limits.conf file"
cp /etc/security/limits.conf /etc/security/limits.conf_$DATE
echo " The backup of the original file is taken"
cat >> /etc/security/limits.conf <oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
EOF
echo "limits.conf file changed successfully"


#Add lines to profile to give maximum limit for Oracle user
echo "Changing /etc/profile file"
echo "Taking the backup of profile"
cp /etc/profile /etc/profile.bak_$DATE
echo " The backup of the file is done"
cat >> /etc/profile <if [ \$USER = "oracle" ]; then
if [ \$SHELL = "bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
EOF
echo "/etc/profile file changed successfully"

#The below lines needed to be added to the /etc/pam.d/login file
echo "Taking the Backup Of login file "
cp /etc/pam.d/login /etc/pam.d/login.bak_$DATE
echo "Backup is done ....................."
echo "Changing /etc/pam.d/login file.."
cat >> /etc/pam.d/login <session required /lib/security/pam_limits.so
session required pam_limits.so
EOF
echo "/etc/pam.d/login file changed successfuly"

#Add some kernel parameters to /etc/sysctl.conf file
echo "Changing kernel parameters"
cp /etc/sysctl.conf /etc/sysctl.conf.backup_$DATE
echo " Sysctl backup is done.........."
cat >> /etc/sysctl.conf <fs.file-max = 6553600
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 262144
EOF
echo "Kernel parameters changed successfully"
#Save all new kernel parameters
/sbin/sysctl -p


#Create new groups and oracle user and add this user to the respective groups

echo "Creating new groups and .oracle user "
groupadd oinstall
groupadd dba
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -g oinstall -G dba -d /home/oracle -s /bin/bash -c .Oracle Software Owner. oracle
useradd -m -p $pass $username
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
fi

#groupadd oinstall
#groupadd dba
#useradd -m -g oinstall -G dba -d /home/oracle -s /bin/bash -c .Oracle Software Owner. oracle
#passwd oracle
echo "Groups and user created successfully"

######### Creating Oracle Directory And Setting Permissions ##########
mkdir -p /u02/app/oracle
chown -R oracle:oinstall /u02/app
chmod -R 775 /u02/app
echo "Directories and the permission are set"

#Adding Environment Variables
cp /home/oracle/.bashrc /home/oracle/.bashrc_backup_$DATE
echo " The File Backup is done "
cat >> /home/oracle/.bashrc <TMPDIR=$TMP; export TMPDIR
ORACLE_HOSTNAME=localhost.localdomain; export ORACLE_HOSTNAME
ORACLE_BASE=/u02/app/oracle; export ORACLE_BASE
ORACLE_HOME=/u02/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_SID=PHNXTEST; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
DISPLAY=localhost:0.0; export DISPLAY
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
export LD_LIBRARY_PATH=/u02/app/oracle/product/11.2.0/dbhome_1/lib32
EOF

#Unzip setup of Oracle
#Place the ZIP file in the /home directory of Oracle
su - oracle
echo "Unzipping setup of Oracle 10g Release 2.. ."
echo "Keep the ZIP files/installers in the /home/oracle directory"
unzip linux.x64_11gR2_database_1of2.zip
echo "Setup file successfully unzipped"

#Enter to installation directory and run the installation .

echo "Installation begins"
cd /home/oracle/11gR1_db/database
chmod 755 runInstaller
sh runInstaller

No comments:

Post a Comment