本例操作系统版本:CentOS 7.8、数据库版本:Oracle 12c(12.201)

https://oracle-base.com/articles/12c/oracle-db-12cr2-installation-on-oracle-linux-6-and-7

  1. hostname: ol7-122.localdomain
  2. hosts: 10.0.0.10 ol7-122.localdomain ol7-122
  1. # 关闭防火墙
  2. systemctl stop firewalld.service
  3. # 禁止防火墙开机启动
  4. systemctl disable firewalld.service
  5. # 查看防火墙状态
  6. systemctl status firewalld.service
  1. # 编辑文件
  2. vi /etc/selinux/config
  3. # 修改内容
  4. SELINUX=disabled

使用 yum 批量安装依赖包,若执行一遍失败则继续执行第二遍(多次执行不会出现其他问题)

  1. yum install binutils -y
  2. yum install compat-libcap1 -y
  3. yum install compat-libstdc++-33 -y
  4. yum install compat-libstdc++-33.i686 -y
  5. yum install glibc -y
  6. yum install glibc.i686 -y
  7. yum install glibc-devel -y
  8. yum install glibc-devel.i686 -y
  9. yum install ksh -y
  10. yum install libaio -y
  11. yum install libaio.i686 -y
  12. yum install libaio-devel -y
  13. yum install libaio-devel.i686 -y
  14. yum install libX11 -y
  15. yum install libX11.i686 -y
  16. yum install libXau -y
  17. yum install libXau.i686 -y
  18. yum install libXi -y
  19. yum install libXi.i686 -y
  20. yum install libXtst -y
  21. yum install libXtst.i686 -y
  22. yum install libgcc -y
  23. yum install libgcc.i686 -y
  24. yum install libstdc++ -y
  25. yum install libstdc++.i686 -y
  26. yum install libstdc++-devel -y
  27. yum install libstdc++-devel.i686 -y
  28. yum install libxcb -y
  29. yum install libxcb.i686 -y
  30. yum install make -y
  31. yum install nfs-utils -y
  32. yum install net-tools -y
  33. yum install smartmontools -y
  34. yum install sysstat -y
  35. yum install unixODBC -y
  36. yum install unixODBC-devel -y

 

检查是否安装成功(31个安装包)

  1. rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel

 

详见文章: 创建Swap

如果你操作系统原有分区都合适,这步可以忽略

  1. # 查看硬盘及分区信息(启动Disk开头的就是硬盘,Device开头的就是分区)
  2. fdisk -l
  3. # 创建分区(/dev/sdb 是硬盘,是你需要创建分区的硬盘,创建分区后会生成 /dev/sdb1,如果本来有sdb1,则会出现sdb2)
  4. fdisk /dev/sdb
  5. # 格式化新创建的分区
  6. mkfs.xfs /dev/sdb1
  7. # 将分区添加到 /etc/fstab 文件中,使之开机自动挂载(编辑保存 fstab 文件后不会立即生效)
  8. vim /etc/fstab
  9. /dev/sdb1 /u01 xfs defaults 0 0
  1. # 创建目录
  2. mkdir /u01
  3. # 重新加载文件 /etc/fstab 所有内容。该操作会忽略所有已经完成的操作,所以多次执行,只会有第一次能看到效果。
  4. mount -a
  5. df -h
  6. Filesystem Size Used Avail Use% Mounted on
  7. /dev/mapper/centos-root 20G 12G 8.7G 57% /
  8. devtmpfs 3.8G 0 3.8G 0% /dev
  9. tmpfs 3.9G 0 3.9G 0% /dev/shm
  10. tmpfs 3.9G 13M 3.8G 1% /run
  11. tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
  12. /dev/sda1 2.0G 179M 1.9G 9% /boot
  13. /dev/mapper/centos-home 10G 33M 10G 1% /home
  14. tmpfs 781M 4.0K 781M 1% /run/user/42
  15. tmpfs 781M 52K 781M 1% /run/user/0
  16. /dev/sdb 20G 33M 20G 1% /u01
  1. # 设置时区
  2. timedatectl set-timezone Asia/Shanghai
  3. # 升级系统
  4. yum clean all && yum update -y
  5. # 安装桌面环境(两个组包必须,不然安装oracle会出现卡死现象)
  6. yum groupinstall "GNOME Desktop" "Server with GUI" -y
  7. # 安装完毕设置开机启动桌面环境
  8. systemctl set-default graphical.target

 

  • Server with GUI

  • Hardware Monitoring Utilities

  • Large Systems Performance

  • Network file system client

  • Performance Tools

  • Compatibility Libraries

  • Development Tools

  1. # 创建oinstall和dba组
  2. groupadd -g 54321 oinstall
  3. groupadd -g 54322 dba
  4. groupadd -g 54323 oper
  5. # 创建oracle用户
  6. useradd -u 54321 -g oinstall -G dba,oper oracle
  7. # 设置oracle密码
  8. passwd oracle
  9. # 查看创建结果
  10. id oracle
  11. uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper)
  1. # 配置内核参数(这些参数根据你机器的配置不同,有些参数需要再次修改,在安装oralce过程中的check那一步,会给出提示,按要求逐个修改对应的推荐值即可)
  1. vi /etc/sysctl.d/98-oracle.conf
  2. fs.file-max = 6815744
  3. kernel.sem = 250 32000 100 128
  4. kernel.shmmni = 4096
  5. kernel.shmall = 1073741824
  6. kernel.shmmax = 4398046511104
  7. kernel.panic_on_oops = 1
  8. net.core.rmem_default = 262144
  9. net.core.rmem_max = 4194304
  10. net.core.wmem_default = 262144
  11. net.core.wmem_max = 1048576
  12. net.ipv4.conf.all.rp_filter = 2
  13. net.ipv4.conf.default.rp_filter = 2
  14. fs.aio-max-nr = 1048576
  15. net.ipv4.ip_local_port_range = 9000 65500
  16. /sbin/sysctl -p /etc/sysctl.d/98-oracle.conf

  1. # 配置ulimit参数
  2. vi /etc/security/limits.d/oracle-database-server-12cR2-preinstall.conf
  3. oracle soft nofile 1024
  4. oracle hard nofile 65536
  5. oracle soft nproc 16384
  6. oracle hard nproc 16384
  7. oracle soft stack 10240
  8. oracle hard stack 32768
  9. oracle hard memlock 134217728
  10. oracle soft memlock 134217728
  1. # 设置上面创建的数据目录权限
  2. mkdir -p /u01/app/oracle/product/12.2.0.1/db_1
  3. chown -R oracle:oinstall /u01
  4. chmod -R 775 /u01
  1. reboot

