Oracle RAC搭建过程

oracle rac环境搭建

安装准备

网络环境

节点 IP
节点一 public ip
节点一 private ip
节点二 public ip
节点二 private ip
虚拟IP vip1
虚拟IP vip2
SCAN IP sip1
SCAN IP sip2
SCAN IP sip3

软件准备

Oracle版本是11.2.0.4

主机系统环境(所有节点均设置)

修改OS系统标识

Oracle默认不支持CentOS系统安装,我们需要将系统标识修改为Redhat

1
[root@localhost ~]# echo "Red Hat Enterprise Linux Server release 7.0 (Maipo)" >/etc/redhat-release

修改主机名

节点一

1
[root@localhost ~]# hostnamectl set-hostname ol7-112-rac1.localdomain

节点二

1
[root@localhost ~]# hostnamectl set-hostname ol7-112-rac2.localdomain

修改系统内核参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[root@localhost ~]# echo "
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 7864320
kernel.shmmax = 132212254720
kernel.shmmni = 4096
#semaphores: semmsl, semmns, semopm, semmni
kernel.sem = 250 32000 100 128
net.core.rmem_default=262144
net.core.rmem_max=16777216
net.core.wmem_default=262144
net.core.wmem_max=16777216
net.core.somaxconn=4096
net.core.netdev_max_backlog=262144
net.ipv4.tcp_max_syn_backlog=262144
net.ipv4.tcp_max_tw_buckets=10000
net.ipv4.ip_local_port_range = 9000 65500
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 3600
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_mem = 786432 1048576 1572864
vm.swappiness = 0
vm.panic_on_oom = 1
kernel.randomize_va_space=0" >>/etc/sysctl.conf
#让修改后的内核参数生效
[root@localhost ~]# sysctl –p

修改hosts文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@localhost ~]# echo "#Public
22.203.144.3 ol7-112-rac1.localdomain ol7-112-rac1
22.203.144.5 ol7-112-rac2.localdomain ol7-112-rac2
#Private
192.168.1.111 ol7-112-rac1-priv.localdomain ol7-112-rac1-priv
192.168.1.112 ol7-112-rac2-priv.localdomain ol7-112-rac2-priv
#Virtual
22.203.144.240 ol7-112-rac1-vip.localdomain ol7-112-rac1-vip
22.203.144.241 ol7-112-rac2-vip.localdomain ol7-112-rac2-vip
#SCAN
22.203.144.242 ol7-112-scan.localdomain ol7-112-scan
22.203.144.243 ol7-112-scan.localdomain ol7-112-scan
22.203.144.244 ol7-112-scan.localdomain ol7-112-scan
" >>/etc/hosts

修改操作系统资源限制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@localhost ~]# echo "#ORACLE
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 4096
oracle hard nofile 65536
oracle soft stack 10240" >>/etc/security/limits.conf
[root@localhost ~]# echo "#GRID
grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 4096
grid hard nofile 65536
grid soft stack 10240" >>/etc/security/limits.conf
echo "session required pam_limits.so" >>/etc/pam.d/login
[root@localhost ~]# vi /etc/security/limits.d/20-nproc.conf
#修改参数
* soft nproc 1024
#为
* - nproc 16384

创建用户和组

1
2
3
4
5
6
7
8
[root@localhost ~]# groupadd -g 54321 oinstall
[root@localhost ~]# groupadd -g 54322 dba
[root@localhost ~]# groupadd -g 54323 oper
[root@localhost ~]# groupadd -g 54327 asmdba
[root@localhost ~]# groupadd -g 54328 asmoper
[root@localhost ~]# groupadd -g 54329 asmadmin
[root@localhost ~]# useradd -u 54321 -g oinstall -G dba,asmadmin,asmdba,asmoper grid
[root@localhost ~]# useradd -u 54322 -g oinstall -G dba,oper,asmadmin,asmdba oracle

分别为grid和oracle用户设置密码

1
2
[root@localhost ~]# passwd grid
[root@localhost ~]# passwd oracle

修改oracle用户环境变量

节点一:在/home/oracle/.bash_profile末尾添加

1
2
3
4
5
6
7
8
9
10
11
12
13
#Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=ol7-112-rac1.localdomain
export ORACLE_UNQNAME=ORCL
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0.1/db_1
export ORACLE_SID=ORCL1
export ORACLE_TERM=xterm
export BASE_PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$BASE_PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

节点二:在/home/oracle/.bash_profile末尾添加

1
2
3
4
5
6
7
8
9
10
11
12
13
#Oracle Settings
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_HOSTNAME=ol7-112-rac2.localdomain
export ORACLE_UNQNAME=ORCL
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0.1/db_1
export ORACLE_SID=ORCL2
export ORACLE_TERM=xterm
export BASE_PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$BASE_PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

修改grid用户环境变量

节点一:在/home/grid/.bash_profile末尾添加

1
2
3
4
5
6
7
8
#Grid Settings
export ORACLE_SID=+ASM1
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/11.2.0.1/grid
export BASE_PATH=/usr/sbin:$PATH
export PATH=\$ORACLE_HOME/bin:$BASE_PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

节点二:在/home/grid/.bash_profile末尾添加

1
2
3
4
5
6
7
8
#Grid Settings
export ORACLE_SID=+ASM2
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/11.2.0.1/grid
export BASE_PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$BASE_PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib

创建目录及授权

