Oracle 11g R2 RAC安裝前的系統環境搭建

wang_0720發表於2013-11-06
在安裝Oracle 11g RAC時有很多的前期準備工作要做,在多個節點上做大量繁瑣、重複的工作著實讓人無法忍受。而用指令碼代替手工操作無疑會使工作效率大大提高。本文是一個RAC環境搭建的shell指令碼,在每個節點上對紅色字型稍作更改,就可以用該指令碼做如下工作:安裝所需的軟體包,建立使用者,使用者環境變數的配置以及系統引數的配置等。
#!/bin/bash
#oracle RAC enviroment configure
#./oracinstall.sh
#software setup
software()
{
for software in binutils\              
                compat-libstdc++\
                elfutils-libelf\
                elfutils-libelf-devel\
                elfutils-libelf-devel-static\
                gcc\
                gcc-c++\
                glibc\
                glibc-common\
                glibc-devel\
                glibc-headers\
                kernel-headers\
                ksh\
                libaio\
                libaio-devel\
                libgcc\
                libgomp\
                libstdc++\
                libstdc++-devel\
                make\
                sysstat\
                unixODBC\
                unixODBC-devel;do
        rpm -qa|grep ${software} >/dev/null
        if [ $? -ne 0 ];then
                echo "${software} is not installed"
                rpm -Uvh /cdrom/${software}-*
                if [ $? -eq 0 ];then
                        echo "${software} installed successful"
                fi
        fi
    echo "${software} has been installed"
done
}
#create user and group for grid infrastructure
grid()
{
groupadd -g 1000 oinstall
groupadd -g 1200 asmadmin
groupadd -g 1201 asmdba
groupadd -g 1202 asmoper
useradd -m -u 1100 -g oinstall -G asmadmin,asmdba,asmoper -d /home/grid -s /bin/bash -c "Grid Infrastructure Owner" grid
#grid登入密碼,可以根據實際情況設定
echo "gridpassword" |passwd --stdin grid
cat >>/home/grid/.bash_profile< #ASM例項的sid,每個節點唯一
ORACLE_SID=+ASM1;export ORACLE_SID
JAVA_HOME=/usr/local/java; export JAVA_HOME
ORACLE_BASE=/u01/app/grid; export ORACLE_BASE
ORACLE_HOME=/u01/app/11.2.0/grid; export ORACLE_HOME
ORACLE_PATH=/u01/app/oracle/common/oracle/sql; export ORACLE_PATH
SQLPATH=/u01/app/common/oracle/sql; export SQLPATH
NLS_DATE_FORMAT="DD-MON-YYYY HH24:MI:SS"; export NLS_DATE_FORMAT
TNS_ADMIN=\$ORACLE_HOME/network/admin; export TNS_ADMIN
ORA_NLS11=\$ORACLE_HOME/nls/data; export ORA_NLS11
PATH=.:\${JAVA_HOME}/bin:\${PATH}:\$HOME/bin:\$ORACLE_HOME/bin
PATH=\${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
PATH=\${PATH}:/u01/app/common/oracle/bin
export PATH
LD_LIBRARY_PATH=\$ORACLE_HOME/lib
LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\$ORACLE_HOME/oracm/lib
LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
CLASSPATH=\$ORACLE_HOME/JRE
CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/jlib
CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/rdbms/jlib
CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/network/jlib
export CLASSPATH
export TEMP=/tmp
export TMPDIR=/tmp
umask 022
EOF
source /home/grid/.bash_profile
}

#create user and group for oracle
oracle()
{
groupadd -g 1300 dba
groupadd -g 1301 oper
useradd -m -u 1101 -g oinstall -G dba,oper,asmdba -d /home/oracle -s /bin/bash -c "Oracle Software Owner" oracle
#oracle使用者登入密碼,可以根據實際情況設定
echo "oraclepassword"|passwd --stdin oracle
cat >>/home/oracle/.bash_profile< alias sqlplus="rlwrap sqlplus"
alias rman="rlwrap rman"
alias lsnrctl="rlwrap lsnrctl"
#oracle例項的sid,每個節點唯一
ORACLE_SID=racdb1; export ORACLE_SID
ORACLE_UNQNAME=racdb; export ORACLE_UNQNAME
JAVA_HOME=/usr/local/java; export JAVA_HOME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_PATH=/u01/app/common/oracle/sql; export ORACLE_PATH
SQLPATH=/u01/app/common/oracle/sql; export SQLPATH
NLS_DATE_FORMAT="DD-MON-YYYY HH24:MI:SS"; export NLS_DATE_FORMAT
TNS_ADMIN=\$ORACLE_HOME/network/admin; export TNS_ADMIN
ORA_NLS11=\$ORACLE_HOME/nls/data; export ORA_NLS11
PATH=.:\${JAVA_HOME}/bin:\${PATH}:\$HOME/bin:\$ORACLE_HOME/bin
PATH=\${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
PATH=\${PATH}:/u01/app/common/oracle/bin
export PATH
LD_LIBRARY_PATH=\$ORACLE_HOME/lib
LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\$ORACLE_HOME/oracm/lib
LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
CLASSPATH=\$ORACLE_HOME/JRE
CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/jlib
CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/rdbms/jlib
CLASSPATH=\${CLASSPATH}:\$ORACLE_HOME/network/jlib
export CLASSPATH
export TEMP=/tmp
export TMPDIR=/tmp
umask 022
EOF
source /home/oracle/.bash_profile
}
id nobody>/dev/null 2>&1
if [ $? -ne 0 ];then
useradd nobody
fi
#create home base for grid and oracle
homebase()
{
mkdir -p /u01/app/grid
mkdir -p /u01/app/11.2.0/grid
chown -R grid:oinstall /u01
mkdir -p /u01/app/oracle
chown oracle:oinstall /u01/app/oracle
chmod -R 775 /u01
}
limit()
{
cat >>/etc/security/limits.conf< grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
EOF
cat >>/etc/pam.d/login< session      required      pam_limits.so
EOF
}
profile()
{
cat >> /etc/profile < if [  \$USER = "oracle" ] || [ \$USER = "grid" ]; then
    if [  \$SHELL = "/bin/ksh" ]; then
        ulimit -p 16384
        ulimit -n 65536
    else
        ulimit -u 16384 -n 65536
    fi
    umask 022
fi
EOF
}
sys()
{
cat >/etc/sysctl.conf< net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
#4GB physical memory configure like this
kernel.shmmax = 4294967295
kernel.shmall = 268435456
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 6815744
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
fs.aio-max-nr = 1048576
EOF
}                                  
#==============
case ${1} in
       software)
       software
       ;;
       grid)
       grid
       ;;
       oracle)
       oracle
       ;;
       homebase)
       hoembase
       ;;
       limit)
       limit
       ;;
       profile)
       profile
       ;;
       sys)
       sys
       ;;
       all)
       software
       grid
       oracle
       homebase
       limit
       profile
       sys
       ;;
       *)
       exit 0
       ;;
esac

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

相關文章