最近工作需要安装oracle 11g R2在阿里云ECS上,因此编写了一个脚本来完成图形化安装界面之前的准备工作,这样节省时间,shell如下:
#!/bin/bash SYSCTL="/etc/sysctl.conf" LIMITS="/etc/security/limits.conf" PAM="/etc/pam.d/login" PROFILE="/etc/profile" BASH_PROFILE="/home/oracle/.bash_profile" oracle_passwd='oracle' SID=orcl lang="AMERICAN_AMERICA.AL32UTF8" #ora_install_dir=/u01 #ora_database_dir=/u02 ORACLE_BASE=$ora_install_dir/app/oracle ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db #初始化检查,OS版本、内存、磁盘情况 check_init() { OS=`cat/etc/redhat-release` MEM=`free-m|grep'Mem'|awk'{print$2}'` cpuS=`grep-i"processor"/proc/cpuinfo|wc-l` echo"系统版本:$OS" echo"内存:${MEM}M" echo"cpu核数:$cpuS" } #检查swap空间是否分配 check_swap() { swap_check="`grep-i'swaptotal'/proc/meminfo|awk'{print$2}'`" if[[$swap_check="0"]];then echo"swapspaceNotset,pleasecreateforswapspace!!!" exit1 fi } #检查是否root用户执行脚本 isroot() { if[$USER!="root"];then echo-e"\n\e[1;31mTheusermustberoot,andyouuseris$USER,pleasesutoroot.\e[0m" exit4 fi } #创建oracle用户 oracle_useradd() { if[[`grep"oracle"/etc/passwd`!=""]];then echo-e"\e[1;31mUseroracleexits,deleteandcreateoracle!\e[0m"&&sleep2 userdel-rforacle fi if[[`grep"oinstall"/etc/group`=""]];then groupaddoinstall fi if[[`grep"dba"/etc/group`=""]];then groupadddba fi useraddoracle-goinstall-Gdba&&echo$oracle_passwd|passwdoracle--stdin if[$?-eq0];then echo-e"\n\e[1;32moracle'spasswordupdatesuccessfully---OK!\e[0m" else echo-e"\n\e[1;31moracle'spasswordsetFailed.---NO!\e[0m" fi } #创建oracle使用的目录 oracle_dirs() { read-p"pleaseinputoracleinstalldirname,default/u01":ora_install_dir read-p"pleaseinputoracledatabasedirname,default/u02":ora_database_dir mkdir-p$ora_install_dir/app/oracle/{oraInventory,product/11.2.0/db} mkdir-p"$ora_database_dir/oradata/oradb" chown-Roracle:oinstall$ora_install_dir chown-Roracle.oinstall$ora_database_dir chmod-R755$ora_install_dir$ora_database_dir if[$?==0];then echo"$ora_install_dircreatesucessfully!" echo"$ora_database_dircreatesucessfully!" else echo"$ora_install_diror$ora_database_dircreateFailed,pleasecheck!" exit2 fi } #配置profile文件 oracle_profile() { if[-f"/etc/profile.bak"];then rm-rf/etc/profile>/dev/null cp/etc/profile.bak/etc/profile cat<<EOF>>$PROFILE if[$USER="oracle"];then if[$SHELL="/bin/ksh"];then ulimit-p16384 ulimit-n65536 else ulimit-u16384-n65536 fi fi EOF else cp/etc/profile/etc/profile.bak cat<<EOF>>$PROFILE if[$USER="oracle"];then if[$SHELL="/bin/ksh"];then ulimit-p16384 ulimit-n65536 else ulimit-u16384-n65536 fi fi EOF fi if[$?-eq0];then echo-e"\n\e[1;32m$PROFILEupdatesuccessfully...OK!\e[0m" fi } #配置.bash_profile() oracle_bash() { if[-f"/home/oracle/.bash_profile.bak"];then rm-rf$BASH_PROFILE>/dev/null cp/home/oracle/.bash_profile.bak$BASH_PROFILE cat<<EOF>>$BASH_PROFILE exportORACLE_BASE=$ORACLE_BASE exportORACLE_HOME=$ORACLE_BASE/product/11.2.0/db exportORACLE_SID=$SID exportORACLE_TERM=xterm exportORACLE_OWNER=oracle exportTNS_ADMIN=$ORACLE_HOME/network/admin exportORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data exportLD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:/lib:/usr/lib:/usr/local/lib exportLIBPATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:/lib:/usr/lib:/usr/local/lib exportPATH=$PATH:/sbin:/usr/bin:/usr/sbin:$JAVA_HOME/bin:$ORACLE_HOME/bin:$ORACLE_HOME/lib:$HOME/bin:$ORACLE_HOME/OPatch:. umask022 exportNLS_LANG=$lang EOF else cp$BASH_PROFILE/home/oracle/.bash_profile.bak cat<<EOF>>$BASH_PROFILE exportORACLE_BASE=$ORACLE_BASE exportORACLE_HOME=$ORACLE_BASE/product/11.2.0/db exportORACLE_SID=$SID exportORACLE_TERM=xterm exportORACLE_OWNER=oracle exportTNS_ADMIN=$ORACLE_HOME/network/admin exportORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data exportLD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:/lib:/usr/lib:/usr/local/lib exportLIBPATH=$ORACLE_HOME/lib:$ORACLE_HOME/network/lib:/lib:/usr/lib:/usr/local/lib exportPATH=$PATH:/sbin:/usr/bin:/usr/sbin:$JAVA_HOME/bin:$ORACLE_HOME/bin:$ORACLE_HOME/lib:$HOME/bin:$ORACLE_HOME/OPatch:. umask022 exportNLS_LANG=$lang EOF fi if[$?-eq0];then echo-e"\n\e[1;32m$BASH_PROFILEupdatesuccessfully...OK!\e[0m" fi } #设置limit资源限制 oracle_limit() { if[-f"/etc/security/limits.conf.bak"];then rm-rf$LIMITS>/dev/null cp/etc/security/limits.conf.bak$LIMITS cat<<EOF>>$LIMITS oraclesoftnproc8192 oraclehardnproc16384 oraclesoftnofile8192 oraclehardnofile65536 EOF else cp$LIMITS/etc/security/limits.conf.bak cat<<EOF>>$LIMITS oraclesoftnproc8192 oraclehardnproc16384 oraclesoftnofile8192 oraclehardnofile65536 EOF fi if[$?-eq0];then echo-e"\n\e[1;32m$LIMITSupdatesucessfully...OK!\e[0m" fi } #设置内核参数 oracle_kernal() { if[-f/etc/sysctl.conf.bak];then rm-rf$SYSCTL>/dev/null cp/etc/sysctl.conf.bak$SYSCTL sed-i's/kernel.msgmnb.*/#kernel.msgmnb=65536/g'$SYSCTL sed-i's/kernel.msgmax.*/#kernel.msgmax=65536/g'$SYSCTL sed-i's/kernel.shmmax.*/#kernel.shmmax=68719476736/g'$SYSCTL sed-i's/kernel.shmall.*/#kernel.shmall=4294967296/g'$SYSCTL cat<<EOF>>$SYSCTL kernel.shmall=2097152 kernel.shmmax=2147483648 kernel.shmmni=40960 kernel.sem=25032000100128 kernel.msgmni=4096 kernel.msgmax=65536 kernel.msgmnb=84000 fs.file-max=6815744 net.ipv4.ip_local_port_range=900065500 fs.file-max=6815744 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 net.ipv4.tcp_wmem=262144262144262144 net.ipv4.tcp_rmem=419430441943044194304 EOF else cp$SYSCTL/etc/sysctl.conf.bak sed-i's/kernel.msgmnb.*/#kernel.msgmnb=65536/g'$SYSCTL sed-i's/kernel.msgmax.*/#kernel.msgmax=65536/g'$SYSCTL sed-i's/kernel.shmmax.*/#kernel.shmmax=68719476736/g'$SYSCTL sed-i's/kernel.shmall.*/#kernel.shmall=4294967296/g'$SYSCTL cat<<EOF>>$SYSCTL kernel.shmall=2097152 kernel.shmmax=2147483648 kernel.shmmni=40960 kernel.sem=25032000100128 kernel.msgmni=4096 kernel.msgmax=65536 kernel.msgmnb=84000 fs.file-max=6815744 net.ipv4.ip_local_port_range=900065500 fs.file-max=6815744 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 net.ipv4.tcp_wmem=262144262144262144 net.ipv4.tcp_rmem=419430441943044194304 EOF fi if[$?-eq0];then echo-e"\n\e[1;32m$SYSCTLupdatesucessfully...OK!\e[0m" fi } #关闭iptablesandselinux iptables_selinux() { serviceiptablesstop&&chkconfigiptablesoff setenforce0&>/dev/null sed-i'/SELINUX/s/enforcing/disabled/;/SELINUX/s/permissive/disabled/'/etc/selinux/config } #下载oracle安装文件 get_oracle() { wgethttp://10.139.96.23:8080/p13390677_112040_Linux-x86-64_1of7.zip-P/home/oracle&&wgethttp://10.139.96.23:8080/p13390677_112040_Linux-x86-64_2of7.zip-P/home/oracle } #oracle安装准备主程序 main() { isroot check_init&&sleep1 oracle_useradd&&sleep1 oracle_dirs&&sleep1 oracle_profile&&sleep1 oracle_bash&&sleep1 oracle_limit&&sleep1 oracle_kernal&&sleep1 iptables_selinux&&sleep1 get_oracle&&sleep1 if[$?-eq0];then echo-e"\n\e[1;32moracle初始化配置已经完成,请确保图形化界面正常工作,执行./database安装程序!\e[0m" fi } main原文链接:https://www.f2er.com/oracle/212969.html