可以在线下载 可以通过拷贝方式 可以在同网段电脑上开启ftp或者http服务后,在服务上 wget 下载 官方下载地址: https://www.oracle.com/database/technologies/oracle-database-software-downloads.html

  1. mkdir /home/oracle/scripts
  2. cat > /home/oracle/scripts/setEnv.sh <<EOF
  3. # Oracle Settings
  4. export TMP=/tmp
  5. export TMPDIR=\$TMP
  6. export ORACLE_HOSTNAME=ol7-122.localdomain
  7. export ORACLE_UNQNAME=cdb1
  8. export ORACLE_BASE=/u01/app/oracle
  9. export ORACLE_HOME=\$ORACLE_BASE/product/12.2.0.1/db_1
  10. export ORACLE_SID=cdb1
  11. export PATH=/usr/sbin:/usr/local/bin:\$PATH
  12. export PATH=\$ORACLE_HOME/bin:\$PATH
  13. export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
  14. export CLASSPATH=\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
  15. EOF
  16. echo ". /home/oracle/scripts/setEnv.sh" >> /home/oracle/.bash_profile
  17. # 执行命令使环境变量生效
  18. source ~/.bash_profile

假设 oracle 文件已经下载到 /opt/linuxx64_12201_database.zip 使用图形化安装方式,你可以直接在原服务器上连接显示器安装,或者使用其他 ssh 远程安装(不带图形化的静默安找找度娘)。 如果使用 Xshell 这种工具安装(需要开启X11,可以参考:Xshell 显示图形化界面

  1. su - oracle
  2. cd /opt/
  3. unzip linuxx64_12201_database.zip
  4. cd database/
  5. ./runInstaller

详细安装步骤如下:

 

 

 

 

 

编辑“ /etc/oratab”文件,将每个实例的重新启动标志设置为“ Y”。

  1. cdb1:/u01/app/oracle/product/12.2.0.1/db_1:Y
  1. cat > /home/oracle/scripts/start_all.sh <<EOF
  2. #!/bin/bash
  3. . /home/oracle/scripts/setEnv.sh
  4. export ORAENV_ASK=NO
  5. . oraenv
  6. export ORAENV_ASK=YES
  7. dbstart \$ORACLE_HOME
  8. EOF
  9. cat > /home/oracle/scripts/stop_all.sh <<EOF
  10. #!/bin/bash
  11. . /home/oracle/scripts/setEnv.sh
  12. export ORAENV_ASK=NO
  13. . oraenv
  14. export ORAENV_ASK=YES
  15. dbshut \$ORACLE_HOME
  16. EOF
  17. chown -R oracle.oinstall /home/oracle/scripts
  18. chmod u+x /home/oracle/scripts/*.sh
  1. ~/scripts/start_all.sh # 启动脚本
  2. ~/scripts/stop_all.sh # 停止脚本
  3. # 使用 telnet 测试服务端口
  4. telnet 127.0.0.1 1521
  5. # 使用 sqlplus 登录数据库
  6. sqlplus /nolog
  7. conn / as sysdba

创建一个新服务以自动启动/停止Oracle数据库。这是假定Oracle数据库不使用Oracle重新启动和“start_all.sh”和“stop_all.sh”脚本已经存在

创建名为“ /lib/systemd/system/dbora.service”的服务文件。

  1. vi /lib/systemd/system/dbora.service
  2. [Unit]
  3. Description=The Oracle Database Service
  4. After=syslog.target network.target
  5. [Service]
  6. # systemd ignores PAM limits, so set any necessary limits in the service.
  7. # Not really a bug, but a feature.
  8. # https://bugzilla.redhat.com/show_bug.cgi?id=754285
  9. LimitMEMLOCK=infinity
  10. LimitNOFILE=65535
  11. #Type=simple
  12. # idle: similar to simple, the actual execution of the service binary is delayed
  13. # until all jobs are finished, which avoids mixing the status output with shell output of services.
  14. RemainAfterExit=yes
  15. User=oracle
  16. Group=oinstall
  17. Restart=no
  18. ExecStart=/bin/bash -c \'/home/oracle/scripts/start_all.sh\'
  19. ExecStop=/bin/bash -c \'/home/oracle/scripts/stop_all.sh\'
  20. [Install]
  21. WantedBy=multi-user.target
  1.  
  1. systemctl daemon-reload
  2. systemctl stop dbora.service
  3. systemctl start dbora.service
  4. systemctl enable dbora.service

至此,Oracle 数据库安装结束。

版权声明:本文为renato原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/renato/p/13710114.html