本帖最后由 傅宣铭 于 2020-5-27 18:03 编辑
Install Database
This document was created by Fu Xuanming in 2020, thanks for your reading
ORACLE 数据库的单点结构
ORACLE 数据库的单点结构示意如下
ORACLE Database Host with Single Environment (Red Hat Enterprise Linux 7.6)
│
├────ORACLE Database ASMCA
├────ORACLE Database Listener
│
├────ORACLE Database Instance (SID=spring; EM Express=5500)─────ORACLE Database (Filesystem)
├────ORACLE Database Instance (SID=summer; EM Express=5501) ORACLE Database (Filesystem)
├────ORACLE Database Instance (SID=auttum; EM Express=5502)─────────┐
└────ORACLE Database Instance (SID=winter; EM Express=5503)─────ORACLE Database (ASM Storage)
在以上单点示意图中, 请注意:
• ORACLE 数据库主机可以使用 RHEL / CentOS / ORACLE Linux 等多种 Linux 发行版本作为操作系统, 其中官方推荐 ORACLE Linux
• ORACLE 数据库主机可以选择性的安装 AMS 底层组件和 Grid 软件, 从而使用 ASMCA 工具制作网格化存储磁盘组
• ORACLE 数据库主机应具有监听器, 用于接受数据库实例和服务的注册请求, 以及网络连接请求
• ORACLE 数据库主机应运行有带有唯一 SID 标识的数据库实例, 且数据库实例带有 Eenterprise Manager Express 管理工具
• ORACLE 数据库主机上可以有若干数据库, 这些数据库可以被挂载到数据库实例上
• ORACLE 数据库主机的数据库可以使用网格形态的 ASM 作为存储介质, 也可以使用文件系统作为存储介质
ORACLE 数据库的环境搭建演示
资源准备清单如下
:: database host: 4 核心 | 8GB 内存 | 8GB 交换空间 | 300GB 存储 | 172.16.0.201 (database.boat.com)
:: /srv/kmod-oracleasm-2.0.8-26.0.1.el7.x86_64.rpm
:: /srv/oracleasmlib-2.0.12-1.el7.x86_64.rpm
:: /srv/oracleasm-support-2.1.11-2.el7.x86_64.rpm
:: /srv/linuxamd64_12102_grid_1of2.zip
:: /srv/linuxamd64_12102_grid_2of2.zip
:: /srv/linuxamd64_12102_database_1of2.zip
:: /srv/linuxamd64_12102_database_2of2.zip
>>>>>>>>> 升级主机的各软件包, 调整主机的基础运行环境
[root ~]# yum clean all && yum makecache && yum upgrade -y
[root ~]# yum install -y bash-argsparse.noarch bash-completion.noarch bash-completion-extras.noarch
[root ~]# yum groups install -y "X Window System" "GNOME Desktop"
[root ~]# systemctl set-default graphical.target && init 5
[root ~]# hostnamectl set-hostname "database.boat.com"
[root ~]# echo "172.16.0.201 database.boat.com" >> /etc/hosts
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>>>> 关闭主机的防火墙服务和 SELinux 防护
[root ~]# sed -i -r 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/sysconfig/selinux
[root ~]# sed -i -r 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
[root ~]# setenforce 0
[root ~]# systemctl stop firewalld.service
[root ~]# systemctl disable firewalld.service
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>>>> 准备安装磁盘网格化软件和数据库软件所需要的用户体系
[root ~]# groupadd oinstall
[root ~]# groupadd dba
[root ~]# groupadd oper
[root ~]# groupadd asmdba
[root ~]# groupadd asmadmin
[root ~]# groupadd asmoper
[root ~]# useradd -g oinstall -G dba,oper,asmdba,asmadmin,asmoper grid
[root ~]# useradd -g oinstall -G dba,oper,asmdba,asmadmin,asmoper oracle
[root ~]# echo "my_password" | passwd --stdin grid
[root ~]# echo "my_password" | passwd --stdin oracle
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>>>> 为数据库用户配置免密码 sudo 权限, 以及合适的系统资源限制参数, 随后重启主机
[root ~]# echo "%oinstall ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
[root ~]# echo "umask 002" >> ~grid/.bash_profile
[root ~]# echo "umask 002" >> ~oracle/.bash_profile
[root ~]# cat >> /etc/security/limits.conf << EOF
> @oinstall soft nproc 65536
> @oinstall hard nproc 65536
> @oinstall soft nofile 65536
> @oinstall hard nofile 65536
> @oinstall soft stack 65536
> @oinstall hard stack 65536
> @oinstall soft core -1
> @oinstall hard core -1
> @oinstall soft rss -1
> @oinstall hard rss -1
> EOF
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>>>> 准备软件安装所需的环境依赖
[root ~]# yum groups install -y "Development Tools" "Server Platform Development"
[root ~]# yum install -y compat-libcap1.x86_64 \
> compat-libstdc++-33.x86_64 \
> gcc-c++.x86_64 \
> glibc.x86_64 \
> glibc-utils.x86_64 \
> ksh.x86_64 \
> libXi.x86_64 \
> libXtst.x86_64 \
> libaio.x86_64 \
> libaio-devel.x86_64 \
> libgcc.x86_64 \
> libstdc++-devel.x86_64 \
> sysstat.x86_64
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>>>> 安装 ASMCA 工具的底层依赖软件包, 随后初始化 ASMLIB 工具并重启主机, 重启后注意观察服务单元 oracleasm.service 的运行状态
[root ~]# rpm -ivh /srv/kmod-oracleasm-2.0.8-26.0.1.el7.x86_64.rpm
[root ~]# rpm -ivh /srv/oracleasmlib-2.0.12-1.el7.x86_64.rpm
[root ~]# rpm -ivh /srv/oracleasm-support-2.1.11-2.el7.x86_64.rpm
[root ~]# oracleasm configure -i
Configuring the Oracle ASM library driver
• Default user to own the driver interface: grid
• Default group to own the driver interface: asmadmin
• Start Oracle ASM library driver on boot (y/n): y
• Scan for Oracle ASM disks on boot (y/n): y
[root ~]# reboot
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>>>> 使用 ASMLIB 工具网格化已经提前准备好的磁盘分区, 并确认磁盘分区的网格化情况, 随后准备数据库的 OFA 目录结构
[root ~]# oracleasm createdisk disk_00 /dev/sdb1
[root ~]# oracleasm createdisk disk_01 /dev/sdb2
[root ~]# oracleasm listdisks
[root ~]# mkdir -p /u01/{app,setup}
[root ~]# chown -R :oinstall /u01/{app,setup} && chmod 3775 /u01/{app,setup}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>> 解压缩 Grid 软件的安装包, 并在 X11 通道或控制台内进行图形化的软件安装
grid:~$ unzip /srv/linuxamd64_12102_grid_1of2.zip -d /u01/setup
grid:~$ unzip /srv/linuxamd64_12102_grid_2of2.zip -d /u01/setup
grid:~$ /u01/setup/grid/runInstaller
Starting ORACLE Universal Installer ... | 使用根用户登录到主机终端, 以在软件安装过程中根据提示执行某些脚本
Checking Temp space: must be greater than 500MB. Actual 16618 MB Passed
Checking Swap space: must be greater than 150MB. Actual 8084 MB Passed
Preparing to launch ORACLE Universal Installer from /tmp/OraInstall2019-12-01_12_01_01PM. Please wait ...
... ... | 先决条件检查: 执行 /tmp/CVU_12.1.0.2.0_grid/runfixup.sh 以更新系统参数
... ... | 安装产品: 执行 /u01/app/oraInventory/orainstRoot.sh
... ... | 安装产品: 执行 /u01/app/grid/product/12.1.0/grid/root.sh
The installation of ORACLE Grid infrastructure for a Standalone Server was successful
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>>>> 检查 /tmp/CVU_12.1.0.2.0_grid/runfixup.sh 脚本对主机内核参数的修正情况
grid:~$ tail -n 30 /etc/sysctl.conf
kernel.sem = 250 32000 100 128 | 信号参数, 包含 semmsl/semmns/semopm/semmni 这四个参数
kernel.shmmax = 4100421632 | 内存参数, 指定单个数据库实例共享内存段 SGA 的最大值
kernel.shmmni = 4096 | 内存参数, 指定单个数据库实例共享内存页的大小 (默认为 4KB)
kernel.shmall = 800863 | 内存参数, 指定单个数据库实例可使用的共享内存页的总页数
fs.file-max = 6815744 | 最大文件打开数量
net.ipv4.ip_local_port_range = 9000 65535 | 配置主机内服务可以随机监听的端口范围
net.core.rmem_default = 262144 | 网络套接字默认接收缓冲的缓冲区大小
net.core.rmem_max = 4194304 | 网络套接字最大接收缓冲的缓冲区大小
net.core.wmem_default = 262144 | 网络套接字默认发送缓冲的缓冲区大小
net.core.wmem_max = 1048576 | 网络套接字最大发送缓冲的缓冲区大小
fs.aio-max-nr = 1048576 | 最大异步输入输出请求的数量
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>> 配置网格化用户的环境变量, 并使用 ASMCA 工具制作网格化资源组
grid:~$ cat >> ~/.bash_prodile << EOF
> export ORACLE_SID=+ASM
> export ORACLE_BASE=/u01/app/grid
> export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/grid
> export PATH=$ORACLE_HOME/bin:$PATH
> EOF
grid:~$ asmca | 制作网格化的 DATA 磁盘组和 FRA 磁盘组
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>> 使用 netmgr 工具制作数据库网络监听器, 并启动该监听器
grid:~$ netmgr
... ... | 在 ORACLE Net Configuration / Local / Listeners 目录下新建 LISTENER
... ... | 配置监听器 LISTENER 的 TCP / TCPS / IPC 监听服务及监听端口
grid:~$ lsnrctl start LISTENER
Starting /u01/app/grid/product/12.1.0/grid/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 12.1.0.2.0 - Production
System parameter file is /u01/app/grid/product/12.1.0/grid/network/admin/listener.ora
Log messages written to /u01/app/grid/diag/tnslsnr/db-1/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db-1.boat.com)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=db-1.boat.com)(PORT=2484)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=thisismykey)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db-1.boat.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 22-DEC-2019 17:00:15
Uptime 0 days 0 hr. 9 min. 37 sec
Trace Level OFF
Security ON
SNMP OFF
Listener Parameter File /u01/app/grid/product/12.1.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/db-1/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db-1.boat.com)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=db-1.boat.com)(PORT=2484)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=thisismykey)))
The listener supports no services
The command completed successfully
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>>>> 按顺序解压甲骨文数据库软件的安装包, 启动软件通用安装程序
oracle:~$ unzip /srv/linuxamd64_12102_database_1of2.zip -d /u01/setup
oracle:~$ unzip /srv/linuxamd64_12102_database_2of2.zip -d /u01/setup
oracle:~$ /u01/setup/database/runInstaller
Starting ORACLE Universal Installer ... | 使用根用户登录到主机终端, 以在软件安装过程中根据提示执行某些脚本
Checking Temp space: must be greater than 500MB. Actual 16618 MB Passed
Checking Swap space: must be greater than 150MB. Actual 8084 MB Passed
Preparing to launch ORACLE Universal Installer from /tmp/OraInstall2019-12-01_12_01_01PM. Please wait ...
... ... | 安装产品: 执行 /u01/app/oracle/product/12.1.0/dbhome_1/root.sh
You can find the log of this install session at:
/u01/app/oraInventory/logs/installActions2019-12-01_12_01_01PM.log
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>>>> 配置数据库专有用户的环境变量, 并使用 SQL*Plus 验证数据库软件的安装情况
oracle:~$ cat >> ~/.bash_profile << EOF
> export ORACLE_BASE=/u01/app/oracle
> export ORACLE_HOME=$ORACLE_BASE/product/12.1.0/dbhome_1
> export PATH=$ORACLE_HOME/bin:$PATH
> EOF
oracle:~$ source ~/.bash_profile
oracle:~$ sqlplus /nolog
SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 28 09:06:35 2019
Copyright (c) 1982, 2014, ORACLE. All rights reserved.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
>>>>>>>>> 使用 DBCA 工具创建数据库实例, 并使用 SQL*Plus 工具连接到数据库实例做测试
oracle:~$ dbca
... ... | 从 5500 端口开始, 为数据库实例启用 EM Express 工具
... ... | 将数据库实例注册到端口为 1521 的监听器上
oracle:~$ source oraenv
ORACLE_SID = [oracle] ? summer
The ORACLE base remains unchanged with value /u01/app/oracle
oracle:~$ sqlplus /nolog
SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 28 09:06:35 2019
Copyright (c) 1982, 2014, ORACLE. All rights reserved.
SQL> CONN / AS SYSDBA;
Connected.
SQL> ALTER SYSTEM SET DB_SECUREFILE='PERMITTED' SCOPE=SPFILE;
SQL> ALTER SYSTEM SET SESSION_CACHED_CURSORS=300 SCOPE=SPFILE;
SQL> ALTER SYSTEM SET SHARED_POOL_SIZE=300M SCOPE=SPFILE;
SQL> STARTUP FORCE; | 调整数据库实例的运行参数, 以便后续加入到 EMCC 服务做统一管理
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✻
|