zoukankan      html  css  js  c++  java
  • 【SHELL】Linux下安装Oracle Client

    一、新建Oracle脚本存储目录并上传文件

    [root@A04-Test-172]# mkdir  -p /tmp/instance_oracle                    #新建存储目录

    [root@A04-Test-172 install_oracle]# ll
    total 4452872
    -rw-r--r-- 1 root root 8752 Apr 26 08:24 client_install.rsp
    -rwxr-xr-x 1 root root 3880 Apr 26 09:16 install_oracle_2.sh
    -rw-r--r-- 1 root root 706187979 Apr 25 14:54 linux.x64_11gR2_client.zip
    -rwxr-xr-x 1 root root 803 Apr 25 14:52 repo_1.sh
    -rw-r--r-- 1 root root 118 Apr 23 13:51 rhel.repo
    -rw-r--r-- 1 root root 3853516800 Apr 25 14:29 rhel-server-6.5-x86_64-dvd.iso
    [root@A04-Test-172 install_oracle]#

    二、安装脚本说明

    执行脚本时需依照脚本后的尾号顺序进行执行!

    1. repo_1.sh

    说明:该脚本用来挂载ISO镜像,为Oracle安装依赖包做准备!

    [root@A04-Test-172 install_oracle]# more repo_1.sh 
    #!/bin/bash
    
    #The script is used to replace repo file
    
    #1.create mount directory                          #判断/yum目录是否存在,如果不存在,则新建
    if [ -d "/yum" ];then                                     
        echo "Warning: The /yum directory is exitst!"
    else
        mkdir /yum
    fi
    
    #2.mount iso                                       #判断/yum目录下是否已挂载文件,如果未挂载,则进行挂载
    mountnum=`ls -lrt /yum|wc -l`
    if [ $mountnum -gt 1 ];then
        echo "Warning:The directory is mounted!"
    else
        mount -o loop /tmp/install_oracle/rhel-server-6.5-x86_64-dvd.iso  /yum
    fi
    
    #3.modify repofile                                #判断/etc/yum.repos.d目录下是否有扩展名为.repo的文件,如果有则进行重命名。重命名格式:原名称.当前日期
    CurrentDate=`date +%Y-%m-%d`
    repofile=`find /etc/yum.repos.d  -name "*.repo"|wc -l`
    if [ $repofile == 0 ];then
         echo "Warning: The repo file is no exsits! Now starting copy repo file to destination directory!"
    else
         for i in `find /etc/yum.repos.d  -name "*.repo"`
         do
            mv $i $i.$CurrentDate
         done
    fi
    cp /tmp/install_oracle/rhel.repo /etc/yum.repos.d         #复制/tmp/instance_oracle目录下的文件到/etc/yum.repos.d目录
    echo "The directory mount over!"
    [root@A04-Test-172 install_oracle]# more rhel.repo 
    [rhel-source]
    name=Red Hat Enterprise Linux $releasever - $basearch - Source
    baseurl=file:///yum
    enabled=1
    gpgcheck=0

    2. install_oracle_2.sh

    说明:该脚本主要完成Oracle Client的安装工作,主要包括新建oracle用户、新建Oracle安装目录,修改环境变量,安装Oracle Client.

               Oracle安装时的一些选项通过文件client_install.rsp来配置,该文件默认在Oracle解压后的response目录下。

    [root@A04-Test-172 install_oracle]# more install_oracle_2.sh 
    #!/bin/bash
    
    
    echo "#####################1.add ip and hostname to /etc/hosts###########"
    ip=`ifconfig|grep "inet addr"|grep "Bcast"|awk -F: '{print$2 }'|awk '{print$1}'`
    hostname1=`hostname`
    checkhosts=`cat /etc/hosts|grep $ip|wc -l`
    if [ $checkhosts -eq 0 ];then
       echo "$ip $hostname1">>/etc/hosts
    else
       echo "Warning: the hostname added to the /etc/hosts!"
    fi
    
    
    echo "#####################2.create user and  group######################"
    
    group1=`cat /etc/group|grep oinstall|wc -l`
    group2=`cat /etc/group|grep dba|wc -l`
    user1=`cat /etc/passwd|grep oracle|wc -l`
    
    if [ $group1 -eq 0 ];then
        /usr/sbin/groupadd oinstall
    else
        echo "Warning:The oinstall group is exists!"
    fi
    
    if [ $group2 -eq 0 ];then
        /usr/sbin/groupadd dba
    else
        echo "Warning:The dba  group is exists!"
    fi
    
    
    if [ $user1 -eq 0 ];then
        /usr/sbin/useradd -m -g oinstall -G dba oracle
        echo "a4oracle"|passwd --stdin oracle
    else
        echo "Warning:The user oracle  is exists!"
    fi
    
    
    echo "The user and group created finish!"
    
    
    
    
    echo "######################4.create directory##############################"
    
    if [ ! -d "/u01/app/oracle" ];then
       mkdir -p /u01/app/oracle
       chown -R oracle:oinstall /u01/app/oracle
       chmod -R 775 /u01/app/oracle
    else
       echo "Warning: /u01/app/oracle is exists!"
    fi
    
    if [ ! -d "/u01/app/oraInventory" ];then
       mkdir -p /u01/app/oraInventory
       chown -R oracle:oinstall /u01/app/oraInventory
    else
       echo "Warning: /u01/app/oraInventory is exists!"
    fi
    
    cp /etc/skel/.bashrc  /home/oracle
    cp /etc/skel/.bash_logout /home/oracle
    cp /etc/skel/.bash_profile /home/oracle
    
    
    echo "The Oracle install directory created finish"
    
    
    
    
    echo "#####################5.add env variable on oracle user###############"
    
    user1=`cat /etc/passwd|grep oracle|wc -l`
    if [ $user1 -eq 1 ];then
    su - oracle<<EOF
    echo "umask 022
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/client_1
    export PATH=\$ORACLE_HOME/bin:\$PATH" >> ~/.bash_profile;
    
    source ~/.bash_profile;
    EOF
    
    else
       echo "The oracle user is non exists!"
       exit;
    fi
    
    
    
    
    
    
    echo "######################6.add content in /etc/sysctl.conf###############"
    echo "fs.aio-max-nr = 1048576
    fs.file-max = 6815744
    kernel.shmall = 2097152
    kernel.shmmax = 536870912
    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">>/etc/sysctl.conf
    
    /sbin/sysctl -p
    
    echo  "The /etc/sysctl.conf modified finish!"
    
    
    
    
    
    echo  "####################7.install depend on package#######################"
    yum -y install libaio.i686 libaio-devel.i686
    yum -y install libstdc++.i686  libstdc++-devel.i686 compat-libstdc++-33.i686  elfutils-libs.i686 glibc.i686  unixODBC.i686  unixODBC-devel.i686
    yum -y install gcc gcc-c++ libaio libaio-devel libstdc++ libstdc++-devel elfutils-libelf-devel unixODBC unixODBC-devel compat-libstdc++
    
    echo "The oracle depend package installed finish!"
    
    
    
    
    
    echo  "####################8.install oracle client###########################"
    su - oracle<<EOF
    mkdir -p /home/oracle/client;
    cp       /tmp/install_oracle/linux.x64_11gR2_client.zip  /home/oracle/client;
    unzip    /home/oracle/client/linux.x64_11gR2_client.zip;
    mv       /home/oracle/client/linux.x64_11gR2_client.zip  /home/oracle;
    mv       /home/oracle/client/response/client_install.rsp /home/oracle/client/response/client_install.rsp.bak;
    cp       /tmp/install_oracle/client_install.rsp          /home/oracle/client/response;
    chown -R oracle:oinstall /home/oracle/client;
    
    cd /home/oracle/client;
    ./runInstaller -silent -responseFile /home/oracle/client/response/client_install.rsp
    EOF
    
    
    
    echo "#####################9.execute root script#############################"
    sleep 180s              #Oracle安装时需要一定时间,在安装完成时,需要执行如下两个脚本,这里给一个休眠时间,避免Oracle未安装完成就执行脚本,也可以手动执行脚本
    /u01/app/oraInventory/orainstRoot.sh
    /u01/app/oracle/product/11.2.0/client_1/root.sh

    client_install.rsp内容如下,主要修改标记红色部分,当然也可根据自己实际要求进行配置:

    [root@A04-Test-172 install_oracle]# more client_install.rsp 
    ###############################################################################
    ## Copyright(c) Oracle Corporation 1998,2008. All rights reserved.           ##
    ##                                                                           ##
    ## Specify values for the variables listed below to customize                ##
    ## your installation.                                                        ##
    ##                                                                           ##
    ## Each variable is associated with a comment. The comment                   ##
    ## can help to populate the variables with the appropriate                   ##
    ## values.                                                                   ##
    ##                                                                           ##
    ###############################################################################
    
    #-------------------------------------------------------------------------------
    # Do not change the following system generated value. 
    #-------------------------------------------------------------------------------
    oracle.install.responseFileVersion=/oracle/install/rspfmt_clientinstall_response_schema_v11_2_0
    
    #-------------------------------------------------------------------------------
    # This variable holds the hostname of the system as set by the user. 
    # It can be used to force the installation to use an alternative   
    # hostname rather than using the first hostname found on the system
    # (e.g., for systems with multiple hostnames and network interfaces).
    ORACLE_HOSTNAME=Oracle_Client          #Oracle主机名,这里可通过hostname查询到
    #-------------------------------------------------------------------------------
    # Unix group to be set for the inventory directory.  
    UNIX_GROUP_NAME=oinstall               #Oracle安装时所属组
    #-------------------------------------------------------------------------------
    # Inventory location.
    INVENTORY_LOCATION=/u01/app/oraInventory   #Oracle清单安装目录
    #-------------------------------------------------------------------------------
    # Languages in which the components will be installed.             
    #
    # en   : English                  ja   : Japanese                  
    # fr   : French                   ko   : Korean                    
    # ar   : Arabic                   es   : Latin American Spanish    
    # bn   : Bengali                  lv   : Latvian                   
    # pt_BR: Brazilian Portuguese     lt   : Lithuanian                
    # bg   : Bulgarian                ms   : Malay                     
    # fr_CA: Canadian French          es_MX: Mexican Spanish           
    # ca   : Catalan                  no   : Norwegian                 
    # hr   : Croatian                 pl   : Polish                    
    # cs   : Czech                    pt   : Portuguese                
    # da   : Danish                   ro   : Romanian                  
    # nl   : Dutch                    ru   : Russian                   
    # ar_EG: Egyptian                 zh_CN: Simplified Chinese        
    # en_GB: English (Great Britain)  sk   : Slovak                    
    # et   : Estonian                 sl   : Slovenian                 
    # fi   : Finnish                  es_ES: Spanish                   
    # de   : German                   sv   : Swedish                   
    # el   : Greek                    th   : Thai                      
    # iw   : Hebrew                   zh_TW: Traditional Chinese       
    # hu   : Hungarian                tr   : Turkish                   
    # is   : Icelandic                uk   : Ukrainian                 
    # in   : Indonesian               vi   : Vietnamese                
    # it   : Italian                                                   
    #
    # Example : SELECTED_LANGUAGES=en,fr,ja
    #-------------------------------------------------------------------------------
    SELECTED_LANGUAGES=en                  #默认的语言,这里选择英文
    #-------------------------------------------------------------------------------
    # Complete path of the Oracle Home  
    #ORACLE_HOME=$ORACLE_BASE/product/11.2.0/client_1
    ORACLE_HOME=/u01/app/oracle/product/11.2.0/client_1
    #-------------------------------------------------------------------------------
    # Complete path of the Oracle Base. 
    ORACLE_BASE=/u01/app/oracle            #Oracle安装基目录
    #-------------------------------------------------------------------------------
    #Name       : INSTALL_TYPE
    #Datatype   : String
    #Description: Installation type of the component.
    #
    #             The following choices are available. The value should contain
    #             only one of these choices.
    #             InstantClient : InstantClient
    #             Administrator : Administrator
    #             Runtime       : Runtime
    #             Custom        : Custom
    #
    #Example    : INSTALL_TYPE = "Administrator"
    #------------------------------------------------------------------------------
    oracle.install.client.installType=Administrator      #oracle安装时使用的用户类型
    #-------------------------------------------------------------------------------
    # Name       : oracle.install.client.customComponents
    # Datatype   : StringList
    #
    # This property is considered only if INSTALL_TYPE is set to "Custom"
    #
    # Description: List of Client Components you would like to install
    #
    #   The following choices are available. You may specify any
    #   combination of these choices.  The components you choose should
    #   be specified in the form "internal-component-name:version"
    #   Below is a list of components you may specify to install.
    #
    # oracle.sqlj:11.2.0.1.0 -- "Oracle SQLJ"
    # oracle.rdbms.util:11.2.0.1.0 -- "Oracle Database Utilities"
    # oracle.javavm.client:11.2.0.1.0 -- "Oracle Java Client"
    # oracle.sqlplus:11.2.0.1.0 -- "SQL*Plus"
    # oracle.dbjava.jdbc:11.2.0.1.0 -- "Oracle JDBC/THIN Interfaces"
    # oracle.ldap.client:11.2.0.1.0 -- "Oracle Internet Directory Client"
    # oracle.rdbms.oci:11.2.0.1.0 -- "Oracle Call Interface (OCI)"
    # oracle.precomp:11.2.0.1.0 -- "Oracle Programmer"
    # oracle.xdk:11.2.0.1.0 -- "Oracle XML Development Kit"
    # oracle.network.aso:11.2.0.1.0 -- "Oracle Advanced Security"
    # oracle.assistants.oemlt:11.2.0.1.0 -- "Enterprise Manager Minimal Integration"
    # oracle.oraolap.mgmt:11.2.0.1.0 -- "OLAP Analytic Workspace Manager and Worksheet"
    # oracle.network.client:11.2.0.1.0 -- "Oracle Net"
    # oracle.network.cman:11.2.0.1.0 -- "Oracle Connection Manager"
    # oracle.network.listener:11.2.0.1.0 -- "Oracle Net Listener"
    # oracle.ordim.client:11.2.0.1.0 -- "Oracle Multimedia Client Option"
    # oracle.ons:11.2.0.0.0 -- "Oracle Notification Service"
    # oracle.odbc:11.2.0.1.0 -- "Oracle ODBC Driver"
    # oracle.has.client:11.2.0.1.0 -- "Oracle Clusterware High Availability API"
    # oracle.dbdev:11.2.0.1.0 -- "Oracle SQL Developer"
    # oracle.rdbms.scheduler:11.2.0.1.0 -- "Oracle Scheduler Agent"
    #
    #-------------------------------------------------------------------------------
    oracle.install.client.customComponents="oracle.sqlj:11.2.0.1.0","oracle.rdbms.util:11.2.0.1.0","oracle.javavm.client:11.2.0.1.0","oracle.sqlplus:11.2.0.1.0","oracle.db
    java.jdbc:11.2.0.1.0","oracle.ldap.client:11.2.0.1.0","oracle.rdbms.oci:11.2.0.1.0","oracle.precomp:11.2.0.1.0","oracle.xdk:11.2.0.1.0","oracle.network.aso:11.2.0.1.0"
    ,"oracle.assistants.oemlt:11.2.0.1.0","oracle.oraolap.mgmt:11.2.0.1.0","oracle.network.client:11.2.0.1.0","oracle.network.cman:11.2.0.1.0","oracle.network.listener:11.
    2.0.1.0","oracle.ordim.client:11.2.0.1.0","oracle.ons:11.2.0.0.0","oracle.odbc:11.2.0.1.0","oracle.has.client:11.2.0.1.0","oracle.dbdev:11.2.0.1.0","oracle.rdbms.sched
    uler:11.2.0.1.0"
    #-------------------------------------------------------------------------------
    #Name       : MTS_PORT
    #Datatype   : int 
    #Description: Port number to be used for by the Oracle MTS Recovery Service to listen
    #             for requests. This needs to be entered in case oracle.ntoramts is 
    #             selected in the list of custom components in custom install
    #
    #
    #Example    : MTS_PORT = 2030
    #------------------------------------------------------------------------------
    oracle.install.client.oramtsPortNumber=
    
    #------------------------------------------------------------------------------
    # Host name to be used for by the Oracle Scheduler Agent.
    # This needs to be entered in case oracle.rdbms.scheduler is selected in the
    # list of custom components during custom install
    #
    # Example    : oracle.install.client.schedulerAgentHostName = acme.domain.com
    #------------------------------------------------------------------------------
    oracle.install.client.schedulerAgentHostName=
    
    #------------------------------------------------------------------------------
    # Port number to be used for by the Oracle Scheduler Agent.
    # This needs to be entered in case oracle.rdbms.scheduler is selected in the
    # list of custom components during custom install
    #
    # Example: oracle.install.client.schedulerAgentPortNumber = 1500
    #------------------------------------------------------------------------------
    oracle.install.client.schedulerAgentPortNumber=

    三、验证是否安装完成

    Oracle安装成功后,可以切换至Oracle用户时,使用sqlplus登录数据库,看是否可以登录上。如果可以,说明安装成功。

  • 相关阅读:
    86. Partition List
    328. Odd Even Linked List
    19. Remove Nth Node From End of List(移除倒数第N的结点, 快慢指针)
    24. Swap Nodes in Pairs
    2. Add Two Numbers(2个链表相加)
    92. Reverse Linked List II(链表部分反转)
    109. Convert Sorted List to Binary Search Tree
    138. Copy List with Random Pointer
    为Unity的新版ugui的Prefab生成预览图
    ArcEngine生成矩形缓冲区
  • 原文地址:https://www.cnblogs.com/xialiaoliao0911/p/8966447.html
Copyright © 2011-2022 走看看