Oracle11g静默安装

CentOS7 静默安装Oracle11g

不知道爬了多少坑,以至于到最后装好之后整个虚拟机备份…..找到一篇文章可以成功安装并一次成功,录之…

环境

系统: CentOS 7.x (64位)
Oracle: linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip
IP: 192.168.88.129

1. 准备

  • 关闭selinux

    1
    [root@localhost ~]# vi /etc/selinux/config

    修改SELINUX=disabled

  • 执行

    1
    [root@localhost ~]# setenforce 0
  • 关闭防火墙

    1
    2
    3
    4

    [root@localhost ~]# systemctl stop firewalld.service
    [root@localhost ~]# systemctl disable firewalld.service
    [root@localhost ~]# systemctl stop iptables //如果有iptables也要关闭
  • 安装依赖包

    1
    2
    3
    4
    [root@localhost ~]# wget http://public-yum.oracle.com/public-yum-ol7.repo -P /etc/yum.repos.d/
    [root@localhost ~]# wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol7 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle

    [root@localhost ~]# yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers kernel-headers ksh libaio libaio-devel libgcc libgomp libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pcre-devel unzip
  • 更改hostname

    1
    2
    3
    4
    5
    6
    [root@localhost ~]# vi /etc/hostname
    CentOS7
    [root@localhost ~]# vi /etc/hosts
    127.0.0.1 centos localhost localhost.localdomain localhost4localhost4.localdomain4
    ::1 centos localhost localhost.localdomain localhost6localhost6.localdomain6
    192.168.88.129 CentOS7
  • 添加安装用户和用户组

    1
    2
    3
    4
    [root@CentOS ~]# groupadd oinstall
    [root@CentOS ~]# groupadd dba
    [root@CentOS ~]# useradd -g oinstall -G dba oracle
    [root@CentOS ~]# passwd oracle
  • 如显示类似以下信息则表示添加用户和用户组成功

1
2
[root@CentOS ~]# id oracle
uid=1000(oracle) gid=1000(oinstall) groups=1000(oinstall),1001(dba)
  • 修改内核参数配置文件
1
[root@CentOS ~]# vi /etc/sysctl.conf
  • 添加以下内容:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    fs.aio-max-nr = 1048576
    fs.file-max = 6815744
    kernel.shmall = 2097152
    kernel.shmmax = 1073741824
    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

其中kernel.shmmax = 1073741824为本机物理内存(2G)的一半,单位为byte.

  • 生效

    1
    [root@CentOS ~]# sysctl -p
  • 修改用户的限制文件

    1
    [root@CentOS ~]# vim /etc/security/limits.conf
  • 添加以下内容:

    1
    2
    3
    4
    5
    oracle           soft    nproc           2047
    oracle hard nproc 16384
    oracle soft nofile 1024
    oracle hard nofile 65536
    oracle soft stack 10240
  • 修改/etc/pam.d/login文件

    1
    [root@CentOS ~]# vim /etc/pam.d/login
  • 添加以下内容:

    1
    2
    session required  /lib64/security/pam_limits.so
    session required pam_limits.so
  • 修改/etc/profile文件

    1
    [root@CentOS ~]# vim /etc/profile
  • 添加以下内容:

    1
    2
    3
    4
    5
    6
    7
    8
    if [ $USER = "oracle" ]; then
    if [ $SHELL = "/bin/ksh" ]; then
    ulimit -p 16384
    ulimit -n 65536
    else
    ulimit -u 16384 -n 65536
    fi
    fi
  • 生效:

    1
    [root@CentOS ~]# source /etc/profile
  • 创建安装目录和设置文件权限

    1
    2
    3
    4
    5
    6
    7
    [root@CentOS ~]# mkdir -p /data/oracle/oraclesetup
    [root@CentOS ~]# mkdir -p /data/oracle/product/11.2.0
    [root@CentOS ~]# mkdir /data/oracle/oradata
    [root@CentOS ~]# mkdir /data/oracle/inventory
    [root@centos ~]# mkdir /data/oracle/fast_recovery_area

    [root@CentOS ~]# cd /data/oracle/oraclesetup
  • 上传文件 linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.ziporaclesetup目录下 解压并更改目录权限

    1
    2
    3
    [root@CentOS oraclesetup]# unzip -o linux.x64_11gR2_database_1of2.zip && unzip -o linux.x64_11gR2_database_2of2.zip
    [root@CentOS ~]# chown -R oracle:oinstall /data/oracle
    [root@CentOS ~]# chmod -R 775 /data/oracle
  • 设置oracle用户环境变量

    1
    2
    [root@CentOS ~]# su - oracle
    [oracle@CentOS ~]$ vi .bash_profile

    ps:切换用户时切记要加”-“,加-会拥有目标用户的环境变量,不加”-“则没有.

  • 添加如下内容:

    1
    2
    3
    4
    5
    6
    7
    ORACLE_BASE=/data/oracle
    ORACLE_HOME=$ORACLE_BASE/product/11.2.0
    ORACLE_SID=orcl
    PATH=$PATH:$ORACLE_HOME/bin
    export ORACLE_BASE
    export ORACLE_HOME
    export PATH

    根据自己安装目录适当调整

  • 使之生效:

    1
    [oracle@centos ~]$ source .bash_profile
  • 编辑静默安装响应文件

    1
    2
    3
    [oracle@centos ~]$ cp -R /data/oracle/oraclesetup/database/response/ .
    [oracle@centos ~]$ cd response/
    [oracle@centos response]$ vim db_install.rsp
  • 需要设置的选项如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    oracle.install.option=INSTALL_DB_SWONLY
    ORACLE_HOSTNAME=centos
    UNIX_GROUP_NAME=oinstall
    INVENTORY_LOCATION=/data/oracle/inventory
    SELECTED_LANGUAGES=en,zh_CN
    ORACLE_HOME=/data/oracle/product/11.2.0
    ORACLE_BASE=/data/oracle
    oracle.install.db.InstallEdition=EE
    oracle.install.db.DBA_GROUP=dba
    oracle.install.db.OPER_GROUP=dba
    DECLINE_SECURITY_UPDATES=true

