• ORACLE环境安装脚本


    分享一个自己写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 "
    "
    128     read -p "请输入grid ID:" griduid    
    129     read -s -p "请输入grid用户密码:" gridpasswd && echo -e "
    "
    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
    export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1" >> ~/.bash_profile'
    162         su - oracle -c 'echo -e "export ORACLE_TERM=xterm
    export PATH=/usr/sbin:$PATH
    export PATH=$ORACLE_HOME/bin:$PATH" >> ~/.bash_profile'
    163         su - oracle -c 'echo -e "export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
    export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib" >> ~/.bash_profile'
    164         su - oracle -c 'echo -e "ulimit -u 16384 -n 65536
    umask 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
    export ORACLE_BASE=/u01/app/grid
    export ORACLE_HOME=/u01/app/11.2.0/grid" >> ~/.bash_profile'
    180         su - grid -c 'echo -e "export PATH=$PATH:$HOME/bin
    export 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
    export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib" >> ~/.bash_profile'
    182         su - grid -c 'echo -e "export TEMP=/tmp
    export TMP=/tmp
    export TMPDIR=/tmp
    umask 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
  • 相关阅读:
    jq动画效果
    each循环和节点操作
    jquery的基础语法
    JS作用域
    DOM事件
    js语法一
    socketserver模块与mysql语句(一)
    亲测idea编辑器控制台中文乱码成功的解决方法
    PHP Fatal error: Call to undefined function json_decode()
    PHP <? 标签问题导致不能正确运行代码
  • 原文地址:https://www.cnblogs.com/shaozi/p/8343712.html
Copyright © 2020-2023  润新知