Linux下安装Oracle12C详解
本例操作系统版本:CentOS 7.8、数据库版本:Oracle 12c(12.201)
https://oracle-base.com/articles/12c/oracle-db-12cr2-installation-on-oracle-linux-6-and-7
安装步骤如下分解:
- hostname: ol7-122.localdomain
- hosts: 10.0.0.10 ol7-122.localdomain ol7-122
1.关闭防火墙,禁止防火墙开机自启
- # 关闭防火墙
- systemctl stop firewalld.service
- # 禁止防火墙开机启动
- systemctl disable firewalld.service
- # 查看防火墙状态
- systemctl status firewalld.service
2.关闭selinux
- # 编辑文件
- vi /etc/selinux/config
- # 修改内容
- SELINUX=disabled
3.yum安装必要安装包
使用 yum 批量安装依赖包,若执行一遍失败则继续执行第二遍(多次执行不会出现其他问题)
- yum install binutils -y
- yum install compat-libcap1 -y
- yum install compat-libstdc++-33 -y
- yum install compat-libstdc++-33.i686 -y
- yum install glibc -y
- yum install glibc.i686 -y
- yum install glibc-devel -y
- yum install glibc-devel.i686 -y
- yum install ksh -y
- yum install libaio -y
- yum install libaio.i686 -y
- yum install libaio-devel -y
- yum install libaio-devel.i686 -y
- yum install libX11 -y
- yum install libX11.i686 -y
- yum install libXau -y
- yum install libXau.i686 -y
- yum install libXi -y
- yum install libXi.i686 -y
- yum install libXtst -y
- yum install libXtst.i686 -y
- yum install libgcc -y
- yum install libgcc.i686 -y
- yum install libstdc++ -y
- yum install libstdc++.i686 -y
- yum install libstdc++-devel -y
- yum install libstdc++-devel.i686 -y
- yum install libxcb -y
- yum install libxcb.i686 -y
- yum install make -y
- yum install nfs-utils -y
- yum install net-tools -y
- yum install smartmontools -y
- yum install sysstat -y
- yum install unixODBC -y
- yum install unixODBC-devel -y
检查是否安装成功(31个安装包)
- 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
4.创建 swap
详见文章:
5.创建 oracle 分区(可选)
如果你操作系统原有分区都合适,这步可以忽略
- # 查看硬盘及分区信息(启动Disk开头的就是硬盘,Device开头的就是分区)
- fdisk -l
- # 创建分区(/dev/sdb 是硬盘,是你需要创建分区的硬盘,创建分区后会生成 /dev/sdb1,如果本来有sdb1,则会出现sdb2)
- fdisk /dev/sdb
- # 格式化新创建的分区
- mkfs.xfs /dev/sdb1
- # 将分区添加到 /etc/fstab 文件中,使之开机自动挂载(编辑保存 fstab 文件后不会立即生效)
- vim /etc/fstab
- /dev/sdb1 /u01 xfs defaults 0 0
6.创建 oracle data 目录(同第5步可选)
- # 创建目录
- mkdir /u01
- # 重新加载文件 /etc/fstab 所有内容。该操作会忽略所有已经完成的操作,所以多次执行,只会有第一次能看到效果。
- mount -a
-
- df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/centos-root 20G 12G 8.7G 57% /
- devtmpfs 3.8G 0 3.8G 0% /dev
- tmpfs 3.9G 0 3.9G 0% /dev/shm
- tmpfs 3.9G 13M 3.8G 1% /run
- tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
- /dev/sda1 2.0G 179M 1.9G 9% /boot
- /dev/mapper/centos-home 10G 33M 10G 1% /home
- tmpfs 781M 4.0K 781M 1% /run/user/42
- tmpfs 781M 52K 781M 1% /run/user/0
- /dev/sdb 20G 33M 20G 1% /u01
7.设置时区、升级系统、安装桌面环境
方式一:针对最小化安装的系统
- # 设置时区
- timedatectl set-timezone Asia/Shanghai
- # 升级系统
- yum clean all && yum update -y
- # 安装桌面环境(两个组包必须,不然安装oracle会出现卡死现象)
- yum groupinstall "GNOME Desktop" "Server with GUI" -y
- # 安装完毕设置开机启动桌面环境
- systemctl set-default graphical.target
方式2 : 预装系统时勾选桌面环境功能
-
Server with GUI
-
Hardware Monitoring Utilities
-
Large Systems Performance
-
Network file system client
-
Performance Tools
-
Compatibility Libraries
-
Development Tools
8.创建oracle用户与用户组
- # 创建oinstall和dba组
- groupadd -g 54321 oinstall
- groupadd -g 54322 dba
- groupadd -g 54323 oper
- # 创建oracle用户
- useradd -u 54321 -g oinstall -G dba,oper oracle
- # 设置oracle密码
- passwd oracle
- # 查看创建结果
- id oracle
- uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper)
9.参数配置
- # 配置内核参数(这些参数根据你机器的配置不同,有些参数需要再次修改,在安装oralce过程中的check那一步,会给出提示,按要求逐个修改对应的推荐值即可)
- vi /etc/sysctl.d/98-oracle.conf
- fs.file-max = 6815744
- kernel.sem = 250 32000 100 128
- kernel.shmmni = 4096
- kernel.shmall = 1073741824
- kernel.shmmax = 4398046511104
- kernel.panic_on_oops = 1
- net.core.rmem_default = 262144
- net.core.rmem_max = 4194304
- net.core.wmem_default = 262144
- net.core.wmem_max = 1048576
- net.ipv4.conf.all.rp_filter = 2
- net.ipv4.conf.default.rp_filter = 2
- fs.aio-max-nr = 1048576
- net.ipv4.ip_local_port_range = 9000 65500
-
- /sbin/sysctl -p /etc/sysctl.d/98-oracle.conf
-
- # 配置ulimit参数
- vi /etc/security/limits.d/oracle-database-server-12cR2-preinstall.conf
- oracle soft nofile 1024
- oracle hard nofile 65536
- oracle soft nproc 16384
- oracle hard nproc 16384
- oracle soft stack 10240
- oracle hard stack 32768
- oracle hard memlock 134217728
- oracle soft memlock 134217728
- # 设置上面创建的数据目录权限
- mkdir -p /u01/app/oracle/product/12.2.0.1/db_1
- chown -R oracle:oinstall /u01
- chmod -R 775 /u01
10.重启服务器
- reboot
11.下载或拷贝oracle文件
可以在线下载 可以通过拷贝方式 可以在同网段电脑上开启ftp或者http服务后,在服务上 wget 下载 官方下载地址: https://www.oracle.com/database/technologies/oracle-database-software-downloads.html
12.配置环境变量
- mkdir /home/oracle/scripts
-
- cat > /home/oracle/scripts/setEnv.sh <<EOF
- # Oracle Settings
- export TMP=/tmp
- export TMPDIR=\$TMP
-
- export ORACLE_HOSTNAME=ol7-122.localdomain
- export ORACLE_UNQNAME=cdb1
- export ORACLE_BASE=/u01/app/oracle
- export ORACLE_HOME=\$ORACLE_BASE/product/12.2.0.1/db_1
- export ORACLE_SID=cdb1
-
- export PATH=/usr/sbin:/usr/local/bin:\$PATH
- export PATH=\$ORACLE_HOME/bin:\$PATH
-
- export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
- export CLASSPATH=\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
- EOF
-
- echo ". /home/oracle/scripts/setEnv.sh" >> /home/oracle/.bash_profile
- # 执行命令使环境变量生效
- source ~/.bash_profile
13.解压并开始安装
假设 oracle 文件已经下载到 /opt/linuxx64_12201_database.zip
使用图形化安装方式,你可以直接在原服务器上连接显示器安装,或者使用其他 ssh 远程安装(不带图形化的静默安找找度娘)。 如果使用 Xshell 这种工具安装(需要开启X11,可以参考:
- su - oracle
- cd /opt/
- unzip linuxx64_12201_database.zip
- cd database/
- ./runInstaller
详细安装步骤如下:
安装后
编辑“ /etc/oratab”文件,将每个实例的重新启动标志设置为“ Y”。
- cdb1:/u01/app/oracle/product/12.2.0.1/db_1:Y
14.创建启停脚本
- cat > /home/oracle/scripts/start_all.sh <<EOF
- #!/bin/bash
- . /home/oracle/scripts/setEnv.sh
-
- export ORAENV_ASK=NO
- . oraenv
- export ORAENV_ASK=YES
-
- dbstart \$ORACLE_HOME
- EOF
-
-
- cat > /home/oracle/scripts/stop_all.sh <<EOF
- #!/bin/bash
- . /home/oracle/scripts/setEnv.sh
-
- export ORAENV_ASK=NO
- . oraenv
- export ORAENV_ASK=YES
-
- dbshut \$ORACLE_HOME
- EOF
-
- chown -R oracle.oinstall /home/oracle/scripts
- chmod u+x /home/oracle/scripts/*.sh
15.启动并测试服务
- ~/scripts/start_all.sh # 启动脚本
- ~/scripts/stop_all.sh # 停止脚本
-
- # 使用 telnet 测试服务端口
- telnet 127.0.0.1 1521
-
- # 使用 sqlplus 登录数据库
- sqlplus /nolog
- conn / as sysdba
16.创建Linux服务
创建一个新服务以自动启动/停止Oracle数据库。这是假定Oracle数据库不使用Oracle重新启动和“start_all.sh”和“stop_all.sh”脚本已经存在
创建名为“ /lib/systemd/system/dbora.service”的服务文件。
- vi /lib/systemd/system/dbora.service
- [Unit]
- Description=The Oracle Database Service
- After=syslog.target network.target
-
- [Service]
- # systemd ignores PAM limits, so set any necessary limits in the service.
- # Not really a bug, but a feature.
- # https://bugzilla.redhat.com/show_bug.cgi?id=754285
- LimitMEMLOCK=infinity
- LimitNOFILE=65535
-
- #Type=simple
- # idle: similar to simple, the actual execution of the service binary is delayed
- # until all jobs are finished, which avoids mixing the status output with shell output of services.
- RemainAfterExit=yes
- User=oracle
- Group=oinstall
- Restart=no
- ExecStart=/bin/bash -c \'/home/oracle/scripts/start_all.sh\'
- ExecStop=/bin/bash -c \'/home/oracle/scripts/stop_all.sh\'
-
- [Install]
- WantedBy=multi-user.target
-
- systemctl daemon-reload
- systemctl stop dbora.service
- systemctl start dbora.service
- systemctl enable dbora.service