Oracle Database,又名Oracle RDBMS,或简称Oracle。是甲骨文公司的一款关系数据库管理系统。它是在数据库领域一直处于领先地位的产品。可以说Oracle数据库系统是目前世界上流行的关系数据库管理系统,系统可移植性好、使用方便、功能强,适用于各类大、中、小、微机环境。它是一种高效率、可靠性好的适应高吞吐量的数据库解决方案。

安装前准备

  • 相关文件准备(超链接为下载地址)

    • 已安装好 CentOS 7 最小化系统,并配置好了网络
    • 下载 Oracle 12c 数据库企业版,2个压缩包哦
  • SELinux设置为enforcing模式

    # 查看 SELinux 状态
    [root@centos7 ~]# sestatus
    SELinux status:                 enabled
    SELinuxfs mount:                /sys/fs/selinux
    SELinux root directory:         /etc/selinux
    Loaded policy name:             targeted
    Current mode:                   enforcing
    Mode from config file:          enforcing
    Policy MLS status:              enabled
    Policy deny_unknown status:     allowed
    Max kernel policy version:      28
    
    # 如果不是 enforcing 模式,则运行以下命令并重启即可生效。
    sed -i 's/SELINUX.*/SELINUX=enforcing/' /etc/selinux/config
  • 为安全性考虑,启动防火墙服务(如果不启动可以跳过后面的防火墙配置)

    systemctl start firewalld # 启动防火墙
    firewall-cmd --state # 查看当前防火墙状态
  • 更新CentOS 7yum源为国内源,以下源中任选一种即可,当然您一股脑的将下面命令全部运行也并没有什么问题。

    # 备份并删除现有源
    cat /etc/yum.repos.d/* > /etc/yum.repos.d/repo.bak 
    rm -rf /etc/yum.repos.d/*.repo
    # 配置阿里源(2选1)
    wget http://mirrors.aliyun.com/repo/Centos-7.repo -O /etc/yum.repos.d/CentOS-aliyun.repo
    # 配置网易163源(2选1)
    wget http://mirrors.163.com/.help/CentOS7-Base-163.repo -O /etc/yum.repos.d/CentOS-163.repo
    # 最后使源生效
    yum clean all && yum makecache
  • CentOS系统更新至最新组件

    yum update -y

安装步骤

  • Oracle数据库创建所须的操作系统用户及群组

    groupadd oinstall
    groupadd dba
    useradd -g oinstall -G dba oracle
    passwd oracle
    groups oracle # 查看用户所属的组
  • /etc/sysctl.conf加入下列内核参数

      fs.aio-max-nr = 1048576
      ​fs.file-max = 6815744
      ​kernel.shmall = 2097152
      ​kernel.shmmax = 1987162112
      ​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 = 1048586
    
  • 检查并使修改的配置文件生效

    sysctl -p
    sysctl -a
  • 修改系统默认的对oracle用户一些限制,以下命令没有反馈,请勿重复运行

    cat >> /etc/security/limits.conf <<-EOF
    oracle soft nproc 2047
    oracle hard nproc 16384
    oracle soft nofile 1024
    oracle hard nofile 65536
    oracle soft stack 10240
    EOF
  • 使用xftp工具或者scp命令将Oracle数据库文件上传到虚拟机的/tmp目录下
  • Oracle数据库安装文件解压至/stage目录,并修改/stage目录权限,解压文件名根据实际情况。

    mkdir /stage
    yum install -y zip unzip
    unzip /tmp/linuxamd64_12102_database_1of2.zip -d /stage/
    unzip /tmp/linuxamd64_12102_database_2of2.zip -d /stage/
    chown -R oracle:oinstall /stage/
  • Oracle创建/u01作为安装目录,以及创建/u02作为数据库文件目录

    mkdir /u01
    mkdir /u02
    chown -R oracle:oinstall /u01
    chown -R oracle:oinstall /u02
    chmod -R 775 /u01
    chmod -R 775 /u02
    chmod g+s /u01 # g+s权限意为任何用户在此目录下创建的文件都具有和该目录所属的组相同的组
    chmod g+s /u02
  • 安装所需的组件

    yum install -y binutils.x86_64 compat-libcap1.x86_64 gcc.x86_64 gcc-c++.x86_64 glibc.i686 glibc.x86_64 glibc-devel.i686 glibc-devel.x86_64 ksh compat-libstdc++-33 libaio.i686 libaio.x86_64 libaio-devel.i686 libaio-devel.x86_64 libgcc.i686 libgcc.x86_64 libstdc++.i686 libstdc++.x86_64 libstdc++-devel.i686 libstdc++-devel.x86_64 libXi.i686 libXi.x86_64 libXtst.i686 libXtst.x86_64 make.x86_64 sysstat.x86_64
  • 安装X Window System组件

    yum groupinstall -y "X Window System"
  • 由于Oracle安装程序需要用到图形化界面,你可通过以下两个办法来进行

    • 找任意一台带有图形界面的LinuxMac系统的电脑远程登陆,Mac系统我猜想能用这个办法,而未测试

      ssh -X oracle@ipaddr # 替换 ipaddr 为你的ip地址
    • 利用一台拥有SSH客户端(PuTTY)X-Windows图形用户接口(Xming)Windows系统,可以参考这里

      • 首先下载 PuttyXming 工具
      • 启动XmingPutty,连接Putty前请先按照如下图所示进行设置
        putty
      • 测试窗口服务能否正常运行

        yum install xeyes -y 
        xeyes 
  • 请采用上述的方案登录为oracle用户,然后执行Oracle安装程序

    [oracle@centos7 ~]$ /stage/database/runInstaller
    Starting Oracle Universal Installer...

Oracle 安装程序画面

  1. 安全性更新
    假若你不想接收来自Oracle支持部的电邮,请取消勾选该项目并按Next,在新打开的窗口按YES
  2. 安装选项
    选择Create and configure a database并按Next
  3. 系统级别
    选择Desktop Class进行缺省的简便Oracle数据库安装。
  4. 典型安装
    Typical Install Configuration画面,设置以下功能。另外请设置合适的Database edition(数据库版本)及Character set(字符集,最好为UTF-8)。为数据库的管理员设定密码,最后请取消勾选Create as Container database选项。
VariableValue
Oracle base/u01/app/oracle
Software location/u01/app/oracle/product/12.1.0/dbhome_1
Database file location/u02
Global database nameorcl.example.com
  1. 选择日志目录
    选择/u01/app/oraInventory这个目录并点击下一步。
  2. 检查后点击安装
  3. 执行设置脚本
    因为有些安装命令需要root用户权限,当询问窗口出现时,请登录用户root并执行以下两个脚本:

    [root@centos7 ~]# /u01/app/oraInventory/orainstRoot.sh
    Changing permissions of /u01/app/oraInventory.
    Adding read,write permissions for group.
    Removing read,write,execute permissions for world.
    Changing groupname of /u01/app/oraInventory to oinstall.
    The execution of the script is complete.
    
    [root@centos7 ~]# /u01/app/oracle/product/12.1.0/dbhome_1/root.sh
    Performing root user operation.
    The following environment variables are set as:
     ORACLE_OWNER= oracle
     ORACLE_HOME=  /u01/app/oracle/product/12.1.0/dbhome_1
    Enter the full pathname of the local bin directory: [/usr/local/bin]: <PRESS ENTER>
    Copying dbhome to /usr/local/bin ...
    Copying oraenv to /usr/local/bin ...
    Copying coraenv to /usr/local/bin ...
    Creating /etc/oratab file...
    Entries will be added to the /etc/oratab file as needed by
    Database Configuration Assistant when a database is created
    Finished running generic part of root script.
    Now product-specific root actions will be performed.
    You can follow the installation in a separated window.
  4. 顺利完成安装
    安装过程非常慢,请耐性等待直至安装完成,如若遇到问题,请问度娘或者谷歌。

安装后的任务

防火墙

  • 登陆root用户并执行以下命令来打开Oracle服务的防火墙

    firewall-cmd --zone=public --add-port=1521/tcp --add-port=5500/tcp --add-port=5520/tcp --add-port=3938/tcp --permanent
    firewall-cmd --reload
    firewall-cmd --list-ports # 查看已开通的防火墙端口

Oracle 工作环境

  • 登录为oracle用户并在/home/oracle/.bash_profile文件中添加以下信息:

      TMPDIR=$TMP; export TMPDIR
      ​ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
      ​ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1; export ORACLE_HOME
      ​ORACLE_SID=orcl; export ORACLE_SID
      ​PATH=$ORACLE_HOME/bin:$PATH; export PATH
      ​LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/lib64; export LD_LIBRARY_PATH
      ​CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
    
  • 运行以下命令使环境变量生效
source ~/.bash_profile

登陆数据库

  • 最后请登陆数据库:

    [oracle@centos7 ~]$ sqlplus system@orcl
    ... output omitted ...
    Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
    SQL>
最后修改:2022 年 05 月 07 日
如果觉得我的文章对你有用,请我喝杯咖啡吧☕️~