• Oracle 11g 静默安装脚本


    #!/bin/bash
    ####安装Oracle所需依赖包
    function install_yum()
    {
      yum -y install $1
    }
    i="perl-Data-Dumper lvm2* unzip rlwrap screen binutils binutils-devel compat-db control-center control-center-devel
    compat-libstdc++-* elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static
    expat expat-devel gcc gcc-c++ glibc libaio libaio-devel libgcc libstdc++ libstdc++-devel
    libXp libXp-devel make openmotif openmotif-devel ksh unixODBC unixODBC-devel mdadm readline*"
    for j in $i
    do
      install_yum $j
    done
    ################ 软raid 0
    m1=`ls /dev/* |grep md0`
    if [ ! -n "$m1" ]
    then
      ra=`ls /tmp/raiddir/*|awk -F'/' '{print $4}'|awk -F'.' 'BEGIN{ORS=" "}{print "/dev/"$1}'`
      rb=`ls /tmp/raiddir/*|wc -l`
      if [ $rb -eq 0 ]
      then
        echo "no init partition storage"
      else
        mdadm -C /dev/md0 -l raid0 -n $rb $ra
        mkfs.ext4 /dev/md0
        mdadm -E -s -v >> /etc/mdadm.conf
        mkdir /u02
        mount /dev/md0 /u02
        echo '/dev/md0 /u02 ext4 defaults 0 0'>>/etc/fstab
      fi
    else
      echo 'Md0 has been created'
    fi
    ####配置/etc/hosts
    ip_dir=`ifconfig |grep inet|grep -v '127.0.0.1'|awk '{print $2}'|sed -n '1p'`
    hname=`hostname`
    red=`cat /etc/hosts|grep "$hname"|wc -l`
    if [ $red -eq 1 ]
    then
      echo "/etc/hosts is OK Nothing to do"
    else
      echo "$ip_dir" "$hname" >>/etc/hosts
      echo "/etc/hosts is OK"
    fi

    ####创建Oracle数据库安装所需多个目录与Oracle账户
    groupadd -g 501 oinstall
    groupadd -g 502 dba
    groupadd -g 503 oper
    useradd  -u 501  -g  oinstall  -G dba,oper oracle
    echo oracle:oracle | chpasswd
    ORACLE_BASE=/u01/app/oracle
    ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
    hostname=`hostname`
    echo '
    PATH=$PATH:$HOME/bin
    umask 022
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_SID=paydb
    export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
    export PATH=$HOME/bin:$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/OPatch/
    export TMP=/tmp
    export TMPDIR=/tmp
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
    export LC_TYPE=en_US.UTF-8
    export PATH
    alias sqlplus="rlwrap sqlplus"
    alias rman="rlwrap rman"
    alias trace="cd /u01/app/oracle/diag/rdbms/paydb/paydb/trace"
    alias dbs="cd /u01/app/oracle/product/11.2.0/db_1/dbs"
    alias tns="cd /u01/app/oracle/product/11.2.0/db_1/network/admin"
    alias arch="cd /u02/paydb/archivelog"
    alias backup="cd /u02/paydb/backup"
    alias redo="cd /u02/paydb/redo"
    alias data="cd /u02/paydb/oradata"
    alias awr="cd /u01/app/oracle/product/11.2.0/db_1/rdbms/admin"
    alias listener="cd /u01/app/oracle/diag/tnslsnr/"$hostname"/listener/trace/"
    '>>/home/oracle/.bash_profile
    su - oracle <<EOF
    source .bash_profile
    EOF
    mkdir -p  /u01/app/oracle/product/11.2.0/db_1
    mkdir -p  /u01/app/oraInventory
    chown -R  oracle:oinstall /u01/app
    chmod -R  775  /u01/app/oracle
    #mkdir /u02
    #mount /dev/md0 /u02
    mkdir /u02/paydb/{oradata,archivelog,redo,standby,backup/{dump,rman}} -p
    chown -R  oracle:oinstall /u02/paydb/
    chmod -R  775  /u02/paydb/
    mkdir -p /u04/oracle
    id oracle
    uid=`echo $?`
    if [ $uid -eq 0 ]
    then
      echo "User: Oracle is Created"
    else
      echo "User: Oracle is Wrong"
      echo "Pleas check!"
      exit
    fi
    ####配置系统内核
    g=`free -b|grep Mem|awk '{print $2}'`
    h=$(($g*4/5))
    shmall=$(($h/4096))
    echo "
    #oracle
    kernel.sysrq = 0
    kernel.msgmnb = 65536
    kernel.shmall = $shmall
    fs.file-max = 6815744
    kernel.msgmni = 2878
    kernel.msgmax = 8192
    kernel.msgmnb = 65536
    kernel.sem = 250 32000 100 142
    kernel.shmmni = 4096
    kernel.shmmax = $h
    kernel.sysrq = 0
    net.core.wmem_default = 262144
    net.core.rmem_default = 262144
    net.core.rmem_max = 4194304
    net.core.wmem_max = 1048576
    fs.aio-max-nr = 3145728
    net.ipv4.ip_local_port_range = 9000 65500
    vm.min_free_kbytes = 51200" >> /etc/sysctl.conf
    /sbin/sysctl -p
    echo "session required pam_limits.so">> /etc/pam.d/login
    echo "
    oracle soft nproc 2047
    oracle hard nproc 16384
    oracle soft nofile 1024
    oracle hard nofile 65536" >>/etc/security/limits.conf
    echo '
    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'>>/etc/profile
    source /etc/profile
    ##解压缩Oracle安装软件
    udir=/u04/oracle/database
    if [ -e $udir ]
    then
      echo "Oracle soft has been created"
      exit
    else
      unzip /tmp/p13390677_112040_Linux-x86-64_1of7.zip -d  /u04/oracle
      unzip /tmp/p13390677_112040_Linux-x86-64_2of7.zip -d  /u04/oracle
      ox=`echo $?`
      if [ $ox -eq 0 ]
      then
        echo "Unzip oracle soft is right"
      else
        echo "Unzip oracle soft is wrong"
        exit
      fi
    fi
    ##安装Oracle软件
    m=`find /u04 -name db_install.rsp`
    function replace_install()
    {
    sed -i 's/'$1'/'$2'/g' $3
    }
    replace_install "oracle.install.option="  "oracle.install.option=INSTALL_DB_SWONLY"  $m
    replace_install "ORACLE_HOSTNAME="        "ORACLE_HOSTNAME=$hname"  $m
    replace_install "UNIX_GROUP_NAME="        "UNIX_GROUP_NAME=oinstall"  $m
    replace_install "INVENTORY_LOCATION="     "INVENTORY_LOCATION=/u01/app/oraInventory"  $m
    replace_install "SELECTED_LANGUAGES=en"   "SELECTED_LANGUAGES=en,zh_TW,zh_CN"  $m
    replace_install "ORACLE_HOME="            "ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1"  $m
    replace_install "ORACLE_BASE="            "ORACLE_BASE=/u01/app/oracle"  $m
    replace_install "oracle.install.db.InstallEdition="  "oracle.install.db.InstallEdition=EE"  $m
    replace_install "oracle.install.db.DBA_GROUP="       "oracle.install.db.DBA_GROUP=dba"  $m
    replace_install "oracle.install.db.OPER_GROUP="      "oracle.install.db.OPER_GROUP=oper"  $m
    replace_install "oracle.install.db.CLUSTER_NODES="   "#oracle.install.db.CLUSTER_NODES="  $m
    replace_install "SECURITY_UPDATES_VIA_MYORACLESUPPORT="  "SECURITY_UPDATES_VIA_MYORACLESUPPORT=false"  $m
    replace_install "DECLINE_SECURITY_UPDATES="              "DECLINE_SECURITY_UPDATES=true"  $m
    replace_install "oracle.installer.autoupdates.option="   "oracle.installer.autoupdates.option=SKIP_UPDATES"  $m
    n=`find /u04 -name runInstaller`
    su - oracle >>ora_install.log <<EOF
    $n -silent -responseFile $m -ignoreSysPrereqs -ignorePrereq
    EOF
    sleep 300
    sh /u01/app/oraInventory/orainstRoot.sh
    sh /u01/app/oracle/product/11.2.0/db_1/root.sh
    p=`cat ora_install.log |grep -w 'Successfully Setup Software.'`
    r='Successfully Setup Software.'
    if [ "$p" = "$r" ]
    then
      echo "ora_soft_install is right"
    else
      echo "ora_soft_install is wrong"
      exit
    fi
    ####create netca###netca -silent -responseFile /u04/oracle/database/response/netca.rsp
    s=`find /u04 -name netca.rsp`
    su - oracle >> net.log <<EOF
    netca -silent -responseFile $s
    EOF
    t=`echo $?`
    if [ $t -eq 0 ]
    then
      echo "netca is right"
    else
      echo "netca is wrong"
      exit
    fi
    echo '
    SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (GLOBAL_DBNAME = paydb)
          (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
          (SID_NAME = paydb)
        )
      )
    '>> $ORACLE_HOME/network/admin/listener.ora
    su - oracle <<EOF
    lsnrctl stop
    lsnrctl start
    EOF
    ####create database####dbca -silent -responseFile /u04/oracle/database/response/dbca.rsp
    v=`find /u04 -name dbca.rsp`
    sed -i 's/GDBNAME = "orcl11g.us.oracle.com"/GDBNAME = "paydb"/g' $v
    sed -i 's/SID = "orcl11g"/SID = "paydb"/g' $v
    sed -i 's/#SYSPASSWORD = "password"/SYSPASSWORD = "oracle"/g' $v
    sed -i 's/#SYSTEMPASSWORD = "password"/SYSTEMPASSWORD = "oracle"/g' $v
    sed -i 's/#EMCONFIGURATION = "NONE"/EMCONFIGURATION = "NONE"/g' $v
    sed -i 's/#SYSMANPASSWORD = "password"/SYSMANPASSWORD = "oracle"/g' $v
    sed -i 's/#DBSNMPPASSWORD = "password"/DBSNMPPASSWORD = "oracle"/g' $v
    sed -i 's/#CHARACTERSET = "US7ASCII"/CHARACTERSET = "ZHS16GBK"/g' $v
    sed -i 's/#MEMORYPERCENTAGE = "40"/MEMORYPERCENTAGE = "70"/g' $v
    sed -i 's#{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}#/u02/paydb/oradata#g' /u01/app/oracle/product/11.2.0/db_1/assistants/dbca/templates/General_Purpose.dbc
    red=`cat /u01/app/oracle/product/11.2.0/db_1/assistants/dbca/templates/General_Purpose.dbc|grep -w "/u02/paydb/oradata"|wc -l`
    if [ $red -eq 10 ]
    then
      echo "Sed dbca.rsp & General_Purpose.dbc is OK"
    else
      echo "Sed dbca.rsp & General_Purpose.dbc is Wrong"
      exit
    fi
    su - oracle >>dbca.log <<EOF
    dbca -silent -responseFile $v
    EOF
    x=$?
    if [ $x -eq 0 ]
    then
      echo "dbca is right!"
    else
      echo "dbca is wrong!"
      exit
    fi
    ####变更Oracle参数
    su - oracle <<EOF
    sqlplus / as sysdba << S
    alter system set processes=5000 scope=spfile;
    alter system set session_cached_cursors=1000 scope=spfile;
    alter system set open_cursors=1000 scope=spfile;
    alter system set log_archive_dest_1='location=/u02/paydb/archivelog';
    create pfile from spfile;
    shutdown immediate;
    exit;
    S
    sqlplus / as sysdba << Z
    startup mount;
    alter database archivelog;
    alter database open;
    create pfile from spfile;
    create directory dump as '/u02/paydb/backup/dump/';
    alter tablespace users add datafile '/u02/paydb/oradata/users02.dbf' size 10G;
    alter tablespace users add datafile '/u02/paydb/oradata/users03.dbf' size 10G;
    alter tablespace users add datafile '/u02/paydb/oradata/users04.dbf' size 10G;
    alter tablespace users add datafile '/u02/paydb/oradata/users05.dbf' size 10G;
    alter tablespace users add datafile '/u02/paydb/oradata/users06.dbf' size 10G;
    alter tablespace users add datafile '/u02/paydb/oradata/users07.dbf' size 10G;
    alter tablespace users add datafile '/u02/paydb/oradata/users08.dbf' size 10G;
    alter tablespace users add datafile '/u02/paydb/oradata/users09.dbf' size 10G;
    alter tablespace users add datafile '/u02/paydb/oradata/users10.dbf' size 10G;
    create tablespace DBADMIN datafile '/u02/paydb/oradata/dbadmin_data01' size 500M;
    create user dbadmin identified by QazWsx12 default tablespace DBADMIN;
    grant dba to dbadmin;
    grant read,write on directory dump to dbadmin;
    grant select on v_$database to dbadmin;
    grant select on v_$instance to dbadmin;
    grant select on dba_free_space to dbadmin;
    grant select on DBA_HIST_SYSMETRIC_SUMMARY to dbadmin;
    grant select on v_$archived_log to dbadmin;
    grant select on dba_data_files to dbadmin;
    grant select on V_$SGAINFO to dbadmin;
    grant select on dba_temp_free_space to dbadmin;
    grant select on dba_temp_files to dbadmin;
    GRANT SELECT ON V_$SQLAREA TO dbadmin;
    grant select on v_$sqlarea to dbadmin;
    exit;
    Z
    EOF
    echo "Oracle install is OK!"
    #################################################################flyway init
    yum -y install java
    mkdir -p  /u10/flyway
    unzip     /tmp/flyway-commandline-4.2.0-windows-x64.zip -d /u10/flyway
    flyway_home=/u10/flyway/flyway-4.2.0/
    flyway_conf=/u10/flyway/flyway-4.2.0/conf/flyway.conf
    flyway_sql=/u10/flyway/flyway-4.2.0/sql/db/migration
    flyway_drivers=/u10/flyway/flyway-4.2.0/drivers
    cp        /tmp/ojdbc6.jar  $flyway_drivers
    ln -s /u10/flyway/flyway-4.2.0/flyway /usr/bin/flyway
    cd /u10/flyway/flyway-4.2.0
    chmod 777 sql
    #a=`who|awk '{print $1}'`
    #cd
    echo "alias fly='cd /u10/flyway/flyway-4.2.0'" >>/etc/profile
    source /etc/profile
    ip_dir=`ifconfig |grep inet|grep -v '127.0.0.1'|awk '{print $2}'|sed -n '1p'`
    echo "
    flyway.url= jdbc:oracle:thin:@$ip_dir:1521:paydb
    flyway.user=DBADMIN
    flyway.password=QazWsx12
    flyway.schemas=DBADMIN
    flyway.table=SCHEMA_VERSION
    flyway.baselineOnMigrate=true" >> $flyway_conf
    flyway  migrate
    ##########################安装配置Oracle管理
    mkdir /u01/dba_scripts -p
    mkdir /u01/dba_scripts/db_performance -p
    mkdir /u01/dba_scripts/delete_archlog/log -p
    mkdir /u01/dba_scripts/tabsusage/log -p
    mkdir /u01/dba_scripts/rman/log -p
    mkdir /u01/dba_scripts/db_info -p
    mkdir /u01/dba_scripts/dbms_stats/log -p
    mkdir /u01/dba_scripts/other -p
    mv /tmp/db_performance_metric.sh   /u01/dba_scripts/db_performance
    mv /tmp/delete_archivelog.sh       /u01/dba_scripts/delete_archlog
    mv /tmp/update_tbs_info.sh         /u01/dba_scripts/tabsusage
    mv /tmp/rman_full.sh               /u01/dba_scripts/rman
    mv /tmp/db_information_output.sh   /u01/dba_scripts/db_info
    mv /tmp/dbms_stats_tables.sh       /u01/dba_scripts/dbms_stats
    cat /tmp/crontab.txt >> /var/spool/cron/oracle
    chown oracle.  /u01/dba_scripts -R
    chown oracle.  /var/spool/cron/oracle
    mkdir /u01/dba_scripts/nmon_tool -p
    mv /tmp/{nmon_x86_64_rhel6,value_nmon.sh} /u01/dba_scripts/nmon_tool/
    cat /tmp/crontab_root.txt >>/var/spool/cron/root
    mkdir /home/oracle/db_monitor -p
    cp -a /tmp/dba_* /home/oracle/db_monitor/
    chown oracle. /home/oracle/db_monitor/dba_*
  • 相关阅读:
    【2022年】Java瀑布流 2022.02.11 到 2022.12.31
    【002】Spring Boot Druid 2022.02.22 周二
    【转】搞懂这些Redis知识点,吊打面试官!
    sqlserver服务器名称改成本地IP地址登录
    request.getParameter(“参数名”) 中文乱码解决方法
    pads:数据格式不正确,网络必须包含一个以上管脚
    SQL 求 1000 以内的素数(MySQL8.0 版)
    Hive 安装配置
    MySQL 8.0 版本支持 CTE 语法
    [LeetCode]395. Longest Substring with At Least K Repeating Characters滑动窗口+分治(JavaScript)
  • 原文地址:https://www.cnblogs.com/xibuhaohao/p/10748582.html
Copyright © 2020-2023  润新知