1. 程式人生 > >ORACLE環境安裝腳本

ORACLE環境安裝腳本

|| libc ssp ksh sysctl 修改環境變量 tmp 輸入 pan

分享一個自己寫shell腳本,寫得有點粗糙,還有很多要改進的地方,以後會繼續學習,寫出更好的腳本。

  1 #!/usr/bin/bash
  2 
  3 . /etc/init.d/functions
  4 
  5 #安裝依賴包
  6 function yumPackge
  7 {
  8     echo "######################安裝依賴包########################"
  9     yum install -y binutils* >/dev/null 2>&1 && action "安裝binutils*
" /bin/true || action "安裝binutils*" /bin/false 10 yum install -y compat-libstdc* >/dev/null 2>&1 && action "安裝compat-libstdc*" /bin/true || action "安裝compat-libstdc*" /bin/false 11 yum install -y elfutils-libelf* >/dev/null 2>&1 && action "安裝elfutils-libelf*" /bin/true
|| action "安裝elfutils-libelf*" /bin/false 12 yum install -y gcc* >/dev/null 2>&1 && action "安裝gcc*" /bin/true || action "安裝gcc*" /bin/false 13 yum install -y glibc* >/dev/null 2>&1 && action "安裝glibc*" /bin/true || action "安裝glibc*" /bin/false 14 yum install -y ksh* >/dev/null
2>&1 && action "安裝ksh*" /bin/true || action "安裝ksh*" /bin/false 15 yum install -y libaio* >/dev/null 2>&1 && action "安裝libaio*" /bin/true || action "安裝libaio*" /bin/false 16 yum install -y libaio.so.1 >/dev/null 2>&1 && action "安裝libaio.so.1" /bin/true || action "安裝libaio.so.1" /bin/false 17 yum install -y libgcc* >/dev/null 2>&1 && action "安裝libgcc*" /bin/true || action "安裝libgcc*" /bin/false 18 yum install -y libstdc* >/dev/null 2>&1 && action "安裝libstdc*" /bin/true || action "安裝libstdc*" /bin/false 19 yum install -y make* >/dev/null 2>&1 && action "安裝make*" /bin/true || action "安裝make*" /bin/false 20 yum install -y sysstat* >/dev/null 2>&1 && action "安裝sysstat*" /bin/true || action "安裝sysstat*" /bin/false 21 yum install -y libXp* >/dev/null 2>&1 && action "安裝libXp*" /bin/true || action "安裝libXp*" /bin/false 22 yum install -y glibc-kernheaders >/dev/null 2>&1 && action "安裝glibc-kernheaders" /bin/true || action "安裝glibc-kernheaders" /bin/false 23 echo "#########################結束###########################" 24 } 25 26 #修改內核 27 function modifyKennel 28 { 29 echo " 30 fs.aio-max-nr = 1048576 31 fs.file-max = 6815744 32 kernel.shmall = 2097152 33 kernel.shmmax = 4294967295 34 kernel.shmmni = 4096 35 kernel.sem = 250 32000 100 128 36 net.ipv4.ip_local_port_range = 9000 65500 37 net.core.rmem_default = 262144 38 net.core.rmem_max = 4194304 39 net.core.wmem_default = 262144 40 net.core.wmem_max = 1048576 41 " >> /etc/sysctl.conf 42 if [ "$?" -eq 0 ];then 43 sysctl -p >/dev/null 2>&1 44 action "修改內核參數" /bin/true 45 else 46 action "修改內核參數" /bin/false 47 fi 48 } 49 50 #修改資源限制 51 function modifyLimit 52 { 53 echo " 54 oracle soft nproc 2047 55 oracle hard nproc 16384 56 oracle soft nofile 1024 57 oracle hard nofile 65536 58 oracle soft stack 10240 59 grid soft nproc 16384 60 grid hard nproc 16384 61 grid soft nofile 65536 62 grid hard nofile 65536 63 grid soft stack 10240 64 grid hard stack 10240 65 " >> /etc/security/limits.conf 66 if [ "$?" -eq 0 ];then 67 action "修改資源限制" /bin/true 68 else 69 action "修改資源限制" /bin/false 70 fi 71 } 72 73 function modifyProfile 74 { 75 echo " 76 session required /lib/security/pam_limits.so 77 session required pam_limits.so 78 " >> /etc/pam.d/login && action "修改login" /bin/true || action "修改login" /bin/false 79 echo " 80 if [ $USER = "oracle" ]; then 81 if [ $SHELL = "/bin/ksh" ]; then 82 ulimit -p 16384 83 ulimit -n 65536 84 else 85 ulimit -u 16384 -n 65536 86 fi 87 fi 88 " >> /etc/profile 89 if [ "$?" -eq 0 ];then 90 source /etc/profile 91 action "修改profile" /bin/true 92 else 93 action "修改profile" /bin/false 94 fi 95 } 96 97 #創建oracle、grid組 98 function createGroup 99 { 100 [ `cat /etc/group|grep dba|wc -l` -gt 0 ] && groupdel dba 101 [ `cat /etc/group|grep oinstall|wc -l` -gt 0 ] && groupdel oinstall 102 [ `cat /etc/group|grep oper|wc -l` -gt 0 ] && groupdel oper 103 [ `cat /etc/group|grep asmadmin|wc -l` -gt 0 ] && groupdel asmadmin 104 [ `cat /etc/group|grep asmdba|wc -l` -gt 0 ] && groupdel asmdba 105 [ `cat /etc/group|grep asmoper|wc -l` -gt 0 ] && groupdel asmoper 106 read -p "依次輸入dba,oinstall,oper,asmadmin,asmdba,asmoper組號:" dbagid oinstallgid opergid asmadmingid asmdbagid asmopergid 107 groupadd -g $dbagid dba 108 groupadd -g $oinstallgid oinstall 109 groupadd -g $opergid oper 110 groupadd -g $asmadmingid asmadmin 111 groupadd -g $asmdbagid asmdba 112 groupadd -g $asmopergid asmoper 113 [ `cat /etc/group|grep dba|wc -l` -gt 0 ] && action "dba組創建成功" /bin/true || action "dba組創建失敗" /bin/false 114 [ `cat /etc/group|grep oinstall|wc -l` -gt 0 ] && action "oinstall組創建成功" /bin/true || action "oinstall組創建失敗" /bin/false 115 [ `cat /etc/group|grep oper|wc -l` -gt 0 ] && action "oper組創建成功" /bin/true || action "oper組創建失敗" /bin/false 116 [ `cat /etc/group|grep asmadmin|wc -l` -gt 0 ] && action "asmadmin組創建成功" /bin/true || action "asmadmin組創建失敗" /bin/false 117 [ `cat /etc/group|grep asmdba|wc -l` -gt 0 ] && action "asmdba組創建成功" /bin/true || action "asmdba組創建失敗" /bin/false 118 [ `cat /etc/group|grep asmoper|wc -l` -gt 0 ] && action "asmoper組創建成功" /bin/true || action "asmoper組創建失敗" /bin/false 119 } 120 121 #創建oracle、grid用戶 122 function createUser 123 { 124 [ `cat /etc/passwd|grep oracle|wc -l` -gt 0 ] && userdel oracle 125 [ `cat /etc/passwd|grep grid|wc -l` -gt 0 ] && userdel grid 126 read -p "請輸入oracle ID:" oracleuid 127 read -s -p "請輸入oracle用戶密碼:" orapasswd && echo -e "\r" 128 read -p "請輸入grid ID:" griduid 129 read -s -p "請輸入grid用戶密碼:" gridpasswd && echo -e "\r" 130 useradd -u $oracleuid -g oinstall -G dba,oper,asmdba,asmadmin oracle 131 [ $? -eq 0 ] && action "創建oracle用戶成功" /bin/true || action "創建oracle用戶失敗" /bin/false 132 echo "$orapasswd"|passwd oracle --stdin >/dev/null 133 useradd -u $griduid -g oinstall -G dba,asmadmin,asmdba,asmoper grid 134 [ $? -eq 0 ] && action "創建grid用戶成功" /bin/true || action "創建grid用戶失敗" /bin/false 135 echo "$gridpasswd"|passwd grid --stdin >/dev/null 136 } 137 138 #創建目錄 139 function createDIR 140 { 141 rm -rf /u01/app 142 mkdir -p /u01/app/11.2.0/grid 143 mkdir -p /u01/app/grid 144 mkdir -p /u01/app/oracle/product/11.2.0/db_1 145 if [ -d /u01/app/11.2.0/grid ] && [ -d /u01/app/grid ] && [ -d /u01/app/oracle/product/11.2.0/db_1 ];then 146 action "創建目錄成功" /bin/true 147 else 148 action "創建目錄失敗" /bin/false 149 fi 150 chown -R grid:oinstall /u01 151 chmod -R 775 /u01/ 152 chown -R oracle:oinstall /u01/app/oracle 153 } 154 155 156 function oracleProfile 157 { 158 if [ `su - oracle -c "env|grep ORA|wc -l"` -gt 0 ];then 159 action "修改oracle環境" /bin/true 160 else 161 su - oracle -c echo -e "export ORACLE_BASE=/u01/app/oracle\nexport ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1" >> ~/.bash_profile 162 su - oracle -c echo -e "export ORACLE_TERM=xterm\nexport PATH=/usr/sbin:$PATH\nexport PATH=$ORACLE_HOME/bin:$PATH" >> ~/.bash_profile 163 su - oracle -c echo -e "export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib\nexport CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib" >> ~/.bash_profile 164 su - oracle -c echo -e "ulimit -u 16384 -n 65536\numask 022" >> ~/.bash_profile && source ~/.bash_profile 165 if [ `su - oracle -c "env|grep ORA|wc -l"` -gt 0 ];then 166 action "修改oracle環境" /bin/true 167 else 168 action "修改oracle環境" /bin/false 169 fi 170 fi 171 } 172 173 #修改環境變量 174 function gridProfile 175 { 176 if [ `su - grid -c "env|grep ORA|wc -l"` -gt 0 ];then 177 action "修改grid環境" /bin/true 178 else 179 su - grid -c echo -e "export export ORACLE_SID=+ASM\nexport ORACLE_BASE=/u01/app/grid\nexport ORACLE_HOME=/u01/app/11.2.0/grid" >> ~/.bash_profile 180 su - grid -c echo -e "export PATH=$PATH:$HOME/bin\nexport PATH=/usr/sbin:$PATH:$ORACLE_HOME/bin:$PATH" >> ~/.bash_profile 181 su - grid -c echo -e "export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib\nexport CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib" >> ~/.bash_profile 182 su - grid -c echo -e "export TEMP=/tmp\nexport TMP=/tmp\nexport TMPDIR=/tmp\numask 022" >> ~/.bash_profile && source ~/.bash_profile 183 if [ `su - grid -c "env|grep ORA|wc -l"` -gt 0 ];then 184 action "修改grid環境" /bin/true 185 else 186 action "修改grid環境" /bin/false 187 fi 188 fi 189 } 190 191 #主函數 192 function main 193 { 194 yumPackge 195 modifyLimit 196 modifyKennel 197 modifyProfile 198 createGroup 199 createUser 200 createDIR 201 oracleProfile 202 gridProfile 203 } 204 205 main

ORACLE環境安裝腳本