zoukankan      html  css  js  c++  java
  • Centos7静默安装Oracle11g

    1、环境及准备工作

    1.1 环境及配置调整

    操作系统版本、内核版本、系统CPURAM、硬盘配置如下

    [root@localhost ~]# cat /etc/redhat-release
    CentOS Linux release 7.7.1908 (Core)
    [root@localhost ~]# uname -r
    3.10.0-1062.el7.x86_64
    [root@localhost ~]# cat /proc/cpuinfo| grep "processor"| wc -l
    8
    [root@localhost ~]# cat /proc/meminfo| grep MemTotal
    MemTotal:       131826144 kB
    [root@localhost ~]# cat /proc/meminfo| grep SwapTotal
    SwapTotal:       1835004 kB
    [root@localhost ~]# fdisk -l|grep Disk
    Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
    Disk label type: dos
    Disk identifier: 0x000e4fd0
    Disk /dev/vdb: 2199.0 GB, 2199023255552 bytes, 4294967296 sectors
    Disk /dev/mapper/centos-root: 18.5 GB, 18513657856 bytes, 36159488 sectors
    Disk /dev/mapper/centos-swap: 1879 MB, 1879048192 bytes, 3670016 sectors
    

    如下表所示

    项目
    操作系统 CentOS Linux release 7.7.1908 (Core)
    内核版本 3.10.0-1062.el7.x86_64
    CPU 8C
    RAM 128GB
    SWAP 1GB
    磁盘 /dev/vda 20G + /dev/vdb 2TB

    数据盘未做格式化分区(这里仅格式化并挂载到单独目录,不做分区)
    根据内存大小需要对此操作系统重新分配合适的swap空间(这里增加到16G),关于swap分区大小可参考红帽官方说明

    [root@localhost ~]# mkfs.xfs /dev/vdb
    [root@localhost ~]# mkdir /data && mount /dev/vdb /data
    [root@localhost ~]# df -h | grep "data"
    /dev/vdb                 2.0T   33M  2.0T   1% /data
    [root@localhost ~]# blkid |grep vdb|awk '{print $2}'|cut -d '=' -f 2
    "11eda493-b248-4ce0-91fb-e28e1b8164a9"
    [root@localhost ~]# echo "UUID=11eda493-b248-4ce0-91fb-e28e1b8164a9 /data                   xfs     defaults        0 0" >> /etc/fstab  # 开机自动挂载数据盘
    [root@localhost ~]# sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab  # 关掉原来的swap开机自动挂载
    [root@localhost ~]# dd if=/dev/zero of=/data/swapfile bs=1G count=16
    [root@localhost ~]# mkswap /data/swapfile
    [root@localhost ~]# chmod 600 /data/swapfile
    [root@localhost ~]# swapon /data/swapfile
    [root@localhost ~]# echo "/data/swapfile           swap                    swap    defaults        0 0" >> /etc/fstab  # 开机自动挂载swap分区
    

    1.2 常用参数

    修改主机名、关闭selinux、时间同步等

    [root@localhost ~]# hostnamectl set-hostname oracledb-01
    [root@localhost ~]# echo "127.0.0.1   oracledb-01" >> /etc/hosts
    [root@oracledb-01 ~]# sestatus
    SELinux status:                 disabled
    

    1.3 其他准备

    • 安装依赖

      [root@oracledb-01 ~]# yum -y install binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-dev libXi libXtst make sysstat unixODBC unixODBC-devel
      
    • 下载oracle安装包

      官网下载linux 64位安装包,下载后两个文件如下

      [root@oracledb-01 ~]# ls linux.x64_11gR2_database_2of2
      linux.x64_11gR2_database_1of2.zip  linux.x64_11gR2_database_2of2.zip
      
    • 创建用户:安装Oracle数据库,需要以下本地操作系统组和用户

      • Oracle inventory组(通常为 oinstall)
      • OSDBA组 (通常为 dba)
      • OSOPER组 (通常为 oper)
      • Oracle软件所有者(通常为 oracle)
      [root@oracledb-01 ~]# groupadd oinstall
      [root@oracledb-01 ~]# groupadd dba
      [root@oracledb-01 ~]# groupadd oper
      [root@oracledb-01 ~]# useradd -g oinstall -G dba oracle
      
    • 修改oracle用户的密码

      [root@oracledb-01 ~]# echo "oracle" | passwd --stdin oracle
      Changing password for user oracle.
      passwd: all authentication tokens updated successfully.
      
    • 配置资源限制和内核参数

      /etc/sysctl.conf添加如下参数,如果系统中某个参数高于下面的参数的值,保留较大的值,下面的数值只是官方要求的最小值,可以根据系统调整数值,以优化系统性能

      fs.aio-max-nr = 1048576	# 同时可以拥有的的异步IO请求数目
      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	# 发送缓冲区最大值
      

      使内核参数生效

      [root@oracledb-01 ~]# sysctl -p
      

      编辑/etc/security/limits.conf(用户限制配置文件),添加如下参数

      oracle              soft    nproc   2047
      oracle              hard    nproc   16384
      oracle              soft    nofile  1024
      oracle              hard    nofile  65536
      

      编辑/etc/pam.d/login文件,将配置文件加入到登录验证模块

      #Add for Install Oracle Database 11g
      session required  /lib64/security/pam_limits.so
      session required  pam_limits.so
      

      编辑/etc/profile文件(环境变量文件)

      [root@oracledb-01 ~]# vim /etc/profile
      if [ $USER = "oracle" ]; then
         if [ $SHELL = "/bin/ksh" ]; then
             ulimit -p 16384
             ulimit -n 65536
          else
             ulimit -u 16384 -n 65536
         fi
      fi
      [root@oracledb-01 ~]# source /etc/profile
      

      禁用使用Transparent HugePages(启用Transparent HugePages,可能会导致造成内存在运行时的延迟分配,Oracle官方建议使用标准的HugePages)

      • 查看是否启用 如果显示 [always]说明启用了

      • 禁用Transparent HugePages,在/etc/grub.conf添加如下内容

      [root@oracledb-01 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
      [always] madvise never
      [root@oracledb-01 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
      

      重新启动系统以使上述更改成为永久更改

    2、oracle安装

    2.1 基本配置

    • 创建oracle安装目录

      [root@oracledb-01 ~]# mkdir -p /data/app/
      [root@oracledb-01 ~]# chown -R oracle:oinstall /data/app/
      [root@oracledb-01 ~]# chmod -R 775 /data/app/
      
    • 配置oracle用户环境变量
      在文件/home/oracle/.bash_profile里添加下面内容

      umask 022
      export ORACLE_HOSTNAME=oracledb-01  # 修改成主机名
      export ORACLE_BASE=/data/app/oracle
      export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
      export ORACLE_SID=ORCL
      export ORACLE_UNQNAME=orcl
      export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
      export LC_ALL="en_US"
      export LANG="en_US"
      export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
      export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
      

      由于新增了环境变量,再次重启系统

    2.2 解压安装包

    [root@oracledb-01 ~]# cd linux.x64_11gR2_database_2of2/
    [root@oracledb-01 linux.x64_11gR2_database_2of2]# ls
    linux.x64_11gR2_database_1of2.zip  linux.x64_11gR2_database_2of2.zip
    [root@oracledb-01 linux.x64_11gR2_database_2of2]# unzip -q linux.x64_11gR2_database_1of2.zip -d /data
    [root@oracledb-01 linux.x64_11gR2_database_2of2]# unzip -q linux.x64_11gR2_database_2of2.zip -d /data
    [root@oracledb-01 linux.x64_11gR2_database_2of2]# mkdir -p /data/etc
    [root@oracledb-01 linux.x64_11gR2_database_2of2]# cp /data/database/response/* /data/etc/
    

    2.3 正式安装

    修改文件/data/etc/db_install.rsp中以下变量的值

    oracle.install.option=INSTALL_DB_SWONLY
    DECLINE_SECURITY_UPDATES=true
    UNIX_GROUP_NAME=oinstall
    INVENTORY_LOCATION=/data/app/oracle/inventory
    SELECTED_LANGUAGES=en,zh_CN
    ORACLE_HOSTNAME=oracledb-01  # 修改成主机名
    ORACLE_HOME=/data/app/oracle/product/11.2.0
    ORACLE_BASE=/data/app/oracle
    oracle.install.db.InstallEdition=EE
    oracle.install.db.isCustomInstall=true
    oracle.install.db.DBA_GROUP=dba
    oracle.install.db.OPER_GROUP=dba
    

    执行安装脚本

    [root@oracledb-01 ~]# su - oracle
    [oracle@oracledb-01 ~]$ cd /data/database/
    [oracle@oracledb-01 database]$ ./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq
    

    安装时可以根据安装提示查看日志

    [root@oracledb-01 ~]# tail -f /data/app/oracle/inventory/logs/installActions2020-10-31_09-40-21PM.log
    

    安装完成后会有如下提示

    You can find the log of this install session at:
     /data/app/oracle/inventory/logs/installActions2020-10-31_09-40-21PM.log
    The following configuration scripts need to be executed as the "root" user. 
    
     #!/bin/sh
     #Root scripts to run
    
    /data/app/oracle/inventory/orainstRoot.sh
    /data/app/oracle/product/11.2.0/root.sh
    To execute the configuration scripts:
             1. Open a terminal window
             2. Log in as "root"
             3. Run the scripts
             4. Return to this window and hit "Enter" key to continue
    
    Successfully Setup Software.
    

    按照上述提示进行操作,使用root用户运行脚本

    [oracle@oracledb-01 ~]$ su - root
    Password: 
    [root@oracledb-01 ~]# sh /data/app/oracle/inventory/orainstRoot.sh 
    Changing permissions of /data/app/oracle/inventory.
    Adding read,write permissions for group.
    Removing read,write,execute permissions for world.
    
    Changing groupname of /data/app/oracle/inventory to oinstall.
    The execution of the script is complete.
    [root@oracledb-01 ~]# sh /data/app/oracle/product/11.2.0/root.sh 
    Check /data/app/oracle/product/11.2.0/install/root_oracledb-01_2020-10-31_09-46-20.log for the output of root script
    

    配置监听

    [root@oracledb-01 ~]# su - oracle
    [oracle@oracledb-01 ~]$ netca /silent /responsefile /data/etc/netca.rsp
    
    Parsing command line arguments:
        Parameter "silent" = true
        Parameter "responsefile" = /data/etc/netca.rsp
    Done parsing command line arguments.
    Oracle Net Services Configuration:
    Profile configuration complete.
    Oracle Net Listener Startup:
        Running Listener Control:
          /data/app/oracle/product/11.2.0/bin/lsnrctl start LISTENER
        Listener Control complete.
        Listener started successfully.
    Listener configuration complete.
    Oracle Net Services configuration successful. The exit code is 0
    

    查看监听端口

    [oracle@oracledb-01 database]$ netstat -tnpl | grep 1521
    (Not all processes could be identified, non-owned process info
     will not be shown, you would have to be root to see it all.)
    tcp6       0      0 :::1521                 :::*                    LISTEN      6064/tnslsnr
    

    2.4 静默创建数据库

    2.4.1 编辑应答文件

    编辑应答文件/data/etc/dbca.rsp

    [GENERAL]
    RESPONSEFILE_VERSION = "11.2.0"
    OPERATION_TYPE = "createDatabase"
    [CREATEDATABASE]
    GDBNAME = "orcl"
    SID = "orcl"
    SYSPASSWORD = "oracle"
    SYSTEMPASSWORD = "oracle"
    SYSMANPASSWORD = "oracle"
    DBSNMPPASSWORD = "oracle"
    DATAFILEDESTINATION = /data/app/oracle/oradata
    RECOVERYAREADESTINATION=/data/app/oracle/fast_recovery_area
    CHARACTERSET = "AL32UTF8"  # 字符集,根据需求设置,建议前期确定好需要什么字符集,后期不建议更改
    TOTALMEMORY = "102400"  # 分配给Oracle的内存总量,根据服务器内存总量进行分配
    

    2.4.2 执行静默建库

    su - oracle
    dbca -silent -responseFile /data/etc/dbca.rsp
    

    执行时控制台输出如下

    Copying database files
    1% complete
    3% complete
    11% complete
    18% complete
    26% complete
    37% complete
    Creating and starting Oracle instance
    40% complete
    45% complete
    50% complete
    55% complete
    56% complete
    60% complete
    62% complete
    Completing Database Creation
    66% complete
    70% complete
    73% complete
    85% complete
    96% complete
    100% complete
    Look at the log file "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
    

    2.4.3 检查

    查看进程

    [oracle@oracledb-01 ~]$ ps -ef | grep ora_ | grep -v grep
    oracle     8113      1  0 12:03 ?        00:00:00 ora_pmon_orcl
    oracle     8115      1  0 12:03 ?        00:00:00 ora_vktm_orcl
    oracle     8119      1  0 12:03 ?        00:00:00 ora_gen0_orcl
    oracle     8121      1  0 12:03 ?        00:00:00 ora_diag_orcl
    oracle     8123      1  0 12:03 ?        00:00:00 ora_dbrm_orcl
    oracle     8125      1  0 12:03 ?        00:00:00 ora_psp0_orcl
    oracle     8127      1  0 12:03 ?        00:00:00 ora_dia0_orcl
    oracle     8129      1  0 12:03 ?        00:00:00 ora_mman_orcl
    oracle     8131      1  0 12:03 ?        00:00:00 ora_dbw0_orcl
    oracle     8133      1  0 12:03 ?        00:00:00 ora_lgwr_orcl
    oracle     8135      1  0 12:03 ?        00:00:00 ora_ckpt_orcl
    oracle     8137      1  0 12:03 ?        00:00:00 ora_smon_orcl
    oracle     8139      1  0 12:03 ?        00:00:00 ora_reco_orcl
    oracle     8141      1  0 12:03 ?        00:00:00 ora_mmon_orcl
    oracle     8143      1  0 12:03 ?        00:00:00 ora_mmnl_orcl
    oracle     8145      1  0 12:03 ?        00:00:00 ora_d000_orcl
    oracle     8147      1  0 12:03 ?        00:00:00 ora_s000_orcl
    oracle     8161      1  0 12:03 ?        00:00:00 ora_qmnc_orcl
    oracle     8178      1  0 12:03 ?        00:00:00 ora_cjq0_orcl
    oracle     8188      1  0 12:03 ?        00:00:00 ora_q000_orcl
    oracle     8190      1  0 12:03 ?        00:00:00 ora_q001_orcl
    

    查看监听状态

    [oracle@oracledb-01 ~]$ lsnrctl status
    
    LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 03-NOV-2020 12:06:10
    
    Copyright (c) 1991, 2009, Oracle.  All rights reserved.
    
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
    STATUS of the LISTENER
    ------------------------
    Alias                     LISTENER
    Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
    Start Date                03-NOV-2020 11:37:14
    Uptime                    0 days 0 hr. 28 min. 56 sec
    Trace Level               off
    Security                  ON: Local OS Authentication
    SNMP                      OFF
    Listener Parameter File   /data/app/oracle/product/11.2.0/network/admin/listener.ora
    Listener Log File         /data/app/oracle/diag/tnslsnr/oracledb-01/listener/alert/log.xml
    Listening Endpoints Summary...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracledb-01)(PORT=1521)))
    Services Summary...
    Service "orcl" has 1 instance(s).
      Instance "orcl", status READY, has 1 handler(s) for this service...
    Service "orclXDB" has 1 instance(s).
      Instance "orcl", status READY, has 1 handler(s) for this service...
    The command completed successfully
    

    2.5 登录数据库启动监听

    [root@oracledb-01 ~]# su - oracle
    [oracle@oracledb-01 ~]$ sqlplus / as sysdba
    SQL> startup
    ORA-01078: failure in processing system parameters
    LRM-00109: could not open parameter file '/data/app/oracle/product/11.2.0/dbs/initORCL.ora'
    

    按照提示操作

    [oracle@oracledb-01 ~]$ cp /data/app/oracle/admin/orcl/pfile/init.ora.103202012323 /data/app/oracle/product/11.2.0/dbs/initORCL.ora
    

    再次启动监听

    SQL> shutdown immediate;
    SQL> startup;
    ORACLE instance started.
    
    Total System Global Area  534462464 bytes
    Fixed Size                  2215064 bytes
    Variable Size             163578728 bytes
    Database Buffers          360710144 bytes
    Redo Buffers                7958528 bytes
    Database mounted.
    Database opened.
    

    2.6 激活scott用户(可选)

    SQL> alter user scott account unlock;
    SQL> alter user scott identified by tiger;
    SQL> select username,account_status from dba_users;
    

    3、设置开机启动

    修改/data/app/oracle/product/11.2.0/bin/dbstart

    ORACLE_HOME_LISTNER=$ORACLE_HOME
    

    修改/data/app/oracle/product/11.2.0/bin/dbshut

    ORACLE_HOME_LISTNER=$ORACLE_HOME
    

    修改vi /etc/oratab

    orcl:/data/app/oracle/product/11.2.0:Y
    

    新建服务文件/etc/rc.d/init.d/oracle

    #! /bin/bash
    # oracle: Start/Stop Oracle Database 11g R2
    #
    # chkconfig: 345 90 10
    # description: The Oracle Database is an Object-Relational Database Management System.
    #
    # processname: oracle
    . /etc/rc.d/init.d/functions
    LOCKFILE=/var/lock/subsys/oracle
    ORACLE_HOME=/data/app/oracle/product/11.2.0
    ORACLE_USER=oracle
    case "$1" in
    'start')
       if [ -f $LOCKFILE ]; then
          echo $0 already running.
          exit 1
       fi
       echo -n $"Starting Oracle Database:"
       su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
       su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
       su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
       touch $LOCKFILE
       ;;
    'stop')
       if [ ! -f $LOCKFILE ]; then
          echo $0 already stopping.
          exit 1
       fi
       echo -n $"Stopping Oracle Database:"
       su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
       su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
       su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
       rm -f $LOCKFILE
       ;;
    'restart')
       $0 stop
       $0 start
       ;;
    'status')
       if [ -f $LOCKFILE ]; then
          echo $0 started.
          else
          echo $0 stopped.
       fi
       ;;
    *)
       echo "Usage: $0 [start|stop|status]"
       exit 1
    esac
    exit 0
    

    添加执行权限和开机启动

    [root@oracledb-01 ~]# chmod +x /etc/init.d/oracle
    [root@oracledb-01 ~]# chkconfig oracle on
    [root@oracledb-01 ~]# chkconfig --list|grep oracle
    
    Note: This output shows SysV services only and does not include native
          systemd services. SysV configuration data might be overridden by native
          systemd configuration.
    
          If you want to list systemd services use 'systemctl list-unit-files'.
          To see services enabled on particular target use
          'systemctl list-dependencies [target]'.
    
    oracle          0:off   1:off   2:on    3:on    4:on    5:on    6:off
    

    修改启动相关文件的权限

    [root@oracledb-01 ~]# cd /data/app/oracle/product/11.2.0/bin/
    [root@oracledb-01 bin]# chmod 6751 oracle
    [root@oracledb-01 bin]# cd /var/tmp
    [root@oracledb-01 tmp]# chown -R oracle:oinstall .oracle
    

    关机重启测试

    reboot
    

    关机重启后登陆进入数据库后,再执行startup启动数据库。

    参考:

    https://blog.csdn.net/chenghuikai/article/details/85776622

    https://www.cnblogs.com/hftian/p/6944133.html

    https://www.cnblogs.com/xiaofeng666/p/13702197.html

  • 相关阅读:
    「SPOJ10707」Count on a tree II
    UVA 11021 /概率
    power oj/2360/Change
    POJ1613 147/思维题
    Power oj2498/DP/递推
    HDU4815/计数DP
    444A/CF
    观光公交noip<贪心>
    2014 Shanghai Invitation Contest
    POJ1734/Floyd求最小环
  • 原文地址:https://www.cnblogs.com/ssgeek/p/13957020.html
Copyright © 2011-2022 走看看