1、首先需要搭建一个Web站点,用于提供yum服务和oracle软体下载,类似软件资料库一样。(也可使用Ftp服务代替Web服务,看自己的选择)
2、Oracle软件安装时,建议不要安装在根目录下,所以此脚本中/u 目录为一个分区,若无/u分区,则相关目录会在根目录下。此脚本还可以结合PXE+KICKSTART无人值守安装实现批量部署。
3、脚本内容如下:
#!/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 "[email protected]" >&2 exit 1 } #----------------------------------------------------------------------------------------------- # Display the normal print displayheader() { echo -e "\033[32m*******************************************************************\033[0m" echo -e "\033[32m*\033[0m"[email protected]"" 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两个脚本。
时间: 2024-10-13 06:34:43