2. 静默安装oracle

  • 执行

    1
    2
    [oracle@centos ~]$ cd /data/oracle/oraclesetup/database/
    [oracle@centos database]$ ./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq

    ps:Oracle开始在后台静默安装,如果提示Successfully则表示安装成功

  • 按照要求执行脚本,重新开一个终端,以root用户登录,执行脚本

    1
    2
    [root@centos ~]# sh /data/oracle/inventory/orainstRoot.sh
    [root@centos ~]# sh /data/oracle/product/11.2.0/root.sh

    ps:请根据你们自己的提示执行脚本.

  • 以静默方式配置监听

    1
    [oracle@centos ~]$ netca /silent /responsefile /home/oracle/response/netca.rsp
  • 成功后,通过netstat命令可以查看1521端口正在监听

    1
    2
    [oracle@centos ~]$ netstat -tnulp | grep 1521
    tcp6 0 0 :::1521 :::* LISTEN 13816/tnslsnr
  • 以静默方式建立新库,同时也建立一个对应的实例

    1
    [oracle@centos ~]$ vim /home/oracle/response/dbca.rsp
  • 设置以下参数:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    GDBNAME = "orcl"
    SID = "orcl"
    SYSPASSWORD = "oracle"
    SYSTEMPASSWORD = "oracle"
    SYSMANPASSWORD = "oracle"
    DBSNMPPASSWORD = "oracle"
    DATAFILEDESTINATION =/data/oracle/oradata
    RECOVERYAREADESTINATION=/data/oracle/fast_recovery_area
    CHARACTERSET = "AL32UTF8"
    TOTALMEMORY = "1638"

    ps:其中TOTALMEMORY = “1638”为1638MB,一般设置为物理内存的80%

  • 进行静默配置

    1
    [oracle@centos ~]$ dbca -silent -responseFile /home/oracle/response/dbca.rsp
  • 建库后进行实例进程检查

    1
    [oracle@centos ~]$ ps -ef | grep ora_ | grep -v grep
  • 查看监听状态

    1
    [oracle@centos ~]$ lsnrctl status
  • 登录

    1
    [oracle@centos ~]$ sqlplus / as sysdba
  • 查看实例状态

    1
    SQL> select status from v$instance;

如显示

1
2
3
STATUS
------------
OPEN

则表示实例是启动状态

  • 查看数据库编码

    1
    SQL> select userenv('language') from dual;
    • 查看数据库版本
      1
      SQL> select * from v$version;
  1. oracle开机自启动设置
  • 执行

    1
    [oracle@centos ~]$ vi /data/oracle/product/11.2.0/bin/dbstart
  • ORACLE_HOME_LISTNER=$1修改为:

    1
    ORACLE_HOME_LISTNER=$ORACLE_HOME
  • 执行

    1
    [oracle@centos ~]$ vi /data/oracle/product/11.2.0/bin/dbshut
  • ORACLE_HOME_LISTNER=$1修改为:

    1
    ORACLE_HOME_LISTNER=$ORACLE_HOME
  • 修改/etc/oratab文件,执行

    1
    [oracle@centos ~]$ vi /etc/oratab
  • orcl:/data/oracle/product/11.2.0:N修改为:

    1
    orcl:/data/oracle/product/11.2.0:Y
  • 输入dbshut和dbstart测试

    1
    [oracle@centos ~]$ dbshut
  • Oracle监听停止,进程消失

1
[oracle@centos ~]$ dbstart
  • Oracle监听启动,进程启动

  • 切换到root账户建立自启动脚本

    1
    2
    [oracle@centos ~]$ su -
    [root@centos ~]# vi /etc/rc.d/init.d/oracle
  • 添加以下内容(有些值如ORACLE_HOME和ORACLE_USER等根据实际情况可以修改):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    #!/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/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
  • 执行

1
2
chmod +x /etc/init.d/oracle
chkconfig oracle on

Add 2018/12/17

Oracle 11g中有个新特性:新增了一个参数“deferred_segment_creation”含义是段延迟创建,默认是true。用exp命令默认不会导出空表,所以需要在SQL/PLUS执行

SQL>alter system set deferred_segment_creation=false;

ps:参考以下文章
https://blog.slogra.com/post-712.html
http://blog.51cto.com/canonind/1883066
http://www.jianshu.com/p/03f0a0e826e0
http://blog.51cto.com/meiling/1651395
http://kyle-ming.blogspot.com/2015/04/centos-7-oracle-11g.html

作者

Heng.Wang

发布于

2018-12-14

更新于

2023-09-20

许可协议

CC BY-NC-SA 4.0

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×