1
2
3
4
5
6
7
8
9
10
[root@localhost ~]# mkdir -p /u01/app/grid
[root@localhost ~]# mkdir -p /u01/app/11.2.0.1/grid
[root@localhost ~]# chown -R grid:oinstall /u01/app/grid
[root@localhost ~]# chown -R grid:oinstall /u01/app/11.2.0.1
[root@localhost ~]# mkdir -p /u01/app/oracle
[root@localhost ~]# mkdir -p /u01/app/oracle/product/11.2.0.1/db_1
[root@localhost ~]# chown oracle:oinstall /u01/app
[root@localhost ~]# chown -R oracle:oinstall /u01/app/oracle
[root@localhost ~]# chown -R oracle:oinstall /u01/app/oracle/product/11.2.0.1/db_1
[root@localhost ~]# chmod -R 0775 /u01

安装grid与oracle所需的软件环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#根据实际情况变动
[root@localhost ~]# rpm -Uvh compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
[root@localhost ~]# rpm -Uvh ksh-20120801-137.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh libaio-devel-0.3.109-13.el7.x86_64.rpm
[root@localhost ~]# rpm -Uvh unixODBC-2.3.1-11.el7.x86_64.rpm
[root@localhost ~]# rpm -Uvh unixODBC-devel-2.3.1-11.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh zlib-devel-1.2.7-17.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh elfutils-libelf-devel-0.170-4.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh libXmu-1.1.2-2.el7.x86_64.rpm
[root@localhost ~]# rpm -Uvh libXaw-1.0.13-4.el7.x86_64.rpm
[root@localhost ~]# rpm -Uvh xterm-295-3.el7.x86_64.rpm
[root@localhost ~]# rpm -Uvh perl-Switch-2.16-7.el7.noarch.rpm
#以下可以不安装
[root@localhost ~]# rpm -ivh nss-softokn-freebl-3.34.0-2.el7.i686.rpm glibc-2.17-222.el7.i686.rpm
[root@localhost ~]# rpm -ivh glibc-devel-2.17-222.el7.i686.rpm
[root@localhost ~]# rpm -ivh libgcc-4.8.5-28.el7.i686.rpm
[root@localhost ~]# rpm -ivh libstdc++-4.8.5-28.el7.i686.rpm
[root@localhost ~]# rpm -ivh libstdc++-devel-4.8.5-28.el7.i686.rpm
[root@localhost ~]# rpm -ivh libaio-0.3.109-13.el7.i686.rpm
[root@localhost ~]# rpm -ivh libaio-devel-0.3.109-13.el7.i686.rpm
[root@localhost ~]# rpm -Uvh compat-libstdc++-33-3.2.3-72.el7.i686.rpm
[root@localhost ~]# rpm -ivh libXau-1.0.8-2.1.el7.i686.rpm
[root@localhost ~]# rpm -ivh libxcb-1.12-1.el7.i686.rpm
[root@localhost ~]# rpm -ivh libX11-1.6.5-1.el7.i686.rpm
[root@localhost ~]# rpm -ivh libXext-1.3.3-3.el7.i686.rpm
[root@localhost ~]# rpm -ivh libXi-1.7.9-1.el7.i686.rpm
[root@localhost ~]# rpm -ivh libXtst-1.2.3-1.el7.i686.rpm
[root@localhost ~]# rpm -ivh libXp-1.0.2-2.1.el7.x86_64.rpm
#在grid目录下
[root@localhost ~]# rpm -ivh cvuqdisk-1.0.9-1.rpm

设置selinux并使之生效

1
2
[root@localhost ~]# sed -i '/SELINUX=enforcing/s/enforcing/permissive/g' /etc/selinux/config
[root@localhost ~]# setenforce Permissive

关闭防火墙并取消开机启动

1
2
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld

设置NTP时钟

1
2
3
[root@localhost ~]# systemctl stop ntpd
[root@localhost ~]# systemctl disable ntpd
[root@localhost ~]# mv /etc/ntp.conf /etc/ntp.conf.orig

存储配置(在所有节点均要操作)

1
[root@localhost ~]# echo "KERNEL==\"sd?\", SUBSYSTEM==\"block\", PROGRAM=\"/lib/udev/scsi_id --whitelisted --replace-whitespace /dev/\$name\",RESULT==\"`/usr/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/mapper/Data01`\", RUN+=\"/bin/sh -c 'mknod /dev/asm-disk1 b \$major \$minor;chown grid:asmadmin /dev/asm-disk1;chmod 0660 /dev/asm-disk1'\"" >>/etc/udev/rules.d/99-oracle-asmdevices.rules

执行如下(重启),让磁盘绑定生效

1
2
[root@localhost ~]# udevadm control --reload-rules
[root@localhost ~]# udevadm trigger

查看磁盘绑定

1
[root@localhost ~]# ls -al /dev/asm\*

安装Grid Infrastructure

根据图示步骤安装

























使用root用户在节点1上执行orainstRoot.sh如下图

使用root用户在节点2上执行orainstRoot.sh如下图

使用root用户在节点1上执行root.sh如下图

等待提示“Creating /etc/oratab file……”时,新打开一个会话执行如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@localhost ~]# echo "[Unit]
Description=Oracle Hight Availability Services
After=syslog.target
[Service]
ExecStart=/etc/init.d/init.ohasd run > /dev/null 2>&1 Type=simple
Restart=always
[Install]
WantedBy=multi-user.target" > /usr/lib/systemd/system/ohas.service
#systemctl deamon-reload
1. systemctl enable ohas
2. systemctl start ohas
3. systemctl restart ohas
4. 等待提示“Configure Oracle Grid Infrastructure for a Cluster
succeeded”表示在节点1上运行完成并无错误

使用root用户在节点2上执行root.sh如下图


安装oracle数据库软件

根据图示安装















安装oracle数据库















遇到编译错误,修改以下参数解决:

1
2
3
4
5
[root@localhost ~]# vi $ORACLE_HOME/sysman/lib/ins_emagent.mk
#Search for the line
$(MK_EMAGENT_NMECTL)
#Change it to:
$(MK_EMAGENT_NMECTL) -lnnz11