Oracle Linux 7.1 静默安装Oracle 18c RAC

Oracle Linux 7.1 静默安装Oracle 18c RAC
一·系统环境规则

1.1网络架构

                         节点1                        节点2
主机名                   18c1                         18c2               
Private IP            88.88.87.1                 88.88.87.2             
Public IP             10.10.13.171             10.10.13.172
VIP                   10.10.13.173             10.10.13.174
SCANIP                10.10.13.175/176/177   
SCAN_NAME             scan-18c

1.2 存储

共享磁盘                ASM磁盘                ASM磁盘组                 大小         冗余
/dev/sdb                /dev/asmdisk1          OCR                       50G          外部
/dev/sdc                /dev/asmdisk2          DATA                      50G          外部

1.3 软件版本
操作系统:Oracle Linux 7.1
集群软件: Oracle Clusterware 18.0.0
数据库软件:Oracle Database Enterprise 18.0.0

二·安装环境准备
2.1修改主机名和IP地址
修改主机名

[root@localhost ~]# hostnamectl set-hostname 18c1
[root@localhost ~]# hostnamectl set-hostname 18c2

2.2修改Private IP地址

[root@18c1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=ens33
UUID=934ab90a-5e97-496c-bd50-65cddd0a838f
DEVICE=ens33
ONBOOT=yes
IPADDR=88.88.87.1
NETMASK=255.255.255.0



[root@18c2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=ens33
UUID=934ab90a-5e97-496c-bd50-65cddd0a838f
DEVICE=ens33
ONBOOT=yes
IPADDR=88.88.87.2
NETMASK=255.255.255.0

2.3 修改Public IP地址

[root@18c1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens32
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=ens32
UUID=79732427-976c-4d80-b58d-dd81d62ebd17
DEVICE=ens32
ONBOOT=yes
IPADDR=10.10.13.171
NETMASK=255.255.255.0
GATEWAY=10.10.13.254

[root@18c2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens32
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=ens32
UUID=79732427-976c-4d80-b58d-dd81d62ebd17
DEVICE=ens32
ONBOOT=yes
IPADDR=10.10.13.172
NETMASK=255.255.255.0
GATEWAY=10.10.13.254

2.4 关闭时间同步服务

[root@18c1 ~]# systemctl stop chronyd
[root@18c1 ~]# systemctl disable chronyd
rm '/etc/systemd/system/multi-user.target.wants/chronyd.service'
[root@18c1 ~]# mv /etc/chrony.conf /etc/chrony.conf.bak


[root@18c2 ~]# systemctl stop chronyd
[root@18c2 ~]# systemctl disable chronyd
rm '/etc/systemd/system/multi-user.target.wants/chronyd.service'
[root@18c2 ~]# mv /etc/chrony.conf /etc/chrony.conf.bak

2.5关闭防火墙和SELinux

[root@18c1 ~]# setenforce 0
[root@18c1 ~]# sed -i "/^SELINUX=/s#enforcing#disabled#" /etc/selinux/config
[root@18c1 ~]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 


[root@18c2 ~]# setenforce 0
[root@18c2 ~]# sed -i "/^SELINUX=/s#enforcing#disabled#" /etc/selinux/config
[root@18c2 ~]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

2.6 配置本地YUM

[root@18c1 ~]# ls -lrt /etc/yum.repos.d/
total 4
-rw-r--r--. 1 root root 2323 Feb 16  2015 public-yum-ol7.repo
[root@18c1 ~]# mv /etc/yum.repos.d/public-yum-ol7.repo /etc/yum.repos.d/public-yum-ol7.repo.bak
[root@18c1 ~]# cat >> /etc/yum.repos.d/jy.repo < [base]
> name=jy
> baseurl=file:///run/media/root/OL-7.1\ Server.x86_64/  
> enabled=1
> gpgcheck=0
> multilib_policy=all
> EOF
[root@18c1 ~]# cat /etc/yum.repos.d/jy.repo
[base]
name=jy
baseurl=file:///run/media/root/OL-7.1\ Server.x86_64/  
enabled=1
gpgcheck=0
multilib_policy=all

[root@18c1 ~]# yum clean all
Loaded plugins: langpacks
Cleaning repos: base
Cleaning up everything
[root@18c1 ~]# yum makecache
Loaded plugins: langpacks
base                                                                                                                                                                                                                | 3.6 kB  00:00:00     
(1/4): base/group_gz                                                                                                                                                                                                | 134 kB  00:00:00     
(2/4): base/filelists_db                                                                                                                                                                                            | 3.4 MB  00:00:00     
(3/4): base/primary_db                                                                                                                                                                                              | 4.0 MB  00:00:00     
(4/4): base/other_db                                                                                                                                                                                                | 1.3 MB  00:00:00     
Metadata Cache Created



[root@18c2 ~]# ls -lrt /etc/yum.repos.d/
total 4
-rw-r--r--. 1 root root 2323 Feb 16  2015 public-yum-ol7.repo
[root@18c2 ~]# mv /etc/yum.repos.d/public-yum-ol7.repo /etc/yum.repos.d/public-yum-ol7.repo.bak
[root@18c2 ~]# cat >> /etc/yum.repos.d/jy.repo < [base]
> name=jy
> baseurl=file:///run/media/root/OL-7.1\ Server.x86_64/  
> enabled=1
> gpgcheck=0
> multilib_policy=all
> EOF
[root@18c2 ~]# cat /etc/yum.repos.d/jy.repo
[base]
name=jy
baseurl=file:///run/media/root/OL-7.1\ Server.x86_64/  
enabled=1
gpgcheck=0
multilib_policy=all



[root@18c2 ~]# yum makecache
Loaded plugins: langpacks
base                                                                                                                                                                                                                | 3.6 kB  00:00:00     
(1/4): base/group_gz                                                                                                                                                                                                | 134 kB  00:00:00     
(2/4): base/filelists_db                                                                                                                                                                                            | 3.4 MB  00:00:00     
(3/4): base/primary_db                                                                                                                                                                                              | 4.0 MB  00:00:00     
(4/4): base/other_db                                                                                                                                                                                                | 1.3 MB  00:00:00     
Metadata Cache Created

2.7 禁用NTP

[root@18c1 ~]# systemctl stop ntpd.service
[root@18c1 ~]# systemctl disable ntpd.service

[root@18c2 ~]# systemctl stop ntpd.service
[root@18c2 ~]# systemctl disable ntpd.service

2.8创建用户和组
创建用户组

[root@18c1 ~]# groupadd -g 54321 oinstall
[root@18c1 ~]# groupadd -g 54322 dba
[root@18c1 ~]# groupadd -g 54323 oper
[root@18c1 ~]# groupadd -g 54324 backupdba
[root@18c1 ~]# groupadd -g 54325 dgdba
[root@18c1 ~]# groupadd -g 54326 kmdba
[root@18c1 ~]# groupadd -g 54327 asmdba
[root@18c1 ~]# groupadd -g 54328 asmoper
[root@18c1 ~]# groupadd -g 54329 asmadmin
[root@18c1 ~]# groupadd -g 54330 racdba

[root@18c1 ~]# grep 543 /etc/group
oinstall:x:54321:
dba:x:54322:
oper:x:54323:
backupdba:x:54324:
dgdba:x:54325:
kmdba:x:54326:
asmdba:x:54327:
asmoper:x:54328:
asmadmin:x:54329:
racdba:x:54330:

[root@18c2 ~]# groupadd -g 54321 oinstall
[root@18c2 ~]# groupadd -g 54322 dba
[root@18c2 ~]# groupadd -g 54323 oper
[root@18c2 ~]# groupadd -g 54324 backupdba
[root@18c2 ~]# groupadd -g 54325 dgdba
[root@18c2 ~]# groupadd -g 54326 kmdba
[root@18c2 ~]# groupadd -g 54327 asmdba
[root@18c2 ~]# groupadd -g 54328 asmoper
[root@18c2 ~]# groupadd -g 54329 asmadmin
[root@18c2 ~]# groupadd -g 54330 racdba
[root@18c2 ~]# grep 543 /etc/group
oinstall:x:54321:
dba:x:54322:
oper:x:54323:
backupdba:x:54324:
dgdba:x:54325:
kmdba:x:54326:
asmdba:x:54327:
asmoper:x:54328:
asmadmin:x:54329:
racdba:x:54330:

创建用户

[root@18c1 ~]# useradd -u 54322 -g oinstall -G asmadmin,asmdba,asmoper,racdba grid
[root@18c1 ~]# useradd -u 54321 -g oinstall -G dba,asmdba,backupdba,dgdba,kmdba,racdba,oper oracle
[root@18c1 ~]# passwd grid
Changing password for user grid.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@18c1 ~]# passwd oracle
Changing password for user oracle.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.


[root@18c2 ~]# useradd -u 54322 -g oinstall -G asmadmin,asmdba,asmoper,racdba grid
[root@18c2 ~]# useradd -u 54321 -g oinstall -G dba,asmdba,backupdba,dgdba,kmdba,racdba,oper oracle
[root@18c2 ~]# passwd grid
Changing password for user grid.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@18c2 ~]# passwd oracle
Changing password for user oracle.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.

2.9创建相关目录

[root@18c1 ~]# mkdir -p /u01/tmp
[root@18c1 ~]# mkdir -p /u01/app/18.3/grid
[root@18c1 ~]# mkdir -p /u01/app/grid
[root@18c1 ~]# mkdir -p /u01/app/oracle/product/18.3/db
[root@18c1 ~]# mkdir -p /u01/app/oraInventory
[root@18c1 ~]# chown -R grid:oinstall /u01
[root@18c1 ~]# chown oracle:oinstall /u01/app/oracle
[root@18c1 ~]# chmod -R 775 /u01/

[root@18c2 ~]# mkdir -p /u01/tmp
[root@18c2 ~]# mkdir -p /u01/app/18.3/grid
[root@18c2 ~]# mkdir -p /u01/app/grid
[root@18c2 ~]# mkdir -p /u01/app/oracle/product/18.3/db
[root@18c2 ~]# mkdir -p /u01/app/oraInventory
[root@18c2 ~]# chown -R grid:oinstall /u01
[root@18c2 ~]# chown oracle:oinstall /u01/app/oracle
[root@18c2 ~]# chmod -R 775 /u01/

2.10 安装软件包

[root@18c1 ~]# yum install -y bc binutils compat-libcap1 compat-libstdc++ elfutils-libelf elfutils-libelf-devel fontconfig-devel glibc glibc-devel ksh libaio libaio-devel libX11 libXau libXi libXtst libXrender libXrender-devel libgcc libstdc++ libstdc++-devel libxcb make net-tools nfs-utils python  python-configshell  python-rtslib python-six targetcli smartmontools sysstat gcc c-c++ gcc-info gcc-locale gcc48 gcc48-info gcc48-locale gcc48-c++
Loaded plugins: langpacks
Package bc-1.06.95-13.el7.x86_64 already installed and latest version
Package binutils-2.23.52.0.1-30.el7.x86_64 already installed and latest version
Package compat-libcap1-1.10-7.el7.x86_64 already installed and latest version
No package compat-libstdc++ available.
Package elfutils-libelf-0.160-1.el7.x86_64 already installed and latest version
Package glibc-2.17-78.0.1.el7.x86_64 already installed and latest version
Package glibc-devel-2.17-78.0.1.el7.x86_64 already installed and latest version
Package libaio-0.3.109-12.el7.x86_64 already installed and latest version
Package libX11-1.6.0-2.1.el7.x86_64 already installed and latest version
Package libXau-1.0.8-2.1.el7.x86_64 already installed and latest version
Package libXi-1.7.2-2.1.el7.x86_64 already installed and latest version
Package libXtst-1.2.2-2.1.el7.x86_64 already installed and latest version
Package libXrender-0.9.8-2.1.el7.x86_64 already installed and latest version
Package libgcc-4.8.3-9.el7.x86_64 already installed and latest version
Package libstdc++-4.8.3-9.el7.x86_64 already installed and latest version
Package libstdc++-devel-4.8.3-9.el7.x86_64 already installed and latest version
Package libxcb-1.9-5.el7.x86_64 already installed and latest version
Package 1:make-3.82-21.el7.x86_64 already installed and latest version
Package net-tools-2.0-0.17.20131004git.el7.x86_64 already installed and latest version
Package 1:nfs-utils-1.3.0-0.8.el7.x86_64 already installed and latest version
Package python-2.7.5-16.el7.x86_64 already installed and latest version
Package 1:python-configshell-1.1.fb14-1.el7.noarch already installed and latest version
Package python-rtslib-2.1.fb50-1.el7.noarch already installed and latest version
Package python-six-1.3.0-4.el7.noarch already installed and latest version
Package targetcli-2.1.fb37-3.el7.noarch already installed and latest version
Package 1:smartmontools-6.2-4.el7.x86_64 already installed and latest version
Package sysstat-10.1.5-7.el7.x86_64 already installed and latest version
Package gcc-4.8.3-9.el7.x86_64 already installed and latest version
No package c-c++ available.
No package gcc-info available.
No package gcc-locale available.
No package gcc48 available.
No package gcc48-info available.
No package gcc48-locale available.
No package gcc48-c++ available.
Resolving Dependencies
--> Running transaction check
---> Package elfutils-libelf-devel.x86_64 0:0.160-1.el7 will be installed
---> Package fontconfig-devel.x86_64 0:2.10.95-7.el7 will be installed
--> Processing Dependency: freetype-devel >= 2.1.4 for package: fontconfig-devel-2.10.95-7.el7.x86_64
--> Processing Dependency: pkgconfig(freetype2) for package: fontconfig-devel-2.10.95-7.el7.x86_64
--> Processing Dependency: pkgconfig(expat) for package: fontconfig-devel-2.10.95-7.el7.x86_64
---> Package ksh.x86_64 0:20120801-22.el7 will be installed
---> Package libXrender-devel.x86_64 0:0.9.8-2.1.el7 will be installed
--> Processing Dependency: pkgconfig(renderproto) >= 0.9 for package: libXrender-devel-0.9.8-2.1.el7.x86_64
--> Processing Dependency: pkgconfig(xproto) for package: libXrender-devel-0.9.8-2.1.el7.x86_64
--> Processing Dependency: pkgconfig(x11) for package: libXrender-devel-0.9.8-2.1.el7.x86_64
---> Package libaio-devel.x86_64 0:0.3.109-12.el7 will be installed
--> Running transaction check
---> Package expat-devel.x86_64 0:2.1.0-8.el7 will be installed
---> Package freetype-devel.x86_64 0:2.4.11-9.el7 will be installed
--> Processing Dependency: zlib-devel for package: freetype-devel-2.4.11-9.el7.x86_64
---> Package libX11-devel.x86_64 0:1.6.0-2.1.el7 will be installed
--> Processing Dependency: pkgconfig(xcb) >= 1.1.92 for package: libX11-devel-1.6.0-2.1.el7.x86_64
--> Processing Dependency: pkgconfig(xcb) for package: libX11-devel-1.6.0-2.1.el7.x86_64
---> Package xorg-x11-proto-devel.noarch 0:7.7-8.el7.1 will be installed
--> Running transaction check
---> Package libxcb-devel.x86_64 0:1.9-5.el7 will be installed
--> Processing Dependency: pkgconfig(xau) >= 0.99.2 for package: libxcb-devel-1.9-5.el7.x86_64
---> Package zlib-devel.x86_64 0:1.2.7-13.el7 will be installed
--> Running transaction check
---> Package libXau-devel.x86_64 0:1.0.8-2.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================================================================================
 Package                                                           Arch                                               Version                                                       Repository                                        Size
===========================================================================================================================================================================================================================================
Installing:
 elfutils-libelf-devel                                             x86_64                                             0.160-1.el7                                                   base                                              34 k
 fontconfig-devel                                                  x86_64                                             2.10.95-7.el7                                                 base                                             127 k
 ksh                                                               x86_64                                             20120801-22.el7                                               base                                             879 k
 libXrender-devel                                                  x86_64                                             0.9.8-2.1.el7                                                 base                                              16 k
 libaio-devel                                                      x86_64                                             0.3.109-12.el7                                                base                                              12 k
Installing for dependencies:
 expat-devel                                                       x86_64                                             2.1.0-8.el7                                                   base                                              56 k
 freetype-devel                                                    x86_64                                             2.4.11-9.el7                                                  base                                             354 k
 libX11-devel                                                      x86_64                                             1.6.0-2.1.el7                                                 base                                             978 k
 libXau-devel                                                      x86_64                                             1.0.8-2.1.el7                                                 base                                              14 k
 libxcb-devel                                                      x86_64                                             1.9-5.el7                                                     base                                             1.0 M
 xorg-x11-proto-devel                                              noarch                                             7.7-8.el7.1                                                   base                                             280 k
 zlib-devel                                                        x86_64                                             1.2.7-13.el7                                                  base                                              49 k

Transaction Summary
===========================================================================================================================================================================================================================================
Install  5 Packages (+7 Dependent packages)

Total download size: 3.7 M
Installed size: 12 M
Downloading packages:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                       15 MB/s | 3.7 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : xorg-x11-proto-devel-7.7-8.el7.1.noarch                                                                                                                                                                                1/12 
  Installing : libXau-devel-1.0.8-2.1.el7.x86_64                                                                                                                                                                                      2/12 
  Installing : libxcb-devel-1.9-5.el7.x86_64                                                                                                                                                                                          3/12 
  Installing : libX11-devel-1.6.0-2.1.el7.x86_64                                                                                                                                                                                      4/12 
  Installing : expat-devel-2.1.0-8.el7.x86_64                                                                                                                                                                                         5/12 
  Installing : zlib-devel-1.2.7-13.el7.x86_64                                                                                                                                                                                         6/12 
  Installing : freetype-devel-2.4.11-9.el7.x86_64                                                                                                                                                                                     7/12 
  Installing : fontconfig-devel-2.10.95-7.el7.x86_64                                                                                                                                                                                  8/12 
  Installing : libXrender-devel-0.9.8-2.1.el7.x86_64                                                                                                                                                                                  9/12 
  Installing : libaio-devel-0.3.109-12.el7.x86_64                                                                                                                                                                                    10/12 
  Installing : elfutils-libelf-devel-0.160-1.el7.x86_64                                                                                                                                                                              11/12 
  Installing : ksh-20120801-22.el7.x86_64                                                                                                                                                                                            12/12 
  Verifying  : ksh-20120801-22.el7.x86_64                                                                                                                                                                                             1/12 
  Verifying  : libXrender-devel-0.9.8-2.1.el7.x86_64                                                                                                                                                                                  2/12 
  Verifying  : zlib-devel-1.2.7-13.el7.x86_64                                                                                                                                                                                         3/12 
  Verifying  : libxcb-devel-1.9-5.el7.x86_64                                                                                                                                                                                          4/12 
  Verifying  : libX11-devel-1.6.0-2.1.el7.x86_64                                                                                                                                                                                      5/12 
  Verifying  : expat-devel-2.1.0-8.el7.x86_64                                                                                                                                                                                         6/12 
  Verifying  : xorg-x11-proto-devel-7.7-8.el7.1.noarch                                                                                                                                                                                7/12 
  Verifying  : elfutils-libelf-devel-0.160-1.el7.x86_64                                                                                                                                                                               8/12 
  Verifying  : libaio-devel-0.3.109-12.el7.x86_64                                                                                                                                                                                     9/12 
  Verifying  : fontconfig-devel-2.10.95-7.el7.x86_64                                                                                                                                                                                 10/12 
  Verifying  : freetype-devel-2.4.11-9.el7.x86_64                                                                                                                                                                                    11/12 
  Verifying  : libXau-devel-1.0.8-2.1.el7.x86_64                                                                                                                                                                                     12/12 

Installed:
  elfutils-libelf-devel.x86_64 0:0.160-1.el7          fontconfig-devel.x86_64 0:2.10.95-7.el7          ksh.x86_64 0:20120801-22.el7          libXrender-devel.x86_64 0:0.9.8-2.1.el7          libaio-devel.x86_64 0:0.3.109-12.el7         

Dependency Installed:
  expat-devel.x86_64 0:2.1.0-8.el7    freetype-devel.x86_64 0:2.4.11-9.el7    libX11-devel.x86_64 0:1.6.0-2.1.el7    libXau-devel.x86_64 0:1.0.8-2.1.el7    libxcb-devel.x86_64 0:1.9-5.el7    xorg-x11-proto-devel.noarch 0:7.7-8.el7.1   
  zlib-devel.x86_64 0:1.2.7-13.el7   

Complete!

安装compat-libstdc++-33-3.2.3-72.el7.i686.rpm,因为名字带有版本信息

[root@18c1 ~]# yum install  compat-libstdc++-33-3.2.3-72.el7.i686
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package compat-libstdc++-33.i686 0:3.2.3-72.el7 will be installed
--> Processing Dependency: libm.so.6 for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Processing Dependency: libgcc_s.so.1(GLIBC_2.0) for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Processing Dependency: libgcc_s.so.1(GCC_3.3) for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Processing Dependency: libgcc_s.so.1(GCC_3.0) for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Processing Dependency: libgcc_s.so.1 for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Processing Dependency: libc.so.6(GLIBC_2.3) for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Running transaction check
---> Package glibc.i686 0:2.17-78.0.1.el7 will be installed
--> Processing Dependency: libfreebl3.so(NSSRAWHASH_3.12.3) for package: glibc-2.17-78.0.1.el7.i686
--> Processing Dependency: libfreebl3.so for package: glibc-2.17-78.0.1.el7.i686
---> Package libgcc.i686 0:4.8.3-9.el7 will be installed
--> Running transaction check
---> Package nss-softokn-freebl.i686 0:3.16.2.3-9.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================================================================================
 Package                                                          Arch                                              Version                                                        Repository                                         Size
===========================================================================================================================================================================================================================================
Installing:
 compat-libstdc++-33                                              i686                                              3.2.3-72.el7                                                   base                                              196 k
Installing for dependencies:
 glibc                                                            i686                                              2.17-78.0.1.el7                                                base                                              4.2 M
 libgcc                                                           i686                                              4.8.3-9.el7                                                    base                                               99 k
 nss-softokn-freebl                                               i686                                              3.16.2.3-9.el7                                                 base                                              186 k

Transaction Summary
===========================================================================================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 4.6 M
Installed size: 16 M
Is this ok [y/d/N]: y
Downloading packages:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                       35 MB/s | 4.6 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libgcc-4.8.3-9.el7.i686                                                                                                                                                                                                 1/4 
  Installing : nss-softokn-freebl-3.16.2.3-9.el7.i686                                                                                                                                                                                  2/4 
  Installing : glibc-2.17-78.0.1.el7.i686                                                                                                                                                                                              3/4 
  Installing : compat-libstdc++-33-3.2.3-72.el7.i686                                                                                                                                                                                   4/4 
  Verifying  : compat-libstdc++-33-3.2.3-72.el7.i686                                                                                                                                                                                   1/4 
  Verifying  : glibc-2.17-78.0.1.el7.i686                                                                                                                                                                                              2/4 
  Verifying  : libgcc-4.8.3-9.el7.i686                                                                                                                                                                                                 3/4 
  Verifying  : nss-softokn-freebl-3.16.2.3-9.el7.i686                                                                                                                                                                                  4/4 

Installed:
  compat-libstdc++-33.i686 0:3.2.3-72.el7                                                                                                                                                                                                  

Dependency Installed:
  glibc.i686 0:2.17-78.0.1.el7                                               libgcc.i686 0:4.8.3-9.el7                                               nss-softokn-freebl.i686 0:3.16.2.3-9.el7                                              

Complete!


[root@18c2 ~]# yum install -y bc binutils compat-libcap1 compat-libstdc++ elfutils-libelf elfutils-libelf-devel fontconfig-devel glibc glibc-devel ksh libaio libaio-devel libX11 libXau libXi libXtst libXrender libXrender-devel libgcc libstdc++ libstdc++-devel libxcb make net-tools nfs-utils python  python-configshell  python-rtslib python-six targetcli smartmontools sysstat gcc c-c++ gcc-info gcc-locale gcc48 gcc48-info gcc48-locale gcc48-c++
Loaded plugins: langpacks
Package bc-1.06.95-13.el7.x86_64 already installed and latest version
Package binutils-2.23.52.0.1-30.el7.x86_64 already installed and latest version
Package compat-libcap1-1.10-7.el7.x86_64 already installed and latest version
No package compat-libstdc++ available.
Package elfutils-libelf-0.160-1.el7.x86_64 already installed and latest version
Package glibc-2.17-78.0.1.el7.x86_64 already installed and latest version
Package glibc-devel-2.17-78.0.1.el7.x86_64 already installed and latest version
Package libaio-0.3.109-12.el7.x86_64 already installed and latest version
Package libX11-1.6.0-2.1.el7.x86_64 already installed and latest version
Package libXau-1.0.8-2.1.el7.x86_64 already installed and latest version
Package libXi-1.7.2-2.1.el7.x86_64 already installed and latest version
Package libXtst-1.2.2-2.1.el7.x86_64 already installed and latest version
Package libXrender-0.9.8-2.1.el7.x86_64 already installed and latest version
Package libgcc-4.8.3-9.el7.x86_64 already installed and latest version
Package libstdc++-4.8.3-9.el7.x86_64 already installed and latest version
Package libstdc++-devel-4.8.3-9.el7.x86_64 already installed and latest version
Package libxcb-1.9-5.el7.x86_64 already installed and latest version
Package 1:make-3.82-21.el7.x86_64 already installed and latest version
Package net-tools-2.0-0.17.20131004git.el7.x86_64 already installed and latest version
Package 1:nfs-utils-1.3.0-0.8.el7.x86_64 already installed and latest version
Package python-2.7.5-16.el7.x86_64 already installed and latest version
Package 1:python-configshell-1.1.fb14-1.el7.noarch already installed and latest version
Package python-rtslib-2.1.fb50-1.el7.noarch already installed and latest version
Package python-six-1.3.0-4.el7.noarch already installed and latest version
Package targetcli-2.1.fb37-3.el7.noarch already installed and latest version
Package 1:smartmontools-6.2-4.el7.x86_64 already installed and latest version
Package sysstat-10.1.5-7.el7.x86_64 already installed and latest version
Package gcc-4.8.3-9.el7.x86_64 already installed and latest version
No package c-c++ available.
No package gcc-info available.
No package gcc-locale available.
No package gcc48 available.
No package gcc48-info available.
No package gcc48-locale available.
No package gcc48-c++ available.
Resolving Dependencies
--> Running transaction check
---> Package elfutils-libelf-devel.x86_64 0:0.160-1.el7 will be installed
---> Package fontconfig-devel.x86_64 0:2.10.95-7.el7 will be installed
--> Processing Dependency: freetype-devel >= 2.1.4 for package: fontconfig-devel-2.10.95-7.el7.x86_64
--> Processing Dependency: pkgconfig(freetype2) for package: fontconfig-devel-2.10.95-7.el7.x86_64
--> Processing Dependency: pkgconfig(expat) for package: fontconfig-devel-2.10.95-7.el7.x86_64
---> Package ksh.x86_64 0:20120801-22.el7 will be installed
---> Package libXrender-devel.x86_64 0:0.9.8-2.1.el7 will be installed
--> Processing Dependency: pkgconfig(renderproto) >= 0.9 for package: libXrender-devel-0.9.8-2.1.el7.x86_64
--> Processing Dependency: pkgconfig(xproto) for package: libXrender-devel-0.9.8-2.1.el7.x86_64
--> Processing Dependency: pkgconfig(x11) for package: libXrender-devel-0.9.8-2.1.el7.x86_64
---> Package libaio-devel.x86_64 0:0.3.109-12.el7 will be installed
--> Running transaction check
---> Package expat-devel.x86_64 0:2.1.0-8.el7 will be installed
---> Package freetype-devel.x86_64 0:2.4.11-9.el7 will be installed
--> Processing Dependency: zlib-devel for package: freetype-devel-2.4.11-9.el7.x86_64
---> Package libX11-devel.x86_64 0:1.6.0-2.1.el7 will be installed
--> Processing Dependency: pkgconfig(xcb) >= 1.1.92 for package: libX11-devel-1.6.0-2.1.el7.x86_64
--> Processing Dependency: pkgconfig(xcb) for package: libX11-devel-1.6.0-2.1.el7.x86_64
---> Package xorg-x11-proto-devel.noarch 0:7.7-8.el7.1 will be installed
--> Running transaction check
---> Package libxcb-devel.x86_64 0:1.9-5.el7 will be installed
--> Processing Dependency: pkgconfig(xau) >= 0.99.2 for package: libxcb-devel-1.9-5.el7.x86_64
---> Package zlib-devel.x86_64 0:1.2.7-13.el7 will be installed
--> Running transaction check
---> Package libXau-devel.x86_64 0:1.0.8-2.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================================================================================
 Package                                                           Arch                                               Version                                                       Repository                                        Size
===========================================================================================================================================================================================================================================
Installing:
 elfutils-libelf-devel                                             x86_64                                             0.160-1.el7                                                   base                                              34 k
 fontconfig-devel                                                  x86_64                                             2.10.95-7.el7                                                 base                                             127 k
 ksh                                                               x86_64                                             20120801-22.el7                                               base                                             879 k
 libXrender-devel                                                  x86_64                                             0.9.8-2.1.el7                                                 base                                              16 k
 libaio-devel                                                      x86_64                                             0.3.109-12.el7                                                base                                              12 k
Installing for dependencies:
 expat-devel                                                       x86_64                                             2.1.0-8.el7                                                   base                                              56 k
 freetype-devel                                                    x86_64                                             2.4.11-9.el7                                                  base                                             354 k
 libX11-devel                                                      x86_64                                             1.6.0-2.1.el7                                                 base                                             978 k
 libXau-devel                                                      x86_64                                             1.0.8-2.1.el7                                                 base                                              14 k
 libxcb-devel                                                      x86_64                                             1.9-5.el7                                                     base                                             1.0 M
 xorg-x11-proto-devel                                              noarch                                             7.7-8.el7.1                                                   base                                             280 k
 zlib-devel                                                        x86_64                                             1.2.7-13.el7                                                  base                                              49 k

Transaction Summary
===========================================================================================================================================================================================================================================
Install  5 Packages (+7 Dependent packages)

Total download size: 3.7 M
Installed size: 12 M
Downloading packages:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                      7.4 MB/s | 3.7 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : xorg-x11-proto-devel-7.7-8.el7.1.noarch                                                                                                                                                                                1/12 
  Installing : libXau-devel-1.0.8-2.1.el7.x86_64                                                                                                                                                                                      2/12 
  Installing : libxcb-devel-1.9-5.el7.x86_64                                                                                                                                                                                          3/12 
  Installing : libX11-devel-1.6.0-2.1.el7.x86_64                                                                                                                                                                                      4/12 
  Installing : expat-devel-2.1.0-8.el7.x86_64                                                                                                                                                                                         5/12 
  Installing : zlib-devel-1.2.7-13.el7.x86_64                                                                                                                                                                                         6/12 
  Installing : freetype-devel-2.4.11-9.el7.x86_64                                                                                                                                                                                     7/12 
  Installing : fontconfig-devel-2.10.95-7.el7.x86_64                                                                                                                                                                                  8/12 
  Installing : libXrender-devel-0.9.8-2.1.el7.x86_64                                                                                                                                                                                  9/12 
  Installing : libaio-devel-0.3.109-12.el7.x86_64                                                                                                                                                                                    10/12 
  Installing : elfutils-libelf-devel-0.160-1.el7.x86_64                                                                                                                                                                              11/12 
  Installing : ksh-20120801-22.el7.x86_64                                                                                                                                                                                            12/12 
  Verifying  : ksh-20120801-22.el7.x86_64                                                                                                                                                                                             1/12 
  Verifying  : libXrender-devel-0.9.8-2.1.el7.x86_64                                                                                                                                                                                  2/12 
  Verifying  : zlib-devel-1.2.7-13.el7.x86_64                                                                                                                                                                                         3/12 
  Verifying  : libxcb-devel-1.9-5.el7.x86_64                                                                                                                                                                                          4/12 
  Verifying  : libX11-devel-1.6.0-2.1.el7.x86_64                                                                                                                                                                                      5/12 
  Verifying  : expat-devel-2.1.0-8.el7.x86_64                                                                                                                                                                                         6/12 
  Verifying  : xorg-x11-proto-devel-7.7-8.el7.1.noarch                                                                                                                                                                                7/12 
  Verifying  : elfutils-libelf-devel-0.160-1.el7.x86_64                                                                                                                                                                               8/12 
  Verifying  : libaio-devel-0.3.109-12.el7.x86_64                                                                                                                                                                                     9/12 
  Verifying  : fontconfig-devel-2.10.95-7.el7.x86_64                                                                                                                                                                                 10/12 
  Verifying  : freetype-devel-2.4.11-9.el7.x86_64                                                                                                                                                                                    11/12 
  Verifying  : libXau-devel-1.0.8-2.1.el7.x86_64                                                                                                                                                                                     12/12 

Installed:
  elfutils-libelf-devel.x86_64 0:0.160-1.el7          fontconfig-devel.x86_64 0:2.10.95-7.el7          ksh.x86_64 0:20120801-22.el7          libXrender-devel.x86_64 0:0.9.8-2.1.el7          libaio-devel.x86_64 0:0.3.109-12.el7         

Dependency Installed:
  expat-devel.x86_64 0:2.1.0-8.el7    freetype-devel.x86_64 0:2.4.11-9.el7    libX11-devel.x86_64 0:1.6.0-2.1.el7    libXau-devel.x86_64 0:1.0.8-2.1.el7    libxcb-devel.x86_64 0:1.9-5.el7    xorg-x11-proto-devel.noarch 0:7.7-8.el7.1   
  zlib-devel.x86_64 0:1.2.7-13.el7   

Complete!

安装compat-libstdc++-33-3.2.3-72.el7.i686.rpm,因为名字带有版本信息

[root@18c2 ~]# yum install  compat-libstdc++-33-3.2.3-72.el7.i686
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package compat-libstdc++-33.i686 0:3.2.3-72.el7 will be installed
--> Processing Dependency: libm.so.6 for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Processing Dependency: libgcc_s.so.1(GLIBC_2.0) for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Processing Dependency: libgcc_s.so.1(GCC_3.3) for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Processing Dependency: libgcc_s.so.1(GCC_3.0) for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Processing Dependency: libgcc_s.so.1 for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Processing Dependency: libc.so.6(GLIBC_2.3) for package: compat-libstdc++-33-3.2.3-72.el7.i686
--> Running transaction check
---> Package glibc.i686 0:2.17-78.0.1.el7 will be installed
--> Processing Dependency: libfreebl3.so(NSSRAWHASH_3.12.3) for package: glibc-2.17-78.0.1.el7.i686
--> Processing Dependency: libfreebl3.so for package: glibc-2.17-78.0.1.el7.i686
---> Package libgcc.i686 0:4.8.3-9.el7 will be installed
--> Running transaction check
---> Package nss-softokn-freebl.i686 0:3.16.2.3-9.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================================================================================
 Package                                                          Arch                                              Version                                                        Repository                                         Size
===========================================================================================================================================================================================================================================
Installing:
 compat-libstdc++-33                                              i686                                              3.2.3-72.el7                                                   base                                              196 k
Installing for dependencies:
 glibc                                                            i686                                              2.17-78.0.1.el7                                                base                                              4.2 M
 libgcc                                                           i686                                              4.8.3-9.el7                                                    base                                               99 k
 nss-softokn-freebl                                               i686                                              3.16.2.3-9.el7                                                 base                                              186 k

Transaction Summary
===========================================================================================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 4.6 M
Installed size: 16 M
Is this ok [y/d/N]: y
Downloading packages:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                       73 MB/s | 4.6 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libgcc-4.8.3-9.el7.i686                                                                                                                                                                                                 1/4 
  Installing : nss-softokn-freebl-3.16.2.3-9.el7.i686                                                                                                                                                                                  2/4 
  Installing : glibc-2.17-78.0.1.el7.i686                                                                                                                                                                                              3/4 
  Installing : compat-libstdc++-33-3.2.3-72.el7.i686                                                                                                                                                                                   4/4 
  Verifying  : compat-libstdc++-33-3.2.3-72.el7.i686                                                                                                                                                                                   1/4 
  Verifying  : glibc-2.17-78.0.1.el7.i686                                                                                                                                                                                              2/4 
  Verifying  : libgcc-4.8.3-9.el7.i686                                                                                                                                                                                                 3/4 
  Verifying  : nss-softokn-freebl-3.16.2.3-9.el7.i686                                                                                                                                                                                  4/4 

Installed:
  compat-libstdc++-33.i686 0:3.2.3-72.el7                                                                                                                                                                                                  

Dependency Installed:
  glibc.i686 0:2.17-78.0.1.el7                                               libgcc.i686 0:4.8.3-9.el7                                               nss-softokn-freebl.i686 0:3.16.2.3-9.el7                                              

Complete!

检查已经安装的软件包

[root@18c1 ~]# rpm -q --qf '%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n' bc binutils compat-libcap1 compat-libstdc++ elfutils-libelf elfutils-libelf-devel fontconfig-devel glibc glibc-devel ksh libaio libaio-devel libX11 libXau libXi libXtst libXrender libXrender-devel libgcc libstdc++ libstdc++-devel libxcb make net-tools nfs-utils python  python-configshell  python-rtslib python-six targetcli smartmontools sysstat
bc-1.06.95-13.el7 (x86_64)
binutils-2.23.52.0.1-30.el7 (x86_64)
compat-libcap1-1.10-7.el7 (x86_64)
package compat-libstdc++ is not installed
elfutils-libelf-0.160-1.el7 (x86_64)
elfutils-libelf-devel-0.160-1.el7 (x86_64)
fontconfig-devel-2.10.95-7.el7 (x86_64)
glibc-2.17-78.0.1.el7 (x86_64)
glibc-2.17-78.0.1.el7 (i686)
glibc-devel-2.17-78.0.1.el7 (x86_64)
ksh-20120801-22.el7 (x86_64)
libaio-0.3.109-12.el7 (x86_64)
libaio-devel-0.3.109-12.el7 (x86_64)
libX11-1.6.0-2.1.el7 (x86_64)
libXau-1.0.8-2.1.el7 (x86_64)
libXi-1.7.2-2.1.el7 (x86_64)
libXtst-1.2.2-2.1.el7 (x86_64)
libXrender-0.9.8-2.1.el7 (x86_64)
libXrender-devel-0.9.8-2.1.el7 (x86_64)
libgcc-4.8.3-9.el7 (x86_64)
libgcc-4.8.3-9.el7 (i686)
libstdc++-4.8.3-9.el7 (x86_64)
libstdc++-devel-4.8.3-9.el7 (x86_64)
libxcb-1.9-5.el7 (x86_64)
make-3.82-21.el7 (x86_64)
net-tools-2.0-0.17.20131004git.el7 (x86_64)
nfs-utils-1.3.0-0.8.el7 (x86_64)
python-2.7.5-16.el7 (x86_64)
python-configshell-1.1.fb14-1.el7 (noarch)
python-rtslib-2.1.fb50-1.el7 (noarch)
python-six-1.3.0-4.el7 (noarch)
targetcli-2.1.fb37-3.el7 (noarch)
smartmontools-6.2-4.el7 (x86_64)
sysstat-10.1.5-7.el7 (x86_64)


[root@18c2 ~]# rpm -q --qf '%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n' bc binutils compat-libcap1 compat-libstdc++ elfutils-libelf elfutils-libelf-devel fontconfig-devel glibc glibc-devel ksh libaio libaio-devel libX11 libXau libXi libXtst libXrender libXrender-devel libgcc libstdc++ libstdc++-devel libxcb make net-tools nfs-utils python  python-configshell  python-rtslib python-six targetcli smartmontools sysstat
bc-1.06.95-13.el7 (x86_64)
binutils-2.23.52.0.1-30.el7 (x86_64)
compat-libcap1-1.10-7.el7 (x86_64)
package compat-libstdc++ is not installed
elfutils-libelf-0.160-1.el7 (x86_64)
elfutils-libelf-devel-0.160-1.el7 (x86_64)
fontconfig-devel-2.10.95-7.el7 (x86_64)
glibc-2.17-78.0.1.el7 (x86_64)
glibc-2.17-78.0.1.el7 (i686)
glibc-devel-2.17-78.0.1.el7 (x86_64)
ksh-20120801-22.el7 (x86_64)
libaio-0.3.109-12.el7 (x86_64)
libaio-devel-0.3.109-12.el7 (x86_64)
libX11-1.6.0-2.1.el7 (x86_64)
libXau-1.0.8-2.1.el7 (x86_64)
libXi-1.7.2-2.1.el7 (x86_64)
libXtst-1.2.2-2.1.el7 (x86_64)
libXrender-0.9.8-2.1.el7 (x86_64)
libXrender-devel-0.9.8-2.1.el7 (x86_64)
libgcc-4.8.3-9.el7 (x86_64)
libgcc-4.8.3-9.el7 (i686)
libstdc++-4.8.3-9.el7 (x86_64)
libstdc++-devel-4.8.3-9.el7 (x86_64)
libxcb-1.9-5.el7 (x86_64)
make-3.82-21.el7 (x86_64)
net-tools-2.0-0.17.20131004git.el7 (x86_64)
nfs-utils-1.3.0-0.8.el7 (x86_64)
python-2.7.5-16.el7 (x86_64)
python-configshell-1.1.fb14-1.el7 (noarch)
python-rtslib-2.1.fb50-1.el7 (noarch)
python-six-1.3.0-4.el7 (noarch)
targetcli-2.1.fb37-3.el7 (noarch)
smartmontools-6.2-4.el7 (x86_64)
sysstat-10.1.5-7.el7 (x86_64)

2.11编辑hosts文件

[root@18c1 ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#public-ip
10.10.13.171      18c1
10.10.13.172      18c2

#public-vip
10.10.13.173      18c1-vip
10.10.13.174      18c2-vip

#prive-ip
88.88.87.1        18c1-priv
88.88.87.2        18c2-priv

#scan-ip
10.10.13.175      scan-18c
10.10.13.176      scan-18c
10.10.13.177      scan-18c

[root@18c2 ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#public-ip
10.10.13.171      18c1
10.10.13.172      18c2

#public-vip
10.10.13.173      18c1-vip
10.10.13.174      18c2-vip

#prive-ip
88.88.87.1        18c1-priv
88.88.87.2        18c2-priv

#scan-ip
10.10.13.175      scan-18c
10.10.13.176      scan-18c
10.10.13.177      scan-18c

2.12 修改系统内核参数

[root@18c1 ~]# cat >> /etc/sysctl.conf < kernel.shmall = 4294967296
> kernel.sem = 510 65280 510 128
> kernel.shmmni = 4096
> kernel.shmmax = 429496729500
> net.ipv4.ip_local_port_range = 9000 65500
> net.core.rmem_default = 1048576
> net.core.rmem_max = 4194304
> net.core.wmem_default = 262144
> net.core.wmem_max = 1048576
> fs.file-max = 6815744
> fs.aio-max-nr = 1048576
> vm.swappiness = 0
> vm.dirty_background_ratio = 3
> vm.dirty_ratio = 80
> vm.dirty_expire_centisecs = 500
> vm.dirty_writeback_centisecs = 100
> net.ipv4.tcp_sack = 0
> net.ipv4.tcp_timestamps = 0
> net.ipv4.conf.default.rp_filter = 0
> net.ipv4.tcp_wmem = 262144
> net.ipv4.tcp_rmem = 4194304
> EOF


[root@18c2 ~]# cat >> /etc/sysctl.conf < kernel.shmall = 4294967296
> kernel.sem = 510 65280 510 128
> kernel.shmmni = 4096
> kernel.shmmax = 429496729500
> net.ipv4.ip_local_port_range = 9000 65500
> net.core.rmem_default = 1048576
> net.core.rmem_max = 4194304
> net.core.wmem_default = 262144
> net.core.wmem_max = 1048576
> fs.file-max = 6815744
> fs.aio-max-nr = 1048576
> vm.swappiness = 0
> vm.dirty_background_ratio = 3
> vm.dirty_ratio = 80
> vm.dirty_expire_centisecs = 500
> vm.dirty_writeback_centisecs = 100
> net.ipv4.tcp_sack = 0
> net.ipv4.tcp_timestamps = 0
> net.ipv4.conf.default.rp_filter = 0
> net.ipv4.tcp_wmem = 262144
> net.ipv4.tcp_rmem = 4194304
> EOF

[root@18c1 ~]# sysctl -p
kernel.shmall = 4294967296
kernel.sem = 510 65280 510 128
kernel.shmmni = 4096
kernel.shmmax = 429496729500
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 1048576
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.file-max = 6815744
fs.aio-max-nr = 1048576
vm.swappiness = 0
vm.dirty_background_ratio = 3
vm.dirty_ratio = 80
vm.dirty_expire_centisecs = 500
vm.dirty_writeback_centisecs = 100
net.ipv4.tcp_sack = 0
net.ipv4.tcp_timestamps = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.tcp_wmem = 262144
net.ipv4.tcp_rmem = 4194304


[root@18c2 ~]# sysctl -p
kernel.shmall = 4294967296
kernel.sem = 510 65280 510 128
kernel.shmmni = 4096
kernel.shmmax = 429496729500
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 1048576
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.file-max = 6815744
fs.aio-max-nr = 1048576
vm.swappiness = 0
vm.dirty_background_ratio = 3
vm.dirty_ratio = 80
vm.dirty_expire_centisecs = 500
vm.dirty_writeback_centisecs = 100
net.ipv4.tcp_sack = 0
net.ipv4.tcp_timestamps = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.tcp_wmem = 262144
net.ipv4.tcp_rmem = 4194304

2.13 配置LIMITS限制参数

[root@18c1 ~]# cat >> /etc/security/limits.conf < oracle          soft    nproc           2047
> oracle          hard    nproc           16384
> oracle          soft    nofile          65536
> oracle          hard    nofile          65536
> oracle          soft    memlock         3145728
> oracle          hard    memlock         3145728
> oracle          soft    stack           10240
> oracle          hard    stack           32768
> 
> grid          soft    nproc           2047
> grid          hard    nproc           16384
> grid          soft    nofile          65536
> grid          hard    nofile          65536
> grid          soft    memlock         3145728
> grid          hard    memlock         3145728
> grid          soft    stack           10240
> grid          hard    stack           32768
> EOF

[root@18c2 ~]# cat >> /etc/security/limits.conf < oracle          soft    nproc           2047
> oracle          hard    nproc           16384
> oracle          soft    nofile          65536
> oracle          hard    nofile          65536
> oracle          soft    memlock         3145728
> oracle          hard    memlock         3145728
> oracle          soft    stack           10240
> oracle          hard    stack           32768
> 
> grid          soft    nproc           2047
> grid          hard    nproc           16384
> grid          soft    nofile          65536
> grid          hard    nofile          65536
> grid          soft    memlock         3145728
> grid          hard    memlock         3145728
> grid          soft    stack           10240
> grid          hard    stack           32768
> EOF

2.14配置PAM

[root@18c1 ~]# cat  >> /etc/pam.d/login < session    required     /lib64/security/pam_limits.so 
> EOF

[root@18c2 ~]# cat  >> /etc/pam.d/login < session    required     /lib64/security/pam_limits.so 
> EOF

2.15 配置系统环境变量

[root@18c1 ~]# cat  >> /etc/pam.d/login < if [ \$USER = "oracle" ]; then  
>     if [ \$SHELL = "/bin/ksh" ]; then
>         ulimit -p 16384
>         ulimit -n 65536
>     else
>         ulimit -u 16384 -n 65536
>     fi
> fi
> 
> if [ \$USER = "grid" ]; then  
>     if [ \$SHELL = "/bin/ksh" ]; then
>         ulimit -p 16384
>         ulimit -n 65536
>     else
>         ulimit -u 16384 -n 65536
>     fi
> fi
> EOF

[root@18c2 ~]# cat  >> /etc/pam.d/login < if [ \$USER = "oracle" ]; then  
>     if [ \$SHELL = "/bin/ksh" ]; then
>         ulimit -p 16384
>         ulimit -n 65536
>     else
>         ulimit -u 16384 -n 65536
>     fi
> fi
> 
> if [ \$USER = "grid" ]; then  
>     if [ \$SHELL = "/bin/ksh" ]; then
>         ulimit -p 16384
>         ulimit -n 65536
>     else
>         ulimit -u 16384 -n 65536
>     fi
> fi
> EOF

2.16 配置grid用户环境变量

[grid@18c1 ~]$ vi .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/18.3/grid
export ORACLE_SID=+ASM1
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022
export PATH=$PATH:$ORACLE_HOME/rdbms/lib


[grid@18c2 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/18.3/grid
export ORACLE_SID=+ASM2
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022
export PATH=$PATH:$ORACLE_HOME/rdbms/lib

2.17 配置oracle用户环境变量

[oracle@18c1 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/18.3/db
export ORACLE_SID=ora18c1
export ORACLE_UNQNAME=ora18c
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022
export PATH=$PATH:$ORACLE_HOME/rdbms/lib




[oracle@18c2 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/18.3/db
export ORACLE_SID=ora18c2
export ORACLE_UNQNAME=ora18c
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022
export PATH=$PATH:$ORACLE_HOME/rdbms/lib

2.18 配置ASM所需磁盘,编辑/etc/udev/rules.d/99-my-asmdevices.rules配置文件

[root@18c1 ~]# fdisk -l

Disk /dev/sdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000e39cc

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   209715199   104344576   8e  Linux LVM

Disk /dev/mapper/ol-root: 98.4 GB, 98385788928 bytes, 192159744 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/ol-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


[root@18c2 ~]# fdisk -l

Disk /dev/sdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000e39cc

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   209715199   104344576   8e  Linux LVM

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/ol-root: 98.4 GB, 98385788928 bytes, 192159744 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/ol-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


[root@18c1 ~]# /usr/lib/udev/scsi_id -g -u -d /dev/sdb
36000c2900cdc8c5166aa71fdb62b37b1
[root@18c1 ~]# /usr/lib/udev/scsi_id -g -u -d /dev/sdc
36000c2976add1db1089450eb6795b7f1

[root@18c2 ~]# /usr/lib/udev/scsi_id -g -u -d /dev/sdb
36000c2900cdc8c5166aa71fdb62b37b1
[root@18c2 ~]# /usr/lib/udev/scsi_id -g -u -d /dev/sdc
36000c2976add1db1089450eb6795b7f1

[root@18c1 ~]# vi /etc/udev/rules.d/99-my-asmdevices.rules
KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode", RESULT=="36000c2900cdc8c5166aa71fdb62b37b1", RUN+="/bin/sh -c 'mknod /dev/asmdisk01 b $major $minor; chown grid:asmadmin /dev/asmdisk01; chmod 0660 /dev/asmdisk01'"
KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode", RESULT=="36000c2976add1db1089450eb6795b7f1", RUN+="/bin/sh -c 'mknod /dev/asmdisk02 b $major $minor; chown grid:asmadmin /dev/asmdisk02; chmod 0660 /dev/asmdisk02'"


[root@18c2 ~]# vi /etc/udev/rules.d/99-my-asmdevices.rules
KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode", RESULT=="36000c2900cdc8c5166aa71fdb62b37b1", RUN+="/bin/sh -c 'mknod /dev/asmdisk01 b $major $minor; chown grid:asmadmin /dev/asmdisk01; chmod 0660 /dev/asmdisk01'"
KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode", RESULT=="36000c2976add1db1089450eb6795b7f1", RUN+="/bin/sh -c 'mknod /dev/asmdisk02 b $major $minor; chown grid:asmadmin /dev/asmdisk02; chmod 0660 /dev/asmdisk02'"


[root@18c1 ~]# /sbin/udevadm trigger --type=devices --action=change
[root@18c1 ~]# ls -lrt /dev/asm*
brw-rw----. 1 grid asmadmin 8, 32 Sep 14 10:39 /dev/asmdisk02
brw-rw----. 1 grid asmadmin 8, 16 Sep 14 10:39 /dev/asmdisk01

[root@18c2 ~]# /sbin/udevadm trigger --type=devices --action=change
[root@18c2 ~]# ls -lrt /dev/asm*
brw-rw----. 1 grid asmadmin 8, 16 Sep 14 10:39 /dev/asmdisk01
brw-rw----. 1 grid asmadmin 8, 32 Sep 14 10:39 /dev/asmdisk02

三·安装集群软件
3.1解压grid软件

[grid@18c1 ~]$ cd /soft
[grid@18c1 soft]$ ls -lrt
total 9713788
-rw-r--r--. 1 oracle oinstall 4564649047 Mar 31  2019 LINUX.X64_180000_db_home.zip
-rw-r--r--. 1 grid   oinstall 5382265496 Mar 31  2019 LINUX.X64_180000_grid_home.zip

[grid@18c1 soft]$ unzip -q LINUX.X64_180000_grid_home.zip -d $ORACLE_HOME

3.2 安装CVU

[root@18c1 ~]# export CVUQDISK_GRP=oinstall; 
[root@18c1 ~]# rpm -ivh /u01/app/18.3/grid/cv/rpm/cvuqdisk-1.0.10-1.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:cvuqdisk-1.0.10-1                ################################# [100%]

把安装包复件到节点2

[root@18c1 ~]# scp /u01/app/18.3/grid/cv/rpm/cvuqdisk-1.0.10-1.rpm 18c2:~ 
The authenticity of host '18c2 (10.10.13.172)' can't be established.
ECDSA key fingerprint is 33:bd:b1:91:b4:06:6d:e9:5a:e5:1c:e4:8a:98:e3:d8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '18c2,10.10.13.172' (ECDSA) to the list of known hosts.
root@18c2's password: 
cvuqdisk-1.0.10-1.rpm                                                                                                                                                                                    100% 8860     8.7KB/s   00:00    
[root@18c1 ~]# 

[root@18c2 ~]# export CVUQDISK_GRP=oinstall;
[root@18c2 ~]# rpm -ivh cvuqdisk-1.0.10-1.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:cvuqdisk-1.0.10-1                ################################# [100%]

3.3 配置SSH信任
给grid,oracle用户进行配置

[root@18c1 ~]# /u01/app/18.3/grid/oui/prov/resources/scripts/sshUserSetup.sh -user grid  -hosts "18c1 18c2" -advanced exverify -confirm
The output of this script is also logged into /tmp/sshUserSetup_2022-09-14-11-01-04.log
Hosts are 18c1 18c2
user is grid
Platform:- Linux 
Checking if the remote hosts are reachable
PING 18c1 (10.10.13.171) 56(84) bytes of data.
64 bytes from 18c1 (10.10.13.171): icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from 18c1 (10.10.13.171): icmp_seq=2 ttl=64 time=0.020 ms
64 bytes from 18c1 (10.10.13.171): icmp_seq=3 ttl=64 time=0.020 ms
64 bytes from 18c1 (10.10.13.171): icmp_seq=4 ttl=64 time=0.018 ms
64 bytes from 18c1 (10.10.13.171): icmp_seq=5 ttl=64 time=0.037 ms

--- 18c1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.018/0.025/0.037/0.010 ms
PING 18c2 (10.10.13.172) 56(84) bytes of data.
64 bytes from 18c2 (10.10.13.172): icmp_seq=1 ttl=64 time=0.368 ms
64 bytes from 18c2 (10.10.13.172): icmp_seq=2 ttl=64 time=0.170 ms
64 bytes from 18c2 (10.10.13.172): icmp_seq=3 ttl=64 time=0.178 ms
64 bytes from 18c2 (10.10.13.172): icmp_seq=4 ttl=64 time=0.168 ms
64 bytes from 18c2 (10.10.13.172): icmp_seq=5 ttl=64 time=0.157 ms

--- 18c2 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.157/0.208/0.368/0.080 ms
Remote host reachability check succeeded.
The following hosts are reachable: 18c1 18c2.
The following hosts are not reachable: .
All hosts are reachable. Proceeding further...
firsthost 18c1
numhosts 2
The script will setup SSH connectivity from the host 18c1 to all
the remote hosts. After the script is executed, the user can use SSH to run
commands on the remote hosts or copy files between this host 18c1
and the remote hosts without being prompted for passwords or confirmations.

NOTE 1:
As part of the setup procedure, this script will use ssh and scp to copy
files between the local host and the remote hosts. Since the script does not
store passwords, you may be prompted for the passwords during the execution of
the script whenever ssh or scp is invoked.

NOTE 2:
AS PER SSH REQUIREMENTS, THIS SCRIPT WILL SECURE THE USER HOME DIRECTORY
AND THE .ssh DIRECTORY BY REVOKING GROUP AND WORLD WRITE PRIVILEGES TO THESE
directories.

Do you want to continue and let the script make the above mentioned changes (yes/no)?
Confirmation provided on the command line

The user chose yes
Please specify if you want to specify a passphrase for the private key this script will create for the local host. Passphrase is used to encrypt the private key and makes SSH much more secure. Type 'yes' or 'no' and then press enter. In case you press 'yes', you would need to enter the passphrase whenever the script executes ssh or scp. no 
The estimated number of times the user would be prompted for a passphrase is 4. In addition, if the private-public files are also newly created, the user would have to specify the passphrase on one additional occasion. 
Enter 'yes' or 'no'.
yes

The user chose yes
Creating .ssh directory on local host, if not present already
Creating authorized_keys file on local host
Changing permissions on authorized_keys to 644 on local host
Creating known_hosts file on local host
Changing permissions on known_hosts to 644 on local host
Creating config file on local host
If a config file exists already at /root/.ssh/config, it would be backed up to /root/.ssh/config.backup.
Removing old private/public keys on local host
Running SSH keygen on local host
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
passphrase too short: have 4 bytes, need > 4
Generating public/private rsa key pair.
Saving the key failed: /root/.ssh/id_rsa.
Creating .ssh directory and setting permissions on remote host 18c1
THE SCRIPT WOULD ALSO BE REVOKING WRITE PERMISSIONS FOR group AND others ON THE HOME DIRECTORY FOR grid. THIS IS AN SSH REQUIREMENT.
The script would create ~grid/.ssh/config file on remote host 18c1. If a config file exists already at ~grid/.ssh/config, it would be backed up to ~grid/.ssh/config.backup.
The user may be prompted for a password here since the script would be running SSH on host 18c1.
Warning: Permanently added '18c1,10.10.13.171' (ECDSA) to the list of known hosts.
grid@18c1's password: 
Done with creating .ssh directory and setting permissions on remote host 18c1.
Creating .ssh directory and setting permissions on remote host 18c2
THE SCRIPT WOULD ALSO BE REVOKING WRITE PERMISSIONS FOR group AND others ON THE HOME DIRECTORY FOR grid. THIS IS AN SSH REQUIREMENT.
The script would create ~grid/.ssh/config file on remote host 18c2. If a config file exists already at ~grid/.ssh/config, it would be backed up to ~grid/.ssh/config.backup.
The user may be prompted for a password here since the script would be running SSH on host 18c2.
Warning: Permanently added '18c2,10.10.13.172' (ECDSA) to the list of known hosts.
grid@18c2's password: 
Done with creating .ssh directory and setting permissions on remote host 18c2.
Copying local host public key to the remote host 18c1
The user may be prompted for a password or passphrase here since the script would be using SCP for host 18c1.
grid@18c1's password: 
/root/.ssh/id_rsa.pub: No such file or directory
Done copying local host public key to the remote host 18c1
Copying local host public key to the remote host 18c2
The user may be prompted for a password or passphrase here since the script would be using SCP for host 18c2.
grid@18c2's password: 
/root/.ssh/id_rsa.pub: No such file or directory
Done copying local host public key to the remote host 18c2
cat: /root/.ssh/id_rsa.pub: No such file or directory
Creating keys on remote host 18c1 if they do not exist already. This is required to setup SSH on host 18c1.
grid@18c1's password: 
Generating public/private rsa key pair.
Your identification has been saved in .ssh/id_rsa.
Your public key has been saved in .ssh/id_rsa.pub.
The key fingerprint is:
bf:e3:a6:88:97:da:e0:7f:46:6e:9f:1a:c7:9b:a1:35 grid@18c1
The key's randomart image is:
+--[ RSA 1024]----+
|                 |
|                 |
|                 |
|                 |
|        S        |
|        .o       |
|    .  +. E      |
|   . +o.==oB     |
|    +++++*B.     |
+-----------------+
Creating keys on remote host 18c2 if they do not exist already. This is required to setup SSH on host 18c2.
grid@18c2's password: 
Generating public/private rsa key pair.
Your identification has been saved in .ssh/id_rsa.
Your public key has been saved in .ssh/id_rsa.pub.
The key fingerprint is:
ea:df:a7:75:09:21:8e:b2:c3:6d:03:28:c0:03:8c:c6 grid@18c2
The key's randomart image is:
+--[ RSA 1024]----+
|=                |
|+E               |
|oo        . .    |
| ..  .   o . .   |
|  . . o S . .    |
|   . . *     . . |
|      = +   . o  |
|     . o o ...   |
|      ... oo     |
+-----------------+
grid@18c1's password: 
grid@18c2's password: 
Updating authorized_keys file on remote host 18c1
grid@18c1's password: 
Updating known_hosts file on remote host 18c1
grid@18c1's password: 
The script will run SSH on the remote machine 18c1. The user may be prompted for a passphrase here in case the private key has been encrypted with a passphrase.
grid@18c1's password: 
Updating authorized_keys file on remote host 18c2
grid@18c2's password: 
Updating known_hosts file on remote host 18c2
grid@18c2's password: 
The script will run SSH on the remote machine 18c2. The user may be prompted for a passphrase here in case the private key has been encrypted with a passphrase.
grid@18c2's password: 
SSH setup is complete.

------------------------------------------------------------------------
Verifying SSH setup
===================
The script will now run the date command on the remote nodes using ssh
to verify if ssh is setup correctly. IF THE SETUP IS CORRECTLY SETUP,
THERE SHOULD BE NO OUTPUT OTHER THAN THE DATE AND SSH SHOULD NOT ASK FOR
PASSWORDS. If you see any output other than date or are prompted for the
password, ssh is not setup correctly and you will need to resolve the
issue and set up ssh again.
The possible causes for failure could be:
1. The server settings in /etc/ssh/sshd_config file do not allow ssh
for user grid.
2. The server may have disabled public key based authentication.
3. The client public key on the server may be outdated.
4. ~grid or ~grid/.ssh on the remote host may not be owned by grid.
5. User may not have passed -shared option for shared remote users or
may be passing the -shared option for non-shared remote users.
6. If there is output in addition to the date, but no password is asked,
it may be a security alert shown as part of company policy. Append the
additional text to the /sysman/prov/resources/ignoreMessages.txt file.
------------------------------------------------------------------------
--18c1:--
Running /usr/bin/ssh -x -l grid 18c1 date to verify SSH connectivity has been setup from local host to 18c1.
IF YOU SEE ANY OTHER OUTPUT BESIDES THE OUTPUT OF THE DATE COMMAND OR IF YOU ARE PROMPTED FOR A PASSWORD HERE, IT MEANS SSH SETUP HAS NOT BEEN SUCCESSFUL. Please note that being prompted for a passphrase may be OK but being prompted for a password is ERROR.
The script will run SSH on the remote machine 18c1. The user may be prompted for a passphrase here in case the private key has been encrypted with a passphrase.
grid@18c1's password: 
Wed Sep 14 11:03:09 CST 2022
------------------------------------------------------------------------
--18c2:--
Running /usr/bin/ssh -x -l grid 18c2 date to verify SSH connectivity has been setup from local host to 18c2.
IF YOU SEE ANY OTHER OUTPUT BESIDES THE OUTPUT OF THE DATE COMMAND OR IF YOU ARE PROMPTED FOR A PASSWORD HERE, IT MEANS SSH SETUP HAS NOT BEEN SUCCESSFUL. Please note that being prompted for a passphrase may be OK but being prompted for a password is ERROR.
The script will run SSH on the remote machine 18c2. The user may be prompted for a passphrase here in case the private key has been encrypted with a passphrase.
grid@18c2's password: 
Wed Sep 14 11:03:12 CST 2022
------------------------------------------------------------------------
------------------------------------------------------------------------
Verifying SSH connectivity has been setup from 18c1 to 18c1
IF YOU SEE ANY OTHER OUTPUT BESIDES THE OUTPUT OF THE DATE COMMAND OR IF YOU ARE PROMPTED FOR A PASSWORD HERE, IT MEANS SSH SETUP HAS NOT BEEN SUCCESSFUL.
grid@18c1's password: 
Wed Sep 14 11:03:16 CST 2022
------------------------------------------------------------------------
------------------------------------------------------------------------
Verifying SSH connectivity has been setup from 18c1 to 18c2
IF YOU SEE ANY OTHER OUTPUT BESIDES THE OUTPUT OF THE DATE COMMAND OR IF YOU ARE PROMPTED FOR A PASSWORD HERE, IT MEANS SSH SETUP HAS NOT BEEN SUCCESSFUL.
grid@18c1's password: 
Wed Sep 14 11:03:20 CST 2022
------------------------------------------------------------------------
-Verification from complete-
SSH verification complete.




[root@18c1 ~]# /u01/app/18.3/grid/oui/prov/resources/scripts/sshUserSetup.sh -user oracle  -hosts "18c1 18c2" -advanced exverify -confirm
The output of this script is also logged into /tmp/sshUserSetup_2022-09-14-11-04-24.log
Hosts are 18c1 18c2
user is oracle
Platform:- Linux 
Checking if the remote hosts are reachable
PING 18c1 (10.10.13.171) 56(84) bytes of data.
64 bytes from 18c1 (10.10.13.171): icmp_seq=1 ttl=64 time=0.027 ms
64 bytes from 18c1 (10.10.13.171): icmp_seq=2 ttl=64 time=0.025 ms
64 bytes from 18c1 (10.10.13.171): icmp_seq=3 ttl=64 time=0.018 ms
64 bytes from 18c1 (10.10.13.171): icmp_seq=4 ttl=64 time=0.023 ms
64 bytes from 18c1 (10.10.13.171): icmp_seq=5 ttl=64 time=0.016 ms

--- 18c1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 3999ms
rtt min/avg/max/mdev = 0.016/0.021/0.027/0.007 ms
PING 18c2 (10.10.13.172) 56(84) bytes of data.
64 bytes from 18c2 (10.10.13.172): icmp_seq=1 ttl=64 time=0.222 ms
64 bytes from 18c2 (10.10.13.172): icmp_seq=2 ttl=64 time=0.145 ms
64 bytes from 18c2 (10.10.13.172): icmp_seq=3 ttl=64 time=0.141 ms
64 bytes from 18c2 (10.10.13.172): icmp_seq=4 ttl=64 time=0.153 ms
64 bytes from 18c2 (10.10.13.172): icmp_seq=5 ttl=64 time=0.142 ms

--- 18c2 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 3999ms
rtt min/avg/max/mdev = 0.141/0.160/0.222/0.033 ms
Remote host reachability check succeeded.
The following hosts are reachable: 18c1 18c2.
The following hosts are not reachable: .
All hosts are reachable. Proceeding further...
firsthost 18c1
numhosts 2
The script will setup SSH connectivity from the host 18c1 to all
the remote hosts. After the script is executed, the user can use SSH to run
commands on the remote hosts or copy files between this host 18c1
and the remote hosts without being prompted for passwords or confirmations.

NOTE 1:
As part of the setup procedure, this script will use ssh and scp to copy
files between the local host and the remote hosts. Since the script does not
store passwords, you may be prompted for the passwords during the execution of
the script whenever ssh or scp is invoked.

NOTE 2:
AS PER SSH REQUIREMENTS, THIS SCRIPT WILL SECURE THE USER HOME DIRECTORY
AND THE .ssh DIRECTORY BY REVOKING GROUP AND WORLD WRITE PRIVILEGES TO THESE
directories.

Do you want to continue and let the script make the above mentioned changes (yes/no)?
Confirmation provided on the command line

The user chose yes
Please specify if you want to specify a passphrase for the private key this script will create for the local host. Passphrase is used to encrypt the private key and makes SSH much more secure. Type 'yes' or 'no' and then press enter. In case you press 'yes', you would need to enter the passphrase whenever the script executes ssh or scp. no 
The estimated number of times the user would be prompted for a passphrase is 4. In addition, if the private-public files are also newly created, the user would have to specify the passphrase on one additional occasion. 
Enter 'yes' or 'no'.
yes

The user chose yes
Creating .ssh directory on local host, if not present already
Creating authorized_keys file on local host
Changing permissions on authorized_keys to 644 on local host
Creating known_hosts file on local host
Changing permissions on known_hosts to 644 on local host
Creating config file on local host
If a config file exists already at /root/.ssh/config, it would be backed up to /root/.ssh/config.backup.
Removing old private/public keys on local host
Running SSH keygen on local host
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Generating public/private rsa key pair.
Passphrases do not match.  Try again.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
3b:8c:65:92:69:ee:94:70:cf:7d:9b:66:73:12:9b:be root@18c1
The key's randomart image is:
+--[ RSA 1024]----+
|                 |
|                 |
|                 |
|       o         |
|    . * S        |
|     = X o  .    |
|      = * . .+   |
|     o   . .Bo.  |
|      .    +E=   |
+-----------------+
Creating .ssh directory and setting permissions on remote host 18c1
THE SCRIPT WOULD ALSO BE REVOKING WRITE PERMISSIONS FOR group AND others ON THE HOME DIRECTORY FOR oracle. THIS IS AN SSH REQUIREMENT.
The script would create ~oracle/.ssh/config file on remote host 18c1. If a config file exists already at ~oracle/.ssh/config, it would be backed up to ~oracle/.ssh/config.backup.
The user may be prompted for a password here since the script would be running SSH on host 18c1.
Warning: Permanently added '18c1,10.10.13.171' (ECDSA) to the list of known hosts.
oracle@18c1's password: 
Done with creating .ssh directory and setting permissions on remote host 18c1.
Creating .ssh directory and setting permissions on remote host 18c2
THE SCRIPT WOULD ALSO BE REVOKING WRITE PERMISSIONS FOR group AND others ON THE HOME DIRECTORY FOR oracle. THIS IS AN SSH REQUIREMENT.
The script would create ~oracle/.ssh/config file on remote host 18c2. If a config file exists already at ~oracle/.ssh/config, it would be backed up to ~oracle/.ssh/config.backup.
The user may be prompted for a password here since the script would be running SSH on host 18c2.
Warning: Permanently added '18c2,10.10.13.172' (ECDSA) to the list of known hosts.
oracle@18c2's password: 
Done with creating .ssh directory and setting permissions on remote host 18c2.
Copying local host public key to the remote host 18c1
The user may be prompted for a password or passphrase here since the script would be using SCP for host 18c1.
oracle@18c1's password: 
Done copying local host public key to the remote host 18c1
Copying local host public key to the remote host 18c2
The user may be prompted for a password or passphrase here since the script would be using SCP for host 18c2.
oracle@18c2's password: 
Done copying local host public key to the remote host 18c2
Creating keys on remote host 18c1 if they do not exist already. This is required to setup SSH on host 18c1.
Enter passphrase for key '/root/.ssh/id_rsa': 
Generating public/private rsa key pair.
Your identification has been saved in .ssh/id_rsa.
Your public key has been saved in .ssh/id_rsa.pub.
The key fingerprint is:
d6:14:54:7b:fc:11:f3:99:4f:69:b0:66:a8:31:70:0f oracle@18c1
The key's randomart image is:
+--[ RSA 1024]----+
|       . Eo... o |
|        o o..oo B|
|         o.o.+o*o|
|         o+ o..oo|
|        S..     o|
|       .         |
|                 |
|                 |
|                 |
+-----------------+
Creating keys on remote host 18c2 if they do not exist already. This is required to setup SSH on host 18c2.
Enter passphrase for key '/root/.ssh/id_rsa': 
Generating public/private rsa key pair.
Your identification has been saved in .ssh/id_rsa.
Your public key has been saved in .ssh/id_rsa.pub.
The key fingerprint is:
2f:de:18:db:83:fe:6f:e9:1a:59:9f:73:82:9f:62:31 oracle@18c2
The key's randomart image is:
+--[ RSA 1024]----+
|                 |
|                 |
|                 |
|                 |
|        S   .    |
|         . oEo . |
|        o.+ .+= .|
|       ..B..=. = |
|       .=.=Bo.o  |
+-----------------+
Enter passphrase for key '/root/.ssh/id_rsa': 
Enter passphrase for key '/root/.ssh/id_rsa': 
Updating authorized_keys file on remote host 18c1
Enter passphrase for key '/root/.ssh/id_rsa': 
Updating known_hosts file on remote host 18c1
Enter passphrase for key '/root/.ssh/id_rsa': 
The script will run SSH on the remote machine 18c1. The user may be prompted for a passphrase here in case the private key has been encrypted with a passphrase.
Enter passphrase for key '/root/.ssh/id_rsa': 
Updating authorized_keys file on remote host 18c2
Enter passphrase for key '/root/.ssh/id_rsa': 
Updating known_hosts file on remote host 18c2
Enter passphrase for key '/root/.ssh/id_rsa': 
The script will run SSH on the remote machine 18c2. The user may be prompted for a passphrase here in case the private key has been encrypted with a passphrase.
Enter passphrase for key '/root/.ssh/id_rsa': 
SSH setup is complete.

------------------------------------------------------------------------
Verifying SSH setup
===================
The script will now run the date command on the remote nodes using ssh
to verify if ssh is setup correctly. IF THE SETUP IS CORRECTLY SETUP,
THERE SHOULD BE NO OUTPUT OTHER THAN THE DATE AND SSH SHOULD NOT ASK FOR
PASSWORDS. If you see any output other than date or are prompted for the
password, ssh is not setup correctly and you will need to resolve the
issue and set up ssh again.
The possible causes for failure could be:
1. The server settings in /etc/ssh/sshd_config file do not allow ssh
for user oracle.
2. The server may have disabled public key based authentication.
3. The client public key on the server may be outdated.
4. ~oracle or ~oracle/.ssh on the remote host may not be owned by oracle.
5. User may not have passed -shared option for shared remote users or
may be passing the -shared option for non-shared remote users.
6. If there is output in addition to the date, but no password is asked,
it may be a security alert shown as part of company policy. Append the
additional text to the /sysman/prov/resources/ignoreMessages.txt file.
------------------------------------------------------------------------
--18c1:--
Running /usr/bin/ssh -x -l oracle 18c1 date to verify SSH connectivity has been setup from local host to 18c1.
IF YOU SEE ANY OTHER OUTPUT BESIDES THE OUTPUT OF THE DATE COMMAND OR IF YOU ARE PROMPTED FOR A PASSWORD HERE, IT MEANS SSH SETUP HAS NOT BEEN SUCCESSFUL. Please note that being prompted for a passphrase may be OK but being prompted for a password is ERROR.
The script will run SSH on the remote machine 18c1. The user may be prompted for a passphrase here in case the private key has been encrypted with a passphrase.
Enter passphrase for key '/root/.ssh/id_rsa': 
Wed Sep 14 11:06:55 CST 2022
------------------------------------------------------------------------
--18c2:--
Running /usr/bin/ssh -x -l oracle 18c2 date to verify SSH connectivity has been setup from local host to 18c2.
IF YOU SEE ANY OTHER OUTPUT BESIDES THE OUTPUT OF THE DATE COMMAND OR IF YOU ARE PROMPTED FOR A PASSWORD HERE, IT MEANS SSH SETUP HAS NOT BEEN SUCCESSFUL. Please note that being prompted for a passphrase may be OK but being prompted for a password is ERROR.
The script will run SSH on the remote machine 18c2. The user may be prompted for a passphrase here in case the private key has been encrypted with a passphrase.
Enter passphrase for key '/root/.ssh/id_rsa': 
Wed Sep 14 11:07:00 CST 2022
------------------------------------------------------------------------
------------------------------------------------------------------------
Verifying SSH connectivity has been setup from 18c1 to 18c1
IF YOU SEE ANY OTHER OUTPUT BESIDES THE OUTPUT OF THE DATE COMMAND OR IF YOU ARE PROMPTED FOR A PASSWORD HERE, IT MEANS SSH SETUP HAS NOT BEEN SUCCESSFUL.
Enter passphrase for key '/root/.ssh/id_rsa': 
Wed Sep 14 11:07:06 CST 2022
------------------------------------------------------------------------
------------------------------------------------------------------------
Verifying SSH connectivity has been setup from 18c1 to 18c2
IF YOU SEE ANY OTHER OUTPUT BESIDES THE OUTPUT OF THE DATE COMMAND OR IF YOU ARE PROMPTED FOR A PASSWORD HERE, IT MEANS SSH SETUP HAS NOT BEEN SUCCESSFUL.
Enter passphrase for key '/root/.ssh/id_rsa': 
Wed Sep 14 11:07:12 CST 2022
------------------------------------------------------------------------
-Verification from complete-
SSH verification complete.


[root@18c1 ~]# su - grid
Last login: Wed Sep 14 10:52:12 CST 2022 on pts/0
[grid@18c1 ~]$ ssh 18c2 date
Wed Sep 14 11:08:23 CST 2022
[grid@18c1 ~]$ ssh 18c1 date
Wed Sep 14 11:08:30 CST 2022
[grid@18c1 ~]$ exit
logout
[root@18c1 ~]# su - oracle
Last login: Wed Sep 14 10:34:49 CST 2022 on pts/0
[oracle@18c1 ~]$ ssh 18c2 date
Wed Sep 14 11:08:43 CST 2022
[oracle@18c1 ~]$ ssh 18c1 date
Wed Sep 14 11:08:48 CST 2022

[grid@18c2 ~]$ ssh 18c1 date
Wed Sep 14 11:09:13 CST 2022
[grid@18c2 ~]$ ssh 18c2 date
Wed Sep 14 11:09:17 CST 2022
[grid@18c2 ~]$ exit
logout
[root@18c2 ~]# su - oracle
Last login: Wed Sep 14 10:36:22 CST 2022 on pts/0
[oracle@18c2 ~]$ ssh 18c1 date
Wed Sep 14 11:09:33 CST 2022
[oracle@18c2 ~]$ ssh 18c2 date
Wed Sep 14 11:09:41 CST 2022

3.4 安装前环境检查GI

[grid@18c1 ~]$ $ORACLE_HOME/runcluvfy.sh  stage -pre crsinst -n  "18c1,18c2"  -fixup -verbose

根据提示修复检查的问题

[root@18c1 ~]# /u01/tmp/CVU_18.0.0.0.0_grid/runfixup.sh
All Fix-up operations were completed successfully.

[root@18c2 ~]# /u01/tmp/CVU_18.0.0.0.0_grid/runfixup.sh
All Fix-up operations were completed successfully.

3.5开始安装Grid软件

[grid@18c1 ~]$ vi grid.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_crsinstall_response_schema_v18.0.0
INVENTORY_LOCATION=/u01/app/oraInventory
oracle.install.option=CRS_CONFIG
ORACLE_BASE=/u01/app/grid
oracle.install.asm.OSDBA=asmdba
oracle.install.asm.OSOPER=asmoper
oracle.install.asm.OSASM=asmadmin
oracle.install.crs.config.scanType=LOCAL_SCAN
oracle.install.crs.config.gpnp.scanName=scan-18c
oracle.install.crs.config.gpnp.scanPort=1521
oracle.install.crs.config.ClusterConfiguration=STANDALONE
oracle.install.crs.config.configureAsExtendedCluster=false
oracle.install.crs.config.clusterName=ora18c-cluster
oracle.install.crs.config.gpnp.configureGNS=false
oracle.install.crs.config.autoConfigureClusterNodeVIP=false
oracle.install.crs.config.clusterNodes=18c1:18c1-vip:HUB,18c2:18c2-vip:HUB
oracle.install.crs.config.networkInterfaceList=ens33:88.88.87.0:5,ens32:10.10.13.0:1
oracle.install.asm.configureGIMRDataDG=false
oracle.install.crs.config.useIPMI=false
oracle.install.asm.storageOption=ASM
oracle.install.asmOnNAS.configureGIMRDataDG=false
oracle.install.asm.SYSASMPassword=xxzx7817600
oracle.install.asm.diskGroup.name=OCR
oracle.install.asm.diskGroup.redundancy=EXTERNAL
oracle.install.asm.diskGroup.AUSize=4
oracle.install.asm.diskGroup.disks=/dev/asmdisk01
oracle.install.asm.diskGroup.diskDiscoveryString=/dev/asm*
oracle.install.asm.configureAFD=false
oracle.install.asm.monitorPassword=xxzx7817600
oracle.install.crs.configureRHPS=false
oracle.install.crs.config.ignoreDownNodes=false
oracle.install.config.managementOption=NONE
oracle.install.config.omsPort=0
oracle.install.crs.rootconfig.executeRootScript=false

[grid@18c1 ~]$ $ORACLE_HOME/gridSetup.sh -silent -force -noconfig -waitforcompletion -ignorePrereq -responseFile /home/grid/grid.rsp
Launching Oracle Grid Infrastructure Setup Wizard...

[WARNING] [INS-30011] The SYS password entered does not conform to the Oracle recommended standards.
   CAUSE: Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
   ACTION: Provide a password that conforms to the Oracle recommended standards.
[WARNING] [INS-30011] The ASMSNMP password entered does not conform to the Oracle recommended standards.
   CAUSE: Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
   ACTION: Provide a password that conforms to the Oracle recommended standards.
[WARNING] [INS-40109] The specified Oracle Base location is not empty on this server.
   ACTION: Specify an empty location for Oracle Base.
[WARNING] [INS-13013] Target environment does not meet some mandatory requirements.
   CAUSE: Some of the mandatory prerequisites are not met. See logs for details. /u01/tmp/GridSetupActions2022-09-14_11-40-40AM/gridSetupActions2022-09-14_11-40-40AM.log
   ACTION: Identify the list of failed prerequisite checks from the log: /u01/tmp/GridSetupActions2022-09-14_11-40-40AM/gridSetupActions2022-09-14_11-40-40AM.log. Then either from the log file or from installation manual find the appropriate configuration to meet the prerequisites and fix it manually.
The response file for this session can be found at:
 /u01/app/18.3/grid/install/response/grid_2022-09-14_11-40-40AM.rsp

You can find the log of this install session at:
 /u01/tmp/GridSetupActions2022-09-14_11-40-40AM/gridSetupActions2022-09-14_11-40-40AM.log

As a root user, execute the following script(s):
        1. /u01/app/oraInventory/orainstRoot.sh
        2. /u01/app/18.3/grid/root.sh

Execute /u01/app/oraInventory/orainstRoot.sh on the following nodes: 
[18c1, 18c2]
Execute /u01/app/18.3/grid/root.sh on the following nodes: 
[18c1, 18c2]

Run the script on the local node first. After successful completion, you can start the script in parallel on all other nodes.

Successfully Setup Software with warning(s).
As install user, execute the following command to complete the configuration.
        /u01/app/18.3/grid/gridSetup.sh -executeConfigTools -responseFile /home/grid/grid.rsp [-silent]


Moved the install session logs to:
 /u01/app/oraInventory/logs/GridSetupActions2022-09-14_11-40-40AM

节点一 执行root脚本

[root@18c1 /]# /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@18c1 /]# /u01/app/18.3/grid/root.sh
Check /u01/app/18.3/grid/install/root_18c1_2022-09-14_12-06-17-524505190.log for the output of root script

节点二 执行root脚本

[root@18c2 /]# /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@18c2 /]# /u01/app/18.3/grid/root.sh
Check /u01/app/18.3/grid/install/root_18c2_2022-09-14_12-26-02-499327120.log for the output of root script

[grid@18c1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ASMNET1LSNR_ASM.lsnr
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER.lsnr
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.OCR.GHCHKPT.advm
               OFFLINE OFFLINE      18c1                     STABLE
               OFFLINE OFFLINE      18c2                     STABLE
ora.OCR.dg
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.helper
               OFFLINE OFFLINE      18c1                     STABLE
               OFFLINE OFFLINE      18c2                     IDLE,STABLE
ora.net1.network
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.ocr.ghchkpt.acfs
               OFFLINE OFFLINE      18c1                     volume /opt/oracle/r
                                                             hp_images/chkbase is
                                                             unmounted,STABLE
               OFFLINE OFFLINE      18c2                     STABLE
ora.ons
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.proxy_advm
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.18c1.vip
      1        ONLINE  ONLINE       18c1                     STABLE
ora.18c2.vip
      1        ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       18c1                     STABLE
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       18c1                     STABLE
ora.MGMTLSNR
      1        OFFLINE OFFLINE                               STABLE
ora.asm
      1        ONLINE  ONLINE       18c1                     Started,STABLE
      2        ONLINE  ONLINE       18c2                     Started,STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.cvu
      1        ONLINE  ONLINE       18c1                     STABLE
ora.qosmserver
      1        ONLINE  ONLINE       18c1                     STABLE
ora.rhpserver
      1        OFFLINE OFFLINE                               STABLE
ora.scan1.vip
      1        ONLINE  ONLINE       18c2                     STABLE
ora.scan2.vip
      1        ONLINE  ONLINE       18c1                     STABLE
ora.scan3.vip
      1        ONLINE  ONLINE       18c1                     STABLE
--------------------------------------------------------------------------------

3.6创建ASM磁盘组

[grid@18c1 ~]$ sqlplus / as sysasm

SQL*Plus: Release 18.0.0.0.0 - Production on Wed Sep 14 14:53:11 2022
Version 18.3.0.0.0

Copyright (c) 1982, 2018, Oracle.  All rights reserved.


Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0

SQL> create diskgroup DATA external REDUNDANCY disk '/dev/asmdisk02' ATTRIBUTE 'au_size'='4M', 'compatible.rdbms' = '18.0', 'compatible.asm' = '18.0';

Diskgroup created.

节点二执行挂载

[grid@18c2 ~]$ sqlplus / as sysasm

SQL*Plus: Release 18.0.0.0.0 - Production on Wed Sep 14 14:52:53 2022
Version 18.3.0.0.0

Copyright (c) 1982, 2018, Oracle.  All rights reserved.


Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0

SQL> alter diskgroup data mount;

Diskgroup altered.


[grid@18c1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ASMNET1LSNR_ASM.lsnr
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.DATA.dg
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER.lsnr
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.OCR.GHCHKPT.advm
               OFFLINE OFFLINE      18c1                     STABLE
               OFFLINE OFFLINE      18c2                     STABLE
ora.OCR.dg
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.helper
               OFFLINE OFFLINE      18c1                     STABLE
               OFFLINE OFFLINE      18c2                     IDLE,STABLE
ora.net1.network
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.ocr.ghchkpt.acfs
               OFFLINE OFFLINE      18c1                     volume /opt/oracle/r
                                                             hp_images/chkbase is
                                                             unmounted,STABLE
               OFFLINE OFFLINE      18c2                     STABLE
ora.ons
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.proxy_advm
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.18c1.vip
      1        ONLINE  ONLINE       18c1                     STABLE
ora.18c2.vip
      1        ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       18c1                     STABLE
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       18c1                     STABLE
ora.MGMTLSNR
      1        OFFLINE OFFLINE                               STABLE
ora.asm
      1        ONLINE  ONLINE       18c1                     Started,STABLE
      2        ONLINE  ONLINE       18c2                     Started,STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.cvu
      1        ONLINE  ONLINE       18c1                     STABLE
ora.qosmserver
      1        ONLINE  ONLINE       18c1                     STABLE
ora.rhpserver
      1        OFFLINE OFFLINE                               STABLE
ora.scan1.vip
      1        ONLINE  ONLINE       18c2                     STABLE
ora.scan2.vip
      1        ONLINE  ONLINE       18c1                     STABLE
ora.scan3.vip
      1        ONLINE  ONLINE       18c1                     STABLE
--------------------------------------------------------------------------------

四·安装数据库软件
4.1 解压安装包

[oracle@18c1 ~]$ cd /soft
[oracle@18c1 soft]$ ls -lrt
total 9713788
-rw-r--r--. 1 oracle oinstall 4564649047 Mar 31  2019 LINUX.X64_180000_db_home.zip
-rw-r--r--. 1 grid   oinstall 5382265496 Mar 31  2019 LINUX.X64_180000_grid_home.zip

[oracle@18c1 soft]$ unzip -q LINUX.X64_180000_db_home.zip -d $ORACLE_HOME

4.2安装前检查

[grid@18c1 ~]$ORACLE_HOME/runcluvfy.sh stage -pre dbinst -n  "18c1,18c2"  -fixup -verbose
......
Execute "/u01/tmp/CVU_18.0.0.0.0_grid/runfixup.sh" as root user on nodes "18c2,18c1" to perform the fix up operations manually

Press ENTER key to continue after execution of "/u01/tmp/CVU_18.0.0.0.0_grid/runfixup.sh" has completed on nodes "18c2,18c1"

Fix: Group Membership: dba 

  Node Name                             Status                  
  ------------------------------------  ------------------------
  18c2                                  failed                  
  18c1                                  failed                  

ERROR: 
18c2: PRVG-9023 : Manual fix up command "/u01/tmp/CVU_18.0.0.0.0_grid/runfixup.sh" was not issued by root user on node "18c2"

18c1: PRVG-9023 : Manual fix up command "/u01/tmp/CVU_18.0.0.0.0_grid/runfixup.sh" was not issued by root user on node "18c1"

Result: 
"Group Membership: dba" could not be fixed on nodes "18c2,18c1"

Fix up operations for selected fixable prerequisites were unsuccessful on nodes "18c2,18c1"


[root@18c1 ~]# /u01/tmp/CVU_18.0.0.0.0_grid/runfixup.sh
All Fix-up operations were completed successfully.


[root@18c2 ~]# /u01/tmp/CVU_18.0.0.0.0_grid/runfixup.sh
All Fix-up operations were completed successfully.

4.3编写响应文件

[oracle@18c1 ~]$ vi dbinstall.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v18.0.0
oracle.install.option=INSTALL_DB_SWONLY
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oraInventory
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/18.3/db
oracle.install.db.InstallEdition=EE
oracle.install.db.OSDBA_GROUP=dba
oracle.install.db.OSOPER_GROUP=oper
oracle.install.db.OSBACKUPDBA_GROUP=backupdba
oracle.install.db.OSDGDBA_GROUP=dgdba
oracle.install.db.OSKMDBA_GROUP=kmdba
oracle.install.db.OSRACDBA_GROUP=racdba
oracle.install.db.CLUSTER_NODES=18c1,18c2
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE

[oracle@18c1 ~]$ $ORACLE_HOME/runInstaller -silent  -force -noconfig  -ignorePrereq -responseFile /home/oracle/dbinstall.rsp
Launching Oracle Database Setup Wizard...

[WARNING] [INS-13013] Target environment does not meet some mandatory requirements.
   CAUSE: Some of the mandatory prerequisites are not met. See logs for details. /u01/app/oraInventory/logs/InstallActions2022-09-14_01-09-17PM/installActions2022-09-14_01-09-17PM.log
   ACTION: Identify the list of failed prerequisite checks from the log: /u01/app/oraInventory/logs/InstallActions2022-09-14_01-09-17PM/installActions2022-09-14_01-09-17PM.log. Then either from the log file or from installation manual find the appropriate configuration to meet the prerequisites and fix it manually.
The response file for this session can be found at:
 /u01/app/oracle/product/18.3/db/install/response/db_2022-09-14_01-09-17PM.rsp

You can find the log of this install session at:
 /u01/app/oraInventory/logs/InstallActions2022-09-14_01-09-17PM/installActions2022-09-14_01-09-17PM.log

As a root user, execute the following script(s):
        1. /u01/app/oracle/product/18.3/db/root.sh

Execute /u01/app/oracle/product/18.3/db/root.sh on the following nodes: 
[18c1, 18c2]


Successfully Setup Software with warning(s).

4.4执行root.sh脚本

[root@18c1 oracle]# /u01/app/oracle/product/18.3/db/root.sh
Check /u01/app/oracle/product/18.3/db/install/root_18c1_2022-09-14_14-17-43-907653393.log for the output of root script
[root@18c1 oracle]# cat /u01/app/oracle/product/18.3/db/install/root_18c1_2022-09-14_14-17-43-907653393.log
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/product/18.3/db
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...

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.

[root@18c2 18.3]# /u01/app/oracle/product/18.3/db/root.sh
Check /u01/app/oracle/product/18.3/db/install/root_18c2_2022-09-14_14-17-49-252045874.log for the output of root script
[root@18c2 18.3]# cat /u01/app/oracle/product/18.3/db/install/root_18c2_2022-09-14_14-17-49-252045874.log
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/product/18.3/db
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...

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.

五·创建数据库

[oracle@18c1 ~]$ vi dbca.rsp
responseFileVersion=/oracle/assistants/rspfmt_dbca_response_schema_v12.2.0
templateName=General_Purpose.dbc
gdbName=ora18c
sid=ora18c
databaseConfigType=RAC
responseFile=NO_VALUE
characterSet=ZHS16GBK
nationalCharacterSet=AL16UTF16
sysPassword=xxzx7817600
systemPassword=xxzx7817600
createAsContainerDatabase=true
numberOfPDBs=1
pdbName=ora18cpdb
useLocalUndoForPDBs=TRUE
pdbAdminPassword=xxzx7817600
databaseType=MULTIPURPOSE
automaticMemoryManagement=false
totalMemory=3072
redoLogFileSize=50
emConfiguration=NONE
nodelist=18c1,18c2
storageType=ASM
diskGroupName=+DATA
datafileDestination=+DATA
asmsnmpPassword=xxzx7817600
sampleSchema=TRUE

[oracle@18c1 ~]$ dbca -ignorePreReqs -silent  -createDatabase   -responseFile /home/oracle/dbca.rsp
[WARNING] [DBT-06208] The 'SYS' password entered does not conform to the Oracle recommended standards.
   CAUSE: 
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
   ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
[WARNING] [DBT-06208] The 'SYSTEM' password entered does not conform to the Oracle recommended standards.
   CAUSE: 
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
   ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
[WARNING] [DBT-06208] The 'PDBADMIN' password entered does not conform to the Oracle recommended standards.
   CAUSE: 
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
   ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
Prepare for db operation
7% complete
Copying database files
27% complete
Creating and starting Oracle instance
28% complete
31% complete
35% complete
37% complete
40% complete
Creating cluster database views
41% complete
53% complete
Completing Database Creation
57% complete
59% complete
60% complete
Creating Pluggable Databases
64% complete
80% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
 /u01/app/oracle/cfgtoollogs/dbca/ora18c.
Database Information:
Global Database Name:ora18c
System Identifier(SID) Prefix:ora18c
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/ora18c/ora18c.log" for further details.

[grid@18c1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ASMNET1LSNR_ASM.lsnr
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.DATA.dg
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER.lsnr
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.OCR.GHCHKPT.advm
               OFFLINE OFFLINE      18c1                     STABLE
               OFFLINE OFFLINE      18c2                     STABLE
ora.OCR.dg
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.helper
               OFFLINE OFFLINE      18c1                     STABLE
               OFFLINE OFFLINE      18c2                     IDLE,STABLE
ora.net1.network
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.ocr.ghchkpt.acfs
               OFFLINE OFFLINE      18c1                     volume /opt/oracle/r
                                                             hp_images/chkbase is
                                                             unmounted,STABLE
               OFFLINE OFFLINE      18c2                     STABLE
ora.ons
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.proxy_advm
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.18c1.vip
      1        ONLINE  ONLINE       18c1                     STABLE
ora.18c2.vip
      1        ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       18c1                     STABLE
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       18c1                     STABLE
ora.MGMTLSNR
      1        OFFLINE OFFLINE                               STABLE
ora.asm
      1        ONLINE  ONLINE       18c1                     Started,STABLE
      2        ONLINE  ONLINE       18c2                     Started,STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.cvu
      1        ONLINE  ONLINE       18c1                     STABLE
ora.ora18c.db
      1        ONLINE  ONLINE       18c1                     Open,HOME=/u01/app/o
                                                             racle/product/18.3/d
                                                             b,STABLE
      2        ONLINE  ONLINE       18c2                     Open,HOME=/u01/app/o
                                                             racle/product/18.3/d
                                                             b,STABLE
ora.qosmserver
      1        ONLINE  ONLINE       18c1                     STABLE
ora.rhpserver
      1        OFFLINE OFFLINE                               STABLE
ora.scan1.vip
      1        ONLINE  ONLINE       18c2                     STABLE
ora.scan2.vip
      1        ONLINE  ONLINE       18c1                     STABLE
ora.scan3.vip
      1        ONLINE  ONLINE       18c1                     STABLE
--------------------------------------------------------------------------------

也可以不指定响应文件直接使用命令行参数来执行

[oracle@18c1 ~]$ dbca -ignorePreReqs -silent -createDatabase -templateName General_Purpose.dbc -gdbName ora18c -sid ora18c -createAsContainerDatabase true -numberOfPDBs 1 -pdbName  ora18cpdb -pdbAdminPassword xxzx7817600 -sysPassword xxzx7817600 -systemPassword xxzx7817600 -datafileDestination 'data/' -redoLogFileSize 50   -storageType ASM  -responseFile NO_VALUE  -characterset ZHS16GBK -nationalCharacterSet AL16UTF16    -sampleSchema  true -automaticMemoryManagement false -totalMemory 3072 -databaseType MULTIPURPOSE -nodelist 18c1,18c2 -listeners ASMNET1LSNR_ASM,LISTENER,LISTENER_SCAN2
[WARNING] [DBT-06208] The 'SYS' password entered does not conform to the Oracle recommended standards.
   CAUSE: 
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
   ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
[WARNING] [DBT-06208] The 'SYSTEM' password entered does not conform to the Oracle recommended standards.
   CAUSE: 
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
   ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
[WARNING] [DBT-06208] The 'PDBADMIN' password entered does not conform to the Oracle recommended standards.
   CAUSE: 
a. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
b.The password entered is a keyword that Oracle does not recommend to be used as password
   ACTION: Specify a strong password. If required refer Oracle documentation for guidelines.
Prepare for db operation
7% complete
Copying database files
27% complete
Creating and starting Oracle instance
28% complete
31% complete
35% complete
37% complete
40% complete
Creating cluster database views
41% complete
53% complete
Completing Database Creation
57% complete
59% complete
60% complete
Creating Pluggable Databases
64% complete
80% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
 /u01/app/oracle/cfgtoollogs/dbca/ora18c.
Database Information:
Global Database Name:ora18c
System Identifier(SID) Prefix:ora18c
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/ora18c/ora18c.log" for further details.

测试连接

[oracle@18c1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 18.0.0.0.0 - Production on Wed Sep 14 15:32:38 2022
Version 18.3.0.0.0

Copyright (c) 1982, 2018, Oracle.  All rights reserved.


Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0

SQL> desc v$version;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 BANNER                                             VARCHAR2(80)
 BANNER_FULL                                        VARCHAR2(160)
 BANNER_LEGACY                                      VARCHAR2(80)
 CON_ID                                             NUMBER



SQL> select * from v$version;

BANNER                                                                           BANNER_FULL                                                                                                                                                BANNER_LEGACY                                                                 CON_ID
-------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----------
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production           Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production                                                                                     Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production             0
                                                                                 Version 18.3.0.0.0


SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORA18CPDB                      READ WRITE NO

Oracle索引访问路径因没有新的统计信息而改变

索引访问路径因没有新的统计信息而改变
在生产环境中,同一个查询的执行路径经常变化,甚至在没有任何相关变化的情况下也是如此。你确认没有收集新的统计信息(事实上,你甚至可能已经锁定了统计信息,以防止执行计划的变化)。在Oracle Database 11g之前的版本中,基数据反馈功能和自动查询调优功能,如果没有任何东西真正改变(即统计信息,实例参数等),对目前直方图的绑定窥视之类的东西没有起作用,那么执行计划几乎保持不变。然而,尽管你绝对肯定优化器不应该改变任何的执行计划,但它确实改变了。这怎么可能呢,嗯,大多数数据库都是“活体”,由于不断进行的交易数据而不断变化。事实上,如果基础数据发生了重大修改,但没有收集新的统计信息以反映这些变化,因为优化器根据不同访问路径的成本做出决定,而成本可能因为数据的变化而改变,所以执行可能将改变。

如果不随着数据的变化对优化器统计信息进行更新,在某些情况下,优化器将很可能错误地估计基数,也就是预期查询返回的行数。如果应用程序往表中添加了大量数据,而没有收集新的统计信息,你可能会认为,因为优化器不知道有新的数据,所以它会继续使用原来的执行计划(计划目前有效)。实际上,如果基于成本的优化器算错了查询真正的选择性和基数,那么随首时间的推移,它有时会改变其执行计划。在输入数量非常大的新数据后,为了执行相同的查询,优化器可能使用不同的计划,因为它低估了查询现在将检索的行数。如果在加入大量的数据之前,全表扫描是最优策略,那么在加入另外的数据后,优化器可能误以为使用索引效果会更好,而实际上全表扫描可能仍然是最好的方法。

1 使用不等条件
使用不等条件的语句,比如select * from emp where department_id<>10有时可能会导致优化器不使用索引。原因是如果优化器猜测某个查询将从表中选择大多数的值,它往往就不会使用索引。如果是这种情况,对表执行全表扫描可能是更有效的。通常情况下,优化器使用公式(1-(1/num_distinct))* num_rows估算基数。换句话说,如果某个列有1000行,其中不同的值有4个,那么基数为750。我们假设,表中大部分行满足为不等条件指定的值。在这种情况下,你可能会认为优化器会使用索引扫描,因为,毕竟所要检索的是不包含在不等条件中指定的值的所有行。然而,在指定<>操作符时,优化器会简单地忽略任何可能有的索引,即使数据分布不均,且<>条件将导致检索表中很小一部分行也是如此。在这种情况下,优化器只是倾向于执行全表扫描,而不是”正确“地选择索引。

运行这个例子中的查询,结果如下:

SQL> select * from emp where department_id<>10;

105 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |   105 |  7245 |     3   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| EMP  |   105 |  7245 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("DEPARTMENT_ID"<>10)

<>子句导致优化器跳过department_id列上的索引。可以尝试用index提供示强制使用索引,如下所示:

SQL> select /*+ index(emp,dept_idx) */ * from emp where department_id<>10;

105 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 169023637

------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |          |   105 |  7245 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| EMP      |   105 |  7245 |     2   (0)| 00:00:01 |
|*  2 |   INDEX FULL SCAN                   | DEPT_IDX |   104 |       |     1   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - filter("DEPARTMENT_ID"<>10)

index提示使优化器用全索引扫描替换了全表扫描,虽然这是较好的,但不如索引范围扫描那么好。全索引扫描必须读取包含<>操作符中指定的值的所有叶节点,因此它不是非常有效的方法。(然而,在其他情况下,优化器可能会因为指定index提示而执行索引范围扫描。)指定<>条件的问题是,优化器甚至可能在查询返回表中很小一部分行时也跳过索引,它只是忽略where谓词中出现的列的索引。忽略索引意味着优化器在生成”最优“的计划之前,甚至不会计算索引扫描的成本,它认为这样会节省所有因此(计算索引扫描成本)花费的开销,因为它假设<>条件将导致提取表中很大一部分行。在这样的情况下,可以尝试重写查询以避免使用<>运算符。

注意:无法强制数据库执行并行索引范围扫描。但是,数据库在执行燕行嵌套循环连接时,确实执行了并行索引查找。

这里的唯一选择就是重写查询,以消除不等于子句。如果有多个谓词需要处理,就更有必要这么做。请记住,当指定not in子句时,优化器的行为与指定不等于子句是相同的。在某些情况下,另一个很好的解决方案是用case结构取代不等于谓词。请记住,如果使用case结构,那么还需要与之相匹配的基于函数的索引。

2 使用通配符查询
如果执行一个包含前导通配符搜索的查询,优化器可能会忽略索引而执行全表扫描。例如对于下面的查询:

SQL> select * from emp where last_name like '%hen';

如果匹配模式中的前导字符不是”%“或下划线(_),优化器更有可能使用索引。like运算符的初始字符使用通配符”%“或”_”,意味着数据库可能必须读取表中大部分行。如果使用索引,也需要访问每个索引块,对索引的读取完成后,可能还需要扫描大多数的表块。在这种情况下,全表扫描可能会更有效。优化器跳过last_name列的索引,因为它必须检查列中的每个值,以确定这些值是否以”hen”值结束。它最后选择了全表扫描,如下面语句的解释计划所示:

SQL> select * from emp where last_name like '%hen';


Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     5 |   345 |     3   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| EMP  |     5 |   345 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("LAST_NAME" LIKE '%hen')

如果把上述语句修改为如下所示的语句,优化器就选择了索引扫描。

SQL> select * from emp where last_name like 'hen%';

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 2522206107

-----------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |               |     1 |    69 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| EMP           |     1 |    69 |     1   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN                  | EMP_LAST_NAME |     1 |       |     1   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("LAST_NAME" LIKE 'hen%')
       filter("LAST_NAME" LIKE 'hen%')

请注意,第一个例子使用前导通配符搜索。事实上,为了强制使用索引,在这个例子中,只要把通配符(%)从前导位置向后移动哪怕一个字符的位置(select * from emp where last_name like ‘h%en%),都会使用优化器使用emp表中的emp_last_name索引。我们经常使用这个例子演示,在搜索字符串中推迟使用通配符不会阻止使用索引。那么,在“%”前有多少字符就将允许使用该索引呢?当额外的字符被添加到搜索字符串中通配符(%)规范前时,优化器自然会预计该数据库将读取更少的索引和表中更少的行,因此它更倾向于选择使用索引。因此,如果搜索“ABC%”,而不是“%ABC”,那么数据库将更有可能使用索引范围扫描,因为它意识到,这时采用全表扫描的成本更高。

3 在谓词中引用空值
假设有个只有两列的表,这两列都允许NULL值。我们还假设,事实上,表中有几行在两列中都是NULL。如果执行以下语句:

SQL> select * from mytable where a is null;

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 1015944200

-----------------------------------------------------------------------------
| Id  | Operation         | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |         |     1 |    26 |     2   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| MYTABLE |     1 |    26 |     2   (0)| 00:00:01 |
-----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("A" IS NULL)

数据库的优化器将不会使用此表上的唯一索引,因为假设有一行数据,它的某个唯一索引的所有列都是NULL值,数据库允许把这样的行添加到表中,但不会把它包括在索引中。事实上,即使表上有唯一索引,也可以向表中添加所有列都是NULL值的多少行,因为Oracle数据库认为所有列都是NULL值的两行是不同的,所以认为它们仍然符合唯一性。其结果是该表将比索引有更多的行,因为所有列都是NULL值的行不会被插入到索引中。当执行先前的查询时,数据库忽略了索引,因为该索引不包括所有的列都是NULL值的行。为了避免得出错误的答案,该数据库忽略了索引。

在这个例子中,让数据库使用索引的唯一方法是,确保在此表的两列中至少有一列被定义为

SQL> create table mytab1(a int,b int not null);

Table created.

SQL> create unique index mytab1_idx on mytab1(a,b);

Index created.

SQL> select * from mytab1 where a is null;

no rows selected


Execution Plan
----------------------------------------------------------
Plan hash value: 3315145109

-------------------------------------------------------------------------------
| Id  | Operation        | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |            |     1 |    26 |     1   (0)| 00:00:01 |
|*  1 |  INDEX RANGE SCAN| MYTAB1_IDX |     1 |    26 |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("A" IS NULL)

如果某行所有的索引列都是空的,Oracle数据库就不会把该行包含到索引中。然而,实际上可以简单地增加另一列到索引中,对NULL值进行索引,
如下所示:

SQL>create index with_null on employees(nullable_column,'1');

4 在查询中包含函数
如果某个查询在where子句中包含索引列上的函数,优化器也会跳过索引。请注意,无论是你在查询中显式地应用了函数,还是数据库在你不知道的情况下隐式地应用了函数,优化器都会跳过索引。下面先讨论显式应用函数。比如,执行以下查询:

SQL>select * from emp where upper(last_name)='CHEN';

在这种情况下,由于upper函数的存在,优化器跳过了last_name列的索引。(第5章介绍了如何使用基于函数的索引来解决这个问题)。如果应用程序需要频繁地把函数应用于索引列,那么最好创建基于函数的索引,以便允许数据库使用索引。

请注意,即使查询没有显式地把函数应用到某个列,在某些情况下它也可能隐式地这样做。例如,如果在表中定义了一个数值型的列,然后通过指定一个字符,而不是一个数值来查询列值,优化器就会忽略索引。也就是说,如果执行语句select * from emp where department_id=’10’,而不是select * from emp where department_id=10,优化器需要在幕后应用to_number函数才能得到答案。再次强调,使用函数意味着优化器将不使用索引。在这种情况下,即使指定了index提示,优化器也可能会执行全索引扫描,但不会执行索引唯一扫描。因为全索引扫描必须扫描整个索引,所以它比索引唯一扫描慢得多。

日期型数据经常会引起隐式转换,从而阻止使用索引。下面的表达式是非常常见的:

SQL> select * from emp where trunc(hire_date)=trunc(sysdate);

在写这样的查询时,人们往往下意识地使用trunc函数。我们把包含时间的日期截断,以消除一天中的时间,往往不考虑查询执行的后果。然而,对Oracle数据库而言,它只是注意到并没有真正对表达式trunc(hire_date)进行索引,而只索引了hire_date列。因此,数据库忽略了索引。

列trunc(hire_date)上的基于函数的索引会使优化器选择访问索引,但还有一种更简单的方法可以解决这个问题,而无需创建基于函数的索引。

只要对sysdate值使用trunc函数,并把等于运算符替换为范围比较运算符(大于或小于),就可以不必在hire_date列上应用trunc函数。也就是说,对于如下的语句:

select * from emp where trunc(hire_date)=trunc(sysdate);

可把它改写为下面这个语句:

select * from emp where hire_date>=trunc(sysdate) and hire_date

因为对索引列hire_date移除了trunc函数,所以优化器会使用该列上的索引。

5 跳过索引的前导部分
如果在两个或多个列上有一个复合索引,但没有在查询中使用索引的前导部分,那么优化器很可能会忽略表上的索引,而执行全表扫描。比如,在表mytab1的列(a,b)上有一个索引,a是前导列。如果执行select * from mytab1 where b=99这样的SQL语句,数据库会忽略列(a,b)上的索引,因为它必须在表中的每个单独索引项上检查列a所有可能的值。

请注意,如果执行select a,b from mytab1这样的查询语句,优化器更可能使用(a,b)上的索引,因为它意识到这两列都是索引的一部分。因为索引比表更紧凑,而且数据库可以从索引本身得到查询所请求的所有值,所以优化器可能会执行索引快速全扫描。

即使某个查询不含索引的前导部分,但如果一个复合索引的前导列的不同值很少,数据库仍然可以使用索引。在这种情况下,该数据库将执行索引跳跃式扫描,如在第5章中所解释的那样。

在优化器选择了跳跃式扫描时,在谓词中使用的列前可以有多个前导的索引列。我们所见过的案例中,有谓词列前多达6列的情况,优化器仍然采用了跳跃式扫描。数据库管理员往往认为只有前导列值的个数少时,跳跃扫描才是可行的,但“少”是相对的。如果优化器认为跳跃式扫描比全表扫描的成本更低,那么优化器就将选择跳跃式扫描,最终,成本估算起着决定作用并主导优化器的选择。

Oracle优化器忽略索引的原因

优化器忽略索引的原因
创建索引永远不能保证优化器在评估执行计划时一定会使用索引。如果某个查询从表中选择高比例的行,优化器可能觉得使用全表扫描而不是索引扫描,能更快地得到结果。请记住,数据库使用索引时,它首先查找索引获得rowid,然后使用这些rowid来检索所请求的行。如果查询从表中选择很大比例的行,从而导致要读取表中很大比例的块,那么数据库可能执行全表扫描来避免既读取索引又读取表,因为后者的成本可能比仅仅扫描一次表更高。

优化器是否使用索引取决于多种因素,在本章以下各节将分别对它们进行解释。

1 不同的行数
选择全表扫描或索引扫描的另一关键决定因素是,表中与给定查询谓词相匹配的不同行数占表中总行数的比率。通过查询dba_tables视图的num_rows列可以得到某个表的行数。同样,也可以通过查询dba_tab_columns视图的num_distinct列,得到任意列中不同值的数量。num_rows列与num_distinct列的值越接近,优化器越有可能倾向于访问该列的索引而非执行全表扫描,换句话说,索引的选择性越高,数据库就越有可能使用它。

索引的选择性可能会对数据库是否使用索引产生最大的影响。选择性是指每个列值有多少个不同的值。如果索引是非常有选择性的,那么每个索引条目只有很少几行。另外,如果索引的选择性不强,每个索引条目就会有许多行。

请记住,优化器用列的选择性乘以页块(leaf blocks)的统计数量,来估算在访问索引期间,数据库必须读取多少个索引块。虽然事实上,大多数情况下,高选择性的列确实会使用索引,但并不总是如此,因为使用索引还是全表扫描的最终决定因素是块的选择性。

在Oracle Database 10g版本(但不是在11g版本)中,使用dbms_stats.auto_sample_size常量估计dbms_stats包使用的行数,可能会导致对不同值的数量(NDV)产生错误的估计。如果表很大,而且有相当数量的数据是偏态的,往往就会发生这种情况。因此最好对样本大小使用自己的估计,以获得更准确的NDV值。

2 索引聚簇因子
查询dba_indexes视图的clustering_factor列,可以找到索引的聚簇因子的值。聚簇因子用来衡量表中行的有序程度,这种有序程度是与索引的行相比较而言的。如果聚簇因子接近表中的行数,行就有可能是非常随机地排列的,这种情况下,一个索引块的索引条目对应的数据行不太可能位于相同的数据块中。表的选择性(通过过滤)乘以索引聚簇因子,决定了通过索引访问表的成本。这部分计算中使用的实际上是表的选择性。虽然大部分时间,索引的选择性(乘以leaf_blocks,已在上一节讨论)和表的选择性是相同的,计算它实际上是为了确定需要访问表中的多少数据块。通常情况下,我们都假定索引聚簇因子能保证随机性,但事实并非如此。例如,虽然索引中的每行只指向两个不同的块,但条目是按rowid排序为块1,块2,块1,块2……这种(交替排列的)情况会怎么样呢? 如果索引有10000个条目,聚簇因子是10000,但实际上,将仅访问2个块。因此,聚簇因子的计算不能像大多数人认为的那样,保证数据排列的随机性。

在一个具有“好”的聚簇因子的索引中,具体索引叶块中的索引值指向分布在相同数据块中的行。另一方面,在一个具有“坏”的聚簇因子,它可以用更少的I/O读取数据。而具有相同数量的数据但组织得很差的索引,将需要更大的I/O数量,从一组更多的数据块中读取数据。在这种情况下,关键是要注意,如果每个表只有一个索引,那么它的组织可能是理想的,实际上,这只有在表中的数据按特定的顺序加载时才真正成立。举例来说,或许表是按order_date列的顺序加载的。在这种情况下,order_date上索引的聚簇因子将和表中块的数量几乎相同。但是,因为该表的存储只能按一种顺序排列,所以其他所有索引的顺序都将是“欠优化”的。因此,总而言之,“好”与“坏”更是相对而不是绝对的。这可能就是为什么使用索引的成本计算,由包括表和索引选择性的多个元素组成,以使某一个组成部分不会占非常大的比重。

一条经验法则是:良好的聚簇因子接近表的块数,而糟糕的聚簇因子接近表的行数。

除了这里讨论的两个因素,多块读取数的值对索引使用也有影响。数据库文件多块读取计数(db_file_multiblock_read_count)的值越高,从优化器的角度来看,全表扫描的成本就越低。

Oracle在索引和表扫描之间选择

在索引和表扫描之间选择
用户常常对此感到困惑,为什么在他们认为优化器应该使用索引时,它却选择全表扫描。本章后面的一节,介绍了优化器优先选择全表扫描而不是访问索引的几种情况。不过,在深入介绍这些情况之前,首先来了解一下基于成本的优化器工作的原理。

基于成本的优化器的任务是,从一组可能的计划中选择最佳或最优的执行计划。基于成本的优化器首先利用表或索引的行数,每列的不同值的数量以及更多其他信息,来估计可供选择的执行计划的成本。然后,它采用成本最低的执行计划。

出于演示的目的,让我们集中注意力研究确定查询成本最重要的因素之一:表的总行数和优化器需要从该表中读取的行数。几乎可以肯定,如果表的体积非常小,那么优化器将把它完全读入。假定某个表包含10000000(1000万)行,而表使用了100000个表块,因为每个块平均包含约100行。现在,在此表上创建索引,大约需要20000个叶块来存储每个索引列的索引条目。索引比表需要的块更少,因为它只保存一个列的值(和相关表列的rowid)。假设该索引的高度为3,这意味着它的blevel为2,并且每个索引列有100个不同的值,这些值的分布是均匀的。因此,该索引的每个索引值将出现100000次(1000万除以100)。下面用如下测试查询来演示优化器如何在多个执行计划中做选择:

SQL>select * from test_table where test_code='ABCDE';

优化器选反的到底是索引扫描还是全表扫描?为什么?让我们先来分析索引访问的成本。由于test_code列上的索引在所有可能值中是均匀分布的,优化器需要从test_code列上索引中的100个不同值里选择一个,这相当于索引数据的百分之一。为此,数据库需要先读根块和分支块(在这个例子中,blevel=2)。因此,优化器首先记录读取这两个块的成本。下一步,数据库读取索引叶块的1%,这相当于(20000 *0.01)=200个叶块。因此,对于索引读取,就需要访问202个索引块。

因为查询请求了表中的所有列值,所以接下来数据库必须读表中的行。在这里,关键的变量是该索引的聚簇因子,即表中索引列的值的聚集情况。索引列的值聚集程序越高,读所有必要的表行需要访问的块就会越少。例如,聚簇因子是所有可能值中最差的。

这意味首它与表中的行数(10000000)几乎相同。对于表中包含100行的100000个数据块中的每一个,数据库选择1行选择10,或从每个数据块选择1%。因此,访问表中数据的总成本将是选择性乘以聚簇因子,0.01*10000000=100000。因此,以索引为基础的读取操作的近似成本是,202个索引块访问加上100000个表块访问。得到100202块的巨大总成本。

在涉及全表扫描的成本时,请记住,全表扫描使用多块读,而不像索引的读取总是使用单块I/O。在这个例子中,假定每个表块包含100行,在一次全表扫描中数据库需要扫描大约100000个数据块。假设multi_block_read_count的值被设置为10。届时数据库将必须执行共100000/10次读取,即10000次读取。如果想要更精确地计算,也可以在总数中添加段头块的读取,因此它的值是10001。

显然,在这种情况下,甚至在假定可能出现最差的索引聚簇因子后,全表扫描的成本还是要低得多(10001次块读取与索引访问的100202次块读取相比)。此外,还可以并行执行全表扫描,使它执行得更快。请注意,在前面的例子中,查询只获取了一个大表的1%的数据,但全表扫描成本要低得多。这个简单的演示表明,优化器选择索引或全表扫描,并不只是依赖于查询需要检索的行占全行数据的百分比。相反,它还依赖于其他关键因素,如数据的分布,表和叶块的数量,表块中行的平均数量,索引叶块中叶条目的平均数量,该索引的聚簇因子和多块读取计数(multi_block_read_count)的大小。在优化器决定究竟使用索引还是全表扫描时,想要完全依靠某种神奇的比率(即查询所应检索的行与总行数的百分比,如1%,5%,10%,25%或50%)来决策是根本不现实的。这个简单的例子表明,即使查询要检索的行数只占某个表总行数很小的一部分(1%)时,优化器也可能执行全表扫描。

Oracle如何避免使用索引

如何避免使用索引
一般而言,人们更倾向于寻找一些方法,让成本优化器使用所创建的索引,而不是让它忽略现有的索引。不过,有些时候,你想要做的恰恰是:让优化器不使用索引。

1 在任何情况下都不使用某个索引
例如,在处理某个选择性不强的索引时,有可能希望不使用该索引。这是因为如果某个索引没有足够的选择性,扫描整个基础表有时会更有效。

如果SQL语句包含一个结构,如包括某个索引列的where子句,优化器可能会使用该列上的索引。为了阻止这种情况的发生,可以在查询语句中指定no_index提示,让优化器不得使用某个索引。例如:

SQL> select /*+ no_index(emp dept_idx) */ * from emp where department_id=10;


Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |    69 |     3   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| EMP  |     1 |    69 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("DEPARTMENT_ID"=10)

这个例子列出了想要让优化器忽略的具体索引。如果在表上有其他索引,优化器仍然会考虑使用那些索引。

除了指定单个索引,也可以列出一组优化器必须忽略的索引。如果只是指定no_index提示,而没有列出任何索引,优化器将忽略你指定的表的所有索引。与在本章后面将会介绍的index提示一样,no_index提示适用于B树索引,基于函数的索引,聚簇索引和域索引。

2 只避免快速扫描
no_index_ffs提示可以用来指示优化器避免对某个索引执行索引快速全扫描。请注意,与index提示的情况一样,必须在指定这个提示的同时指定特定的索引名字。例如:

SQL> select /*+ no_index_ffs(test test_i1) */   c from test;

同样,也可以使用no_index_ss提示来告诉优化器排队表中具体索引的跳跃式扫描。

3 强制表扫描
另一种避免使用索引的方法是从相反的方向解决问题,即明确要求执行表扫描。使用full提示指示优化器选择全表扫描而不是索引扫描。下面是如何指定full提示的例子:

SQL> select /*+ full(emp ) */ * from emp where department_id=10;

Oracle全索引扫描

全索引扫描
全索引扫描是读取给定索引中所有条目的操作。从这个意义上说,全索引扫描类似于全表扫描。与首先做全表扫描,然后再对数据排序相比,全索引扫描是一种很好的替代方法。Oracle数据库在下面任何一种情况下都可能使用全索引扫描。
.查询需要排序合并连接(sort merge join):查询所引用的所有列必须都在索引中存在,且前导索引列的顺序也必须与查询中指定的列顺序相同。
.查询包含order by子句:子句中的所有列必须都在该索引中存在。
.查询包含group by子句:索引和group by子句必须包含相同的列,但不要求它们的顺序一定相同。

下面的例子显示数据库如何利用全索引扫描操作检索数据,而无需执行排序操作。因为索引已经排序,所以使用全索引扫描可以不必执行排序操作。全索引扫描读取单个个数据块,而不执行多块读取操作。

SQL> select * from test where c<30000 order by c;

29999 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 2983339933

---------------------------------------------------------------------------------------
| Id  | Operation                   | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |         | 29999 |   292K|    26   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| TEST    | 29999 |   292K|    26   (0)| 00:00:01 |
|*  2 |   INDEX FULL  SCAN          | TEST_I1 | 29999 |       |    14   (0)| 00:00:01 |
---------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("C"<30000)

在此查询中,数据库首先执行全索引扫描,然后通过索引rowid操作执行表访问。这是因为查询请求了除索引列外的其他列(select * from …)。然而,如果查询只请求了索引列并使用了order by子句,数据库将跳过表访问,只通过访问索引得到数据,无需读取表中的值。

索引快速全扫描
当索引本身包含查询中指定的所有列时,Oracle数据库执行索引快速全扫描代替全表扫描。请注意,在下面的例子中,检索数据只用了索引快速全扫描操作,且根本没有访问表本身:

SQL> select   c from test where c<10000;

9999 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 3298034341

--------------------------------------------------------------------------------
| Id  | Operation            | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |         |  9999 | 49995 |   123   (1)| 00:00:01 |
|*  1 |  INDEX FAST FULL SCAN| TEST_I1 |  9999 | 49995 |   123   (1)| 00:00:01 |
--------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("C"<10000)

请注意,不像全索引扫描,索引快速全扫描使用多块读操作来读取索引。因此,既因为多块的I/O,又因为这种类型的扫描可以像全表扫描那样并行运行,所以这种类型的扫描往往更快。

Oracle索引跳跃式扫描

索引跳跃式扫描
当一个查询未在where子句的谓词中指定复合索引的前导列,查询“跳过”该列时,就会发生索引跳跃式扫描。数据库将一个复合索引拆分成多个逻辑子索引。复合索引前导列中的不同值越少,组成复合索引的其他键的不同值越多,索引跳跃式扫描的性能就越好。例如,如果前导列有三个不同值,数据库将把复合索引拆分成三个逻辑子索引,并在其中搜索索引非前导列的值。

在下面的例子中,数据库使用了复合索引test_i1,它是在列(b,c)上创建的。查询指定的条件是”c<10″。查询的where子句没有使用复合索引的前导列(b),从而跳过该列。

SQL> select * from test where c<10;

         A B                   C
---------- ---------- ----------
         0 F                   1
         0 F                   2
         0 F                   3
         0 F                   4
         0 F                   5
         0 F                   6
         0 F                   7
         0 F                   8
         0 F                   9

9 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 650436733

-----------------------------------------------------------------------------------------------
| Id  | Operation                           | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |         |     9 |    90 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| TEST    |     9 |    90 |     1   (0)| 00:00:01 |
|*  2 |   INDEX SKIP SCAN                   | TEST_I1 |     9 |       |     1   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("C"<10)
       filter("C"<10)

数据库把复合索引拆分成多少逻辑子索引,取决于前导列的不同值数量。在这个例子中,复合索引的前导列b只有极少数不同的值:

SQL> select distinct b from test;

B
----------
M
F

正如输出结果所显示的,复合索引的前导列只有两个不同的值。数据库把复合索引(b,c)拆分成两个子索引,第一个子索引的键值是”M”,而第二个子索引的键值是”2″。数据库检索第一个子索引,然后检索第二个子索引。另外,索引的非前导列c有200000个不同的值(与表中的行数据相同)。在这样的情况下,由于复合索引前导列中的不同值很少,数据库将采用复合索引跳跃式扫描,而不是像在以前版本的数据库(也就是说,Oracle 9i以前的版本)中那样执行全表扫描。

Oracle索引范围扫描

索引范围扫描
当数据库需要访问具有高度选择性的数据时,它执行索引范围扫描。数据库按升序返回索引列的值。如果所有行的索引列都是相同的,则按rowid的顺序输出。

当处理以下类型的条件时,优化器会选择索引范围扫描,其中col1是某个索引的前导列:

col1=:b1
col1<:b1 col1>:b1

此外,包含索引前导列的上述三种条件的任何”与 (and)组合,也将导致索引范围扫描。

索引数据以升序存储。如果数据库需要返回降序的数据时,比如需要首先传回最新的数据,或需要检索小于某一具体的数据时,它使用降序索引范围扫描。

SQL> select * from emp where department_id<20;

EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE    JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
----------- -------------------- ------------------------- ------------------------- -------------------- ------------ ---------- ---------- -------------- ---------- -------------
        200 Jennifer             Whalen                    JWHALEN                   515.123.4444         17-SEP-03    AD_ASST          4400                       101            10


Execution Plan
----------------------------------------------------------
Plan hash value: 1909286381

------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |          |    11 |   759 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| EMP      |    11 |   759 |     1   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN                  | DEPT_IDX |    11 |       |     1   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("DEPARTMENT_ID"<20)

从底部开始阅读,解释计划表明,优化器首先执行索引范围扫描,并使用从索引范围扫描获得的rowid执行表访问(table access by index rowid batched操作)。在指定了“大于”条件,如”department_id>100″时,数据库也可能使用索引范围扫描,如下面的例子所示:

SQL> select * from emp where department_id>100;

EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE    JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
----------- -------------------- ------------------------- ------------------------- -------------------- ------------ ---------- ---------- -------------- ---------- -------------
        205 Shelley              Higgins                   SHIGGINS                  515.123.8080         07-JUN-02    AC_MGR          12008                       101           110
        206 William              Gietz                     WGIETZ                    515.123.8181         07-JUN-02    AC_ACCOUNT       8300                       205           110


Execution Plan
----------------------------------------------------------
Plan hash value: 1909286381

------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |          |    11 |   759 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| EMP      |    11 |   759 |     1   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN                  | DEPT_IDX |    11 |       |     1   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("DEPARTMENT_ID">100)

当查询使用between操作符时,数据库也会执行索引范围扫描,如下面的例子所示:

SQL> select * from emp where department_id between 100 and 110;

EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE    JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
----------- -------------------- ------------------------- ------------------------- -------------------- ------------ ---------- ---------- -------------- ---------- -------------
        108 Nancy                Greenberg                 NGREENBE                  515.124.4569         17-AUG-02    FI_MGR          12008                       101           100
        109 Daniel               Faviet                    DFAVIET                   515.124.4169         16-AUG-02    FI_ACCOUNT       9000                       108           100
        110 John                 Chen                      JCHEN                     515.124.4269         28-SEP-05    FI_ACCOUNT       8200                       108           100
        111 Ismael               Sciarra                   ISCIARRA                  515.124.4369         30-SEP-05    FI_ACCOUNT       7700                       108           100
        112 Jose Manuel          Urman                     JMURMAN                   515.124.4469         07-MAR-06    FI_ACCOUNT       7800                       108           100
        113 Luis                 Popp                      LPOPP                     515.124.4567         07-DEC-07    FI_ACCOUNT       6900                       108           100
        205 Shelley              Higgins                   SHIGGINS                  515.123.8080         07-JUN-02    AC_MGR          12008                       101           110
        206 William              Gietz                     WGIETZ                    515.123.8181         07-JUN-02    AC_ACCOUNT       8300                       205           110

8 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1909286381

------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |          |    20 |  1380 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| EMP      |    20 |  1380 |     1   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN                  | DEPT_IDX |    20 |       |     1   (0)| 00:00:01 |
------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("DEPARTMENT_ID">=100 AND "DEPARTMENT_ID"< =110)

请注意,虽然在指定条件"where department_id <20"及"where department_id>100"时,数据库使用索引范围扫描,但如果把查询谓词修改为"where department_id<1200",它就会转而执行全表扫描。原因很简单:在指定条件为"department_id<20"或"department_id>9000"的条件时,相比条件"department_id<1200",数据库需要扫描的值要少得多。很可能有大量的值都满足条件"department_id<120",因此在指定这个条件时,数据库将执行全表扫描来检索数据,如下面的示例所示:

SQL> select * from emp where department_id<1200;

Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |  1107 |  7383 |    13   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| EMP  |  1107 |  7383 |    13   (0)| 00:00:01 |
--------------------------------------------------------------------------

   2 - access("DEPARTMENT_ID"<1200)

以下是另一个例子,显示了当查询谓词需要搜索表中绝大部分行时,数据库为何倾向于执行全表扫描,条件”department_id>30″显示比”department_id<1200″需要扫描更多的数据。

SQL> select * from emp where department_id>30;
Execution Plan
----------------------------------------------------------
Plan hash value: 3956160932

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |  2078 |  7383 |    23   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| EMP  |  2078 |  7383 |    23   (0)| 00:00:01 |
--------------------------------------------------------------------------

  2 - access("DEPARTMENT_ID">30)

索引降序范围扫描(index range scan descending)操作与索引范围扫描非常类似,不同的是,使用索引降序范围扫描时数据库引擎以降序读取结果。优化器之所以做出这样的选择,其中一个原因可能是避免将来再排序。在指定order by desc子句而索引又能满足该子句时,基于成本的优化器将使用索引降序范围扫描操作,从而避免降序操作。索引降序范围扫描操作向后读取索引,以避免按正常次序(升序)读取,然后再执行降序排序操作。

SQL> select * from emp where department_id<20 order by department_id desc;

EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE    JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
----------- -------------------- ------------------------- ------------------------- -------------------- ------------ ---------- ---------- -------------- ---------- -------------
        200 Jennifer             Whalen                    JWHALEN                   515.123.4444         17-SEP-03    AD_ASST          4400                       101            10


Execution Plan
----------------------------------------------------------
Plan hash value: 3507836879

-----------------------------------------------------------------------------------------
| Id  | Operation                    | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |          |    11 |   759 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID | EMP      |    11 |   759 |     1   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN DESCENDING| DEPT_IDX |    11 |       |     1   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("DEPARTMENT_ID"<20)

Oracle索引唯一扫描

索引唯一扫描
如果查询只需要从表中获取单个行,数据库就执行索引唯一扫描。当查询只包含某个唯一索引中的列时,数据库使用索引唯一扫描。当查询在主键约束列上指定了相等条件时,数据库也使用索引唯一扫描。

在下面的例子中,在列employee_id上有主键约束,因此查询通过谓词”where employee_id=200″保证只访问一行。

SQL> select * from emp where employee_id=200;

EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE    JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
----------- -------------------- ------------------------- ------------------------- -------------------- ------------ ---------- ---------- -------------- ---------- -------------
        200 Jennifer             Whalen                    JWHALEN                   515.123.4444         17-SEP-03    AD_ASST          4400                       101            10


Execution Plan
----------------------------------------------------------
Plan hash value: 4024650034

--------------------------------------------------------------------------------------
| Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |        |     1 |    69 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |     1 |    69 |     1   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN         | EMP_PK |     1 |       |     1   (0)| 00:00:01 |
--------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("EMPLOYEE_ID"=200)

在这个例子中,数据库使用列employee_id上的主键(emp_pk)。注意,在指定了某个唯一索引的所有列时,数据库也很可能执行索引唯一扫描。

Oracle报告分区索引

Oracle报告分区索引
从关于索引的数据字典中可以收集到很多信息,它们包括以下内容:
.分区名称
.索引类型
.索引分区的状态(需要查询相应的视图)
.索引分区的大小

在下面的例子中,你只是希望得到employees_part表的索引名,分区名和状态的列表。因为此表上既有分区索引又有非分区索引。所以你用union操作把对两种索引的查询合并在一起。

SQL> select table_name,index_name,partition_name,p.status
  2  from user_ind_partitions p join user_indexes i using(index_name)
  3  where table_name='EMPLOYEES_PART'
  4  union
  5  select table_name,index_name,null,status
  6  from user_indexes
  7  where table_name='EMPLOYEES_PART'
  8  order by 2,3;

TABLE_NAME                     INDEX_NAME                     PARTITION_NAME                           STATUS
------------------------------ ------------------------------ ---------------------------------------- --------
EMPLOYEES_PART                 EMPLOYEES_PART_PK                                                       VALID
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             MANAGER_100                              UNUSABLE
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             MANAGER_200                              UNUSABLE
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             MANAGER_300                              UNUSABLE
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             MANAGER_400                              UNUSABLE
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             MANAGER_500                              UNUSABLE
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             MANAGER_600                              UNUSABLE
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             MANAGER_700                              UNUSABLE
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             MANAGER_800                              UNUSABLE
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             MANAGER_900                              UNUSABLE
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             MANAGER_MAX                              USABLE
EMPLOYEES_PART                 EMPLOYEES_PART_UK1                                                      N/A
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P1990                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P1991                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P1992                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P1993                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P1994                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P1995                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P1996                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P1997                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P1998                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P1999                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               P2000                                    USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI               PMAX                                     USABLE
EMPLOYEES_PART                 EMPLOYEE_PART_LI                                                        N/A

25 rows selected.

请注意,在查询user_indexes视图时,分区索引对应的状态(status)列中显示N/A(表示不可用)。只有(基于索引分区的)最精细的数据字典视图的状态列才会被填入数据。也就是说,对于分区索引,user_ind_partitions视图的status列将被填充。如果你查询的最子分区索引,那么只有user_ind_subpartitions视图的status列将被填充,而user_indexes和user_ind_partitions视图的status列将是N/A。

接下来,需要执行一个查询,以确定表上所有索引分区的类型.

SQL> select table_name,index_name,partitioning_type,locality,alignment from user_part_indexes;

TABLE_NAME                     INDEX_NAME                     PARTITION LOCALI ALIGNMENT
------------------------------ ------------------------------ --------- ------ ------------
EMPLOYEES_JY                   EMPLOYEES_UK1                  RANGE     GLOBAL PREFIXED
EMPLOYEES_JY                   EMPLOYEES_JY_IH1               HASH      GLOBAL PREFIXED
EMPLOYEES_PART                 EMPLOYEE_PART_LI               RANGE     LOCAL  PREFIXED
EMPLOYEES_PART                 EMPLOYEES_PART_UK1             RANGE     GLOBAL PREFIXED

在查询段信息时,需要注意区分子分区索引。对于子分区索引,为了获得子分区的信息,大多数数据字典视图中都有一个子分区列。但这有一个例外,当需要从dba_segments等视图中获得段信息时,只有实际分区或表示实际段的子分区名才会在dba_segments中表示。换句话说,对于子分区索引,子分区名称将在dba_segments的partition_name列中出现。在下面的例子中,想要获得billing_fact表中大小超过8GB的索引子分区。你对user_ind_subpartitions执行了一个子查询,这表明dba_segments视图的partition_name列实际上代表了user_ind_subpartitions视图的subpartition_name列。

select segment_name,partition_name,round(bytes/1048576) meg
from dba_segments
where (segment_name,partition_name) in
(select index_name,subpartition_name from user_ind_subpartitions
where index_name in
(select index_name from user_indexes
where table_name='BILLING_FACT'))
and bytes>1048576*8192
order by 3 desc;