数据库
首页 > 数据库> > Oracle单实例通过DG迁移至RAC集群(Oracle 11g 超详细文档)

Oracle单实例通过DG迁移至RAC集群(Oracle 11g 超详细文档)

作者:互联网

Oracle单实例通过DG迁移至RAC集群(Oracle 11g 超详细文档)

置顶 术士起个门 2018-12-25 14:12:05 3307 收藏 13
分类专栏: Oracle 文章标签: oracle DG 迁移 rac
版权
实验:Oracle单实例通过DG迁移至RAC集群(Oracle 11g 超详细文档)
步骤1:Oracle单实例搭建
1. 系统环境检查
2. 创建用户、组,配置环境变量、安装目录
3. 安装Oracle软件
4. 创建Oracle数据库
步骤2:Oracle RAC 双节点搭建
1. 规划IP地址
2. 搭建DNS服务、NTP服务
3. 通过Openfiler为Oracle集群准备ISCSI共享存储
4. Grid安装前系统准备
5. 安装Grid
6. 安装Oracle软件
步骤3:搭建DG
1. 主库准备(orasgl)
2. 备库准备(orarac)
3.配置监听
4. 数据复制
5. 添加日志组
6.打开数据库,测试数据同步
8. 创建spfile到ASM磁盘组
7. 注册到CRS资源管理
8. 将rac2节点开启
步骤4:切换主备
步骤1:Oracle单实例搭建
操作系统:Oracle Linux 6.4 (Desktop安装)
Oracle安装包版本:11.2.0.4
(已有单实例环境可忽略此部分)

1. 系统环境检查
1.1 防火墙

#通过以下命令关闭防火墙
[root@localhost ~]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
#关闭防火墙开机自启动
[root@localhost ~]# chkconfig iptables off
1
2
3
4
5
6
7
1.2 Selinux

#修改selinux配置文件
[root@localhost ~]# vi /etc/selinux/config
-------------------------------------------
SELINUX=disabled #将SELINUX=enforcing修改为SELIUNX=disabled
-------------------------------------------
#检查修改状态
[root@localhost ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: disabled
Policy version: 26
Policy from config file: targeted
#Mode from config file已改变为disabled,重启后生效
[root@localhost ~]# sestatus
SELinux status: disabled
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1.3 主机名

#修改主机名配置文件(永久设置)
[root@localhost ~]# vi /etc/sysconfig/network
----------------------------------------------------------
HOSTNAME=orclsgl #将HOSTNAME=localhost.localdomain修改为自己的主机名
----------------------------------------------------------
#重启后生效
#如若不想重启可使用以下命令改变当前主机名(把当前设置改为和永久设置一致)
[root@localhost ~]# hostname orclsgl
[root@localhost ~]# hostname
orclsgl
#断开session重连后,命令提示符也会随之改变
[root@orclsgl ~]# hostname
orclsgl
1
2
3
4
5
6
7
8
9
10
11
12
13
1.4 ip地址

#确认机器的IP地址,如果是DHCP获得的,最好改成静态IP
[root@orclsgl ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:0F:47:47
inet addr:172.17.10.209 Bcast:172.17.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0f:4747/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:257297 errors:0 dropped:0 overruns:0 frame:0
TX packets:74240 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:269210096 (256.7 MiB) TX bytes:5062907 (4.8 MiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:480 (480.0 b) TX bytes:480 (480.0 b)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1.5 hosts文件

#将IP地址与主机名对应关系写入hosts文件
[root@orclsgl ~]# vi /etc/hosts
--------------------------------------
172.17.10.209 orclsgl #新增一行
--------------------------------------
#可以通过ping命令测试一下,看看解析的地址是否正确
[root@orclsgl ~]# ping orclsgl
PING orclsgl (172.17.10.209) 56(84) bytes of data.
64 bytes from orclsgl (172.17.10.209): icmp_seq=1 ttl=64 time=0.610 ms
64 bytes from orclsgl (172.17.10.209): icmp_seq=2 ttl=64 time=0.073 ms
1
2
3
4
5
6
7
8
9
10
1.6 yum源

#通过yum clean all和yum makecache命令来建立yum缓存,并验证yum源
[root@orclsgl yum.repos.d]# yum clean all
Loaded plugins: refresh-packagekit, security
Cleaning repos: HighAvailability LoadBalancer ResilientStorage ScalableFileSystem Server UEK2
Cleaning up Everything
[root@orclsgl yum.repos.d]# yum makecache
Loaded plugins: refresh-packagekit, security
HighAvailability | 3.7 kB 00:00 ...
HighAvailability/filelists_db | 47 kB 00:00 ...
HighAvailability/primary_db | 54 kB 00:00 ...
HighAvailability/other_db
...
1
2
3
4
5
6
7
8
9
10
11
12
1.7 swap分区

#检查是否有配置swap分区,如果没有配置或配置不足可手动增加
[root@orclsgl ~]# free
total used free shared buffers cached
Mem: 2048424 1906040 142384 0 12720 1550672
-/+ buffers/cache: 342648 1705776
Swap: 4194300 4 4194296
#安装Oracle,swap空间最低3G
1
2
3
4
5
6
7
1.8 tmpfs(/dev/shm)

#检查tmpfs
[root@orclsgl ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 20G 4.4G 15G 24% /
tmpfs 1001M 112K 1001M 1% /dev/shm
/dev/sda1 194M 51M 134M 28% /boot
/dev/sda2 50G 180M 47G 1% /u01
#tmpfs的大小我个人习惯设置为4G,有见到过设置为2G,Oracle安装也不报错的
#修改/etc/fstab,在default后面加上size=4G
[root@orclsgl ~]# vi /etc/fstab
-------------------------------------------
tmpfs /dev/shm tmpfs defaults,size=4G 0 0
-------------------------------------------
#重新挂载tmpfs
[root@orclsgl ~]# mount -o remount /dev/shm/
[root@orclsgl ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 20G 4.4G 15G 24% /
tmpfs 4.0G 112K 4.0G 1% /dev/shm
/dev/sda1 194M 51M 134M 28% /boot
/dev/sda2 50G 180M 47G 1% /u01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1.9 系统时间

#系统时间是需要注意的,也可以配置时间同步,注意时区
[root@orclsgl ~]# date
Mon Dec 17 17:28:49 CST 2018
1
2
3
2. 创建用户、组,配置环境变量、安装目录
2.1 创建Oracle安装所需的组

#Oracle安装需要oinstall、dba、oper三个组
[root@orclsgl ~]# groupadd -g 1100 oinstall
[root@orclsgl ~]# groupadd -g 1200 dba
[root@orclsgl ~]# groupadd -g 1300 oper
#组ID的设置为本人个人习惯
1
2
3
4
5
2.2 创建Oracle安装所需的用户

#Oracle安装需要oracle用户
[root@orclsgl ~]# useradd -u 1000 -g oinstall -G dba,oper oracle
[root@orclsgl ~]# id oracle
uid=1000(oracle) gid=1100(oinstall) groups=1100(oinstall),1200(dba),1300(oper)
#oinstall为oracle的主要组,dba、oper为附加组
#用户ID为本人个人习惯
1
2
3
4
5
6
2.3 配置oracle用户环境变量

#新增以下内容
[root@orclsgl ~]# vi /home/oracle/.bash_profile
-------------------------------------------------------------
export ORACLE_BASE=/u01/app/oracle #数据库BASE目录
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_home #数据库家目录
export ORACLE_SID=orasgl #数据库实例名
export ORACLE_TERM=xterm
export PATH=$ORACLE_HOME/bin:/user/sbin/:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib64:/usr/lib64:/usr/local/lib64
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK #根据数据库字符集书写
-------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
2.4 创建目录并修改目录权限

[root@orclsgl ~]# mkdir -p /u01/app/oracle
[root@orclsgl ~]# chown oracle:oinstall -R /u01/app
#检查目录权限
[root@orclsgl ~]# ll /u01/
total 20
drwxr-xr-x 3 oracle oinstall 4096 Dec 18 17:21 app
drwx------. 2 root root 16384 Dec 17 14:54 lost+found
[root@orclsgl ~]# ll /u01/app/
total 4
drwxr-xr-x 2 oracle oinstall 4096 Dec 18 17:21 oracle
1
2
3
4
5
6
7
8
9
10
3. 安装Oracle软件
3.1 将Oracle镜像上传至服务器并挂载
注: 挂载镜像文件完成后,切换至oracle用户进行操作,避免后面出现权限问题

#将创建挂载目录,将iso镜像挂载到挂载目录下
[root@orclsgl ~]# mkdir /mnt/oracle
[root@orclsgl ~]# mount -o loop /tmp/oracle11g_11204_x86_64.iso /mnt/oracle
[root@orclsgl ~]# cd /mnt/oracle/
[root@orclsgl oracle]# ll
total 3664199
-r-xr-xr-x 1 root root 1395582860 Oct 25 2013 p13390677_112040_Linux-x86-64_1of7.zip
-r-xr-xr-x 1 root root 1151304589 Oct 25 2013 p13390677_112040_Linux-x86-64_2of7.zip
-r-xr-xr-x 1 root root 1205251894 Oct 25 2013 p13390677_112040_Linux-x86-64_3of7.zip
1
2
3
4
5
6
7
8
9
3.2 切换至oracle用户,解压zip包1、zip包2(单实例安装这两个压缩包即可)


[root@orclsgl ~]# xhost + #开放图形化权限给其他用户
[root@orclsgl ~]# su - oracle #切换至oracle用户
[oracle@orclsgl ~]# cd /mnt/oracle
[oracle@orclsgl oracle]# unzip p13390677_112040_Linux-x86-64_1of7.zip -d /tmp/ #解压至/tmp目录下
...解压过程略
[oracle@orclsgl oracle]# unzip p13390677_112040_Linux-x86-64_2of7.zip -d /tmp/
...解压过程略
[oracle@orclsgl oracle]# cd /tmp/database/
[oracle@orclsgl database]$ ./runInstaller #开始安装
...稍微等一会图形化安装界面就会弹出
1
2
3
4
5
6
7
8
9
10
3.3 安装单实例oracle数据库软件
由于没有Support Password这里就取消勾选了,也没拥有过╮(╯﹏╰)╭
由于也没填写邮箱,next的时候会出现提示,点Yes就好了

这里选择的是跳过更新

这里我们选择安装Oracle软件,本人的习惯是安装软件和建库分开处理

选择单实例数据库安装

选择简体中文,具体可按需求增加

选择企业版安装

选择安装路径,如果你的环境变量没问题,这里会自动填上环境变量中的路径

同上,如果环境变量正确,oracle组权限正确,这里保持默认即可

同上,保持默认,OSDBA对应dba,OSOPER对应oper

安装前检查

使用root用户安装缺少的依赖包

安装依赖包

[root@orclsgl ~]# yum install -y compat-libcap1 compat-libstdc++-33 libstdc++-devel \ #'\'换行
> gcc gcc-c++ ksh glibc-devel libaio-devel
#部分linux系统没有ksh这个包,安装前检查出现这个安装包的报错时,可以选择忽略
1
2
3
点击Fix & Check Again,会生成修复脚本,执行修复脚本即可

通过root用户执行修复脚本

[root@orclsgl ~]# /tmp/CVU_11.2.0.4.0_oracle/runfixup.sh
1
点击OK关闭修复脚本弹窗,会自动再次进行安装前检查
有ksh包的提示的同学,可以选择忽略,然后安装

安装Oracle软件前确认

开始安装

使用root身份执行脚本


[root@orclsgl ~]# /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@orclsgl ~]# /u01/app/oracle/product/11.2.0/db_home/root.sh
Performing root user operation for Oracle 11g

The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /u01/app/oracle/product/11.2.0/db_home

Enter the full pathname of the local bin directory: [/usr/local/bin]: #直接回车即可
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
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.
Finished product-specific root actions.
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
执行完脚本后点击OK
安装完成,点击Close关闭


4. 创建Oracle数据库
4.1 oracle用户下运行dbca命令
欢迎界面

创建一个数据库

根据需求选择数据库模板(默认第一个即可)

设置全局名、实例名全局名可带域名,也可不带,我这里没有带域名

关闭EM,根据需求自行选择

关闭自动维护任务,根据需求自行选择

设置SYS和SYSTEM用户的密码(数据库管理员密码)
可分别设置,也可统一设置,如果密码过于简单,会弹出提示,继续即可

默认选择(设置存储类型及数据存储路径)

默认即可(设置快速恢复区)

为了方便后面做实验,勾选增加样例用户

按需选择字符集(其他3个标签默认即可)

建库前确认

点击Finish开始建库

弹出的确认窗口,点击OK即可
开始建库

安装完成点击EXIT退出

4.2 验证数据库状态

#oracle用户下通过sqlplus命令登录
[oracle@orclsgl ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Dec 18 19:34:18 2018

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select instance_name,status from v$instance;

INSTANCE_NAME STATUS
---------------- ------------
orasgl OPEN

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

SQL>
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
完成单实例数据库安装

步骤2:Oracle RAC 双节点搭建
1. 规划IP地址
Oracle RAC集群一般需要Public IP、Private IP、VIP、SCAN-IP四类IP
Public IP 是该节点的真实IP
Private IP 为该节点的私有IP,用于节点间心跳同步的IP,与Public IP属不同网段,采用内网IP
VIP 为该节点的虚拟IP,用于故障漂移,与Public IP同网段
SCAN-IP 全称为Single Client Access Name - IP,是由DNS/GNS解析出来的IP,最多3个,用于负载均衡

#Public IP
orarac1 : 172.17.10.203
orarac2 : 172.17.10.204

#Private IP
orarac1 : 10.10.10.203
orarac2 : 10.10.10.204

#VIP
orarac1 : 172.17.10.213
orarac2 : 172.17.10.214

#SCAN-IP
172.17.17.10.55
172.17.17.10.56
172.17.17.10.57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2. 搭建DNS服务、NTP服务
由于是实验环境,宿主机能力有限,所以DNS服务及NTP服务搭建在之前单实例Oracle的机器上
2.1 搭建DNS服务
安装DNS服务

[root@orclsgl ~]# yum install bind bind-chroot -y
1
配置DNS

[root@orclsgl ~]# cd /etc/
#备份一下配置文件
[root@orclsgl etc]# cp -p named.conf named.conf_bak
#按如下配置修改配文件
[root@orclsgl etc]# vim named.conf
---------------------------------------------------------------
options {
listen-on port 53 { any; };
directory "/var/named";
allow-query { any; };
allow-query-cache { any; };
recursion no;
};

zone "." IN {
type hint;
file "/dev/null"; #由name.ca修改为/dev/null
};

zone "ora.com" IN {
type master;
file "ora.com.zone";
allow-update { none; };
};

zone "10.17.172.in-addr.arpa" IN { #in-addr前面的IP为172.17.10的倒序
type master;
file "10.17.172.local";
allow-update { none; };
};

zone "10.10.10.in-addr.arpa" IN { #同上
type master;
file "10.10.10.local";
allow-update { none; };
};

#include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
---------------------------------------------------------------
[root@orclsgl etc]# cd /var/named/
#配置正向解析文件,文件名依据named.conf中对应file的名字
[root@orclsgl named]# cp -p named.localhost ora.com.zone
#按如下配置修改zone文件
[root@orclsgl named]# vim ora.com.zone
---------------------------------------------------------------
$TTL 1D
@ IN SOA dns.ora.com. root.ora.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS dns.ora.com.
rac1 IN A 172.17.10.203
rac2 IN A 172.17.10.204
rac1-vip IN A 172.17.10.213
rac2-vip IN A 172.17.10.214
rac1-pri IN A 10.10.10.203
rac2-pri IN A 10.10.10.204
scan-ip IN A 172.17.10.55
scan-ip IN A 172.17.10.56
scan-ip IN A 172.17.10.57
dns IN A 172.17.10.209
---------------------------------------------------------------
#配置反向解析文件,文件名依据named.conf中对应file的名字
[root@orclsgl named]# cp -p named.loopback 10.17.172.local
[root@orclsgl named]# vim 10.17.172.local
---------------------------------------------------------------
$TTL 1D
@ IN SOA dns.ora.com. root.ora.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS dns.ora.com.
203 IN PTR rac1.ora.com.
204 IN PTR rac1.ora.com.
213 IN PTR rac1-vip.ora.com.
214 IN PTR rac1-vip.ora.com.
55 IN PTR scan-ip.ora.com.
56 IN PTR scan-ip.ora.com.
57 IN PTR scan-ip.ora.com.
---------------------------------------------------------------
[root@orclsgl named]# cp -p 10.17.172.local 10.10.10.local
[root@orclsgl named]# vim 10.10.10.local
---------------------------------------------------------------
$TTL 1D
@ IN SOA dns.ora.com. root.ora.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS dns.ora.com.
203 IN PTR rac1-pri.ora.com.
204 IN PTR rac1-pri.ora.com.
---------------------------------------------------------------
#启动DNS服务
[root@orclsgl named]# service named start
Generating /etc/rndc.key: [ OK ]
Starting named: [ OK ]
#测试DNS解析
#设置DNS服务器地址(由于这台机器的NetworkManager服务已经被停掉,所以可以直接修改resolv文件)
[root@orclsgl ~]# cat /etc/resolv.conf
nameserver 172.17.10.209
#通过nslookup命令测试
[root@orclsgl ~]# nslookup rac1.ora.com
Server: 172.17.10.209
Address: 172.17.10.209#53

Name: rac1.ora.com
Address: 172.17.10.203

[root@orclsgl ~]# nslookup scan-ip.ora.com
Server: 172.17.10.209
Address: 172.17.10.209#53

Name: scan-ip.ora.com
Address: 172.17.10.56
Name: scan-ip.ora.com
Address: 172.17.10.57
Name: scan-ip.ora.com
Address: 172.17.10.55

[root@orclsgl ~]# nslookup rac2-pri.ora.com
Server: 172.17.10.209
Address: 172.17.10.209#53

Name: rac2-pri.ora.com
Address: 10.10.10.204

[root@orclsgl ~]# nslookup 10.10.10.203
Server: 172.17.10.209
Address: 172.17.10.209#53

203.10.10.10.in-addr.arpa name = rac1-pri.ora.com.

#设置DNS服务开机自启动
[root@orclsgl ~]# chkconfig named on
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
2.2 搭建NTP服务
安装NTP服务

[root@orclsgl ~]# yum install ntp -y
1
参照下图配置NTP服务

修改ntpd文件(如若不修改,grid安装前检测的时候可能会报错–针对于节点机器)

#加一个‘ -x ’
[root@orclsgl ~]# vim /etc/sysconfig/ntpd
------------------------------------------------------
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid -g"
------------------------------------------------------
1
2
3
4
5
6
启动NTP服务

#启动NTP服务并将其设置为开机自启动
[root@orclsgl ~]# service ntpd start
Starting ntpd: [ OK ]
[root@orclsgl ~]# chkconfig ntpd on
1
2
3
4
3. 通过Openfiler为Oracle集群准备ISCSI共享存储
下载Openfiler镜像,下载安装Openfiler系统(其安装过程与Liunx系统安装过程基本一致)
镜像下载地址:http://www.openfiler.com/community/download
共准备了3块磁盘,1块装系统,另外两块用作拉存储

按回车开始装系统

然后就是欢迎页面,键盘选择,之后会提示是否格式化磁盘,选YES就行
再下一步就进入了这个页面,选择Create custom layout,然后下一步,对系统进行分区
注意保留那两块磁盘

创建分区,创建分区的时候注意,把系统分区都创建在同一块磁盘上,保留另两块
(在新建分区的时候,可以选择创建该分区在哪块磁盘上)

然后就是时区设置,取消勾选UTC,网络设置,密码设置等等,按提示下一步,直至安装系统
(此间过程在此不贴图描述了)
Reboot,完成安装

通过浏览器访问该网址即可进入UI界面

可以先通过root用户登录,修改主机名,将DHCP获取到的IP修改为静态IP
通过浏览器登录网址:https://172.17.10.207:446/
默认的用户名及密码为:openfiler/password

登录openfiler,点击Volumes,进入卷组管理界面

点击 create new physical volumes 创建物理卷

点击事先预留好的磁盘,给磁盘分区

直接将整块磁盘创建为物理卷即可

点击返回列表继续为第二块磁盘做操作

对两块磁盘均昨晚操作后,可以看到两块磁盘均分了1个区

点击卷组,创建卷组

将之前创建的两个物理卷创建为一个卷组
点击Add volume group 创建卷组

创建成功,点击Add Volume创建逻辑卷

创建逻辑卷,Filesystem/Volume type选择block,分配的大小按需自行填写,点击Create创建

创建成功

点击System标签,为自己机器的网段开发权限

增加成功

点击Services标签,将iSCSI Target 服务设置为开机自启动,并打开iSCSI Target 服务

点击Volumes标签,来到iSCSI Targets配置页面,添加新的iSCSI Target

将刚刚添加的iSCSI Target 映射出去

开放访问控制

如果已有机器发现共享存储
可通过Status标签、iSCSI Targets选项来查看状态


4. Grid安装前系统准备
4.1 准备两台Linux服务器,Desktop安装
节点1:rac1
节点2:rac2

4.2 系统环境检查(两个节点均需操作)
依照步骤1中单实例安装Oracle的系统环境检查,依次检查:
防火墙、Selinux、主机名、ip地址、hosts文件、yum源、swap、tmpfs、系统时间
注意: 用来搭RAC的节点的服务器需要双网卡,一块网卡用Public IP,另一块用Private IP
以节点1为例:
IP地址:

hosts文件(节点1为例):

4.3 修改DNS地址,并验证DNS是否可以正常解析(两个节点均需操作)
由于使用的是图形化界面,有NetworkManager服务,所以最好通过图形化设置DNS
如果直接修改resolv文件,重启后会被情掉
两个节点均需操作

右键点击图标,打开Edit Connections,选中Public IP的网卡,Edit(该截图来源于节点2)

重启NetworkManager,使DNS配置生效

验证DNS解析

4.4 设置NTP同步(两个节点均需操作)
使两个节点的服务器时间与NTP服务器同步(以rac1节点为例)

修改ntpd文件(如若不修改,grid安装前检测的时候会报错)

#加一个‘ -x ’
[root@rac1 ~]# vim /etc/sysconfig/ntpd
------------------------------------------------------
# Drop root to id 'ntp:ntp' by default.
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid -g"
------------------------------------------------------
1
2
3
4
5
6
配置完成后启动NTP服务并开机自启动

[root@rac1 ~]# service ntpd start
Starting ntpd: [ OK ]
[root@rac1 ~]# chkconfig ntpd on
1
2
3
通过命令检测是否正常同步(通常需要5~10分钟之后才能同步)
还未同步

同步正常

4.5 创建组、创建用户、设置环境变量、创建安装目录(两个节点均需操作)
此处以节点1为例

#创建组
[root@rac1 ~]# groupadd -g 1100 oinstall
[root@rac1 ~]# groupadd -g 1200 dba
[root@rac1 ~]# groupadd -g 1300 oper
[root@rac1 ~]# groupadd -g 2100 asmadmin
[root@rac1 ~]# groupadd -g 2200 asmdba
[root@rac1 ~]# groupadd -g 2300 asmoper
#创建用户
[root@rac1 ~]# useradd -u 1000 -g oinstall -G dba,asmadmin,asmdba,asmoper grid
[root@rac1 ~]# useradd -u 2000 -g oinstall -G dba,oper,asmdba,asmadmin oracle
#核对用户及所属组
[root@rac1 ~]# id oracle
uid=2000(oracle) gid=1100(oinstall) groups=1100(oinstall),1200(dba),1300(oper),2100(asmadmin),2200(asmdba)
######[订正:oracle用户需要 asmdba用户组,否则后面无法发现ASM磁盘组,本人在做第二次试验时忘记添加asmdba用户组]####
[root@rac1 ~]# id grid
uid=1000(grid) gid=1100(oinstall) groups=1100(oinstall),1200(dba),2100(asmadmin),2200(asmdba),2300(asmoper)
#设置用户密码
[root@rac1 ~]# passwd oracle
Changing password for user oracle.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@rac1 ~]# passwd grid
Changing password for user grid.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
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
设置环境变量 - - grid用户环境变量

#增加以下内容
[root@rac1 ~]# vim /home/grid/.bash_profile
---------------------------------------------------------------
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/grid
export ORACLE_OWNER=oracle
export ORACLE_SID=+ASM1 #rac2节点为ORACLE_SID=+ASM2
export ORACLE_TERM=xterm
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH
---------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
设置环境变量 - - oracle用户环境变量

#增加以下内容
[root@rac1 ~]# vim /home/oracle/.bash_profile
---------------------------------------------------------------
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_OWNER=oracle
export ORACLE_SID=orarac1 #rac2节点为ORACLE_SID=orarac2
export ORACLE_TERM=xterm
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH
---------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
创建安装目录(依照环境变量中的目录设置来创建)

[root@rac1 ~]# mkdir -p /u01/app/grid
[root@rac1 ~]# mkdir -p /u01/grid
[root@rac1 ~]# mkdir -p /u01/app/oracle
[root@rac1 ~]# chown grid:oinstall -R /u01/
[root@rac1 ~]# chown oracle:oinstall -R /u01/app/oracle/
1
2
3
4
5
4.6 修改主机shell限制(两个节点均需操作)
此处以节点1为例

#在最后一行增加以下内容
[root@rac1 ~]# vim /etc/security/limits.conf
----------------------------------------------
#grid & oracle configure shell parameters
grid soft nofile 65536
grid hard nofile 65536
grid soft nproc 16384
grid hard nproc 16384

oracle soft nofile 65536
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
----------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
4.7 修改主机内核参数(两个节点均需操作)
此处以节点1为例

#根据以下内容修改,没有的参数增加进去
#对于kernel.shm系列参数,可以按照此处修改,也可按照实际情况按需修改
[root@rac1 ~]# vim /etc/sysctl.conf
----------------------------------------------
kernel.shmmax = 4294967296
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.sem = 250 32000 100 128
fs.file-max = 6815744
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
----------------------------------------------
#使参数生效
[root@rac1 ~]# sysctl -p
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
4.8 发现共享存储(两个节点均需操作)

#安装相关的包
[root@rac2 ~]# yum install iscsi-initiator-utils -y
#发现共享存储
[root@rac1 ~]# iscsiadm -m discovery -t sendtargets -p 172.17.10.207 -l
Starting iscsid: [ OK ]
172.17.10.207:3260,1 iqn.2006-01.com.openfiler:tsn.2a8064793626
Logging in to [iface: default, target: iqn.2006-01.com.openfiler:tsn.2a8064793626, portal: 172.17.10.207,3260] (multiple)
Login to [iface: default, target: iqn.2006-01.com.openfiler:tsn.2a8064793626, portal: 172.17.10.207,3260] successful.
#服务开机自启动
[root@rac1 ~]# chkconfig iscsi on
[root@rac1 ~]# chkconfig iscsid on
#此时通过fdisk -l可以看到存储,/dev/sdb为刚刚发现的共享存储
#Openfiler的UI界面中的Status → iSCSI Targets 此时也可看到存储被发现
[root@rac1 ~]# fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007097e

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 6553 52428800 83 Linux
/dev/sda3 6553 9164 20971520 83 Linux
/dev/sda4 9164 13055 31251456 5 Extended
/dev/sda5 9164 9686 4194304 82 Linux swap / Solaris

Disk /dev/sdb: 78.7 GB, 78651588608 bytes
255 heads, 63 sectors/track, 9562 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
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
33
34
35
36
4.9 对共享存储进行UDEV绑定(两个节点均需操作)

#通过命令得到设备ID
[root@rac1 ~]# scsi_id --whitelisted --replace-whitespace --device=/dev/sdb
14f504e46494c45524b49793131652d445073652d66373731
#对设备ID进行绑定(新建的rules文件,前面的数字要大于70,70号文件为网络的规则文件,iscsi是基于网络的)
#PROGRAM为之前得到设备ID的命令,命令要写全路径,RESULT为命令得到的ID,NAME为/dev/下对应的设备名
[root@rac1 ~]# vim /etc/udev/rules.d/75-oracle-asm.rules
--------------------------------------------------------
KERNEL=="sd*", BUS=="scsi",PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name",RESULT=="14f504e46494c45524b49793131652d445073652d66373731",NAME="sdb",OWNER="grid",GROUP="asmadmin",MODE="0660"
--------------------------------------------------------
#启动udev
[root@rac1 ~]# start_udev
Starting udev: [ OK ]
#多个共享存储就写多条,设置好后可以重启一下测试一下
#节点1搞定后,将udev文件传输给节点2,然后再start_udev即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
4.10 对共享存储进行分区(由于是共享存储,在一个节点上做即可)

[root@rac1 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xdba5a57c.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help):
---------------------------------------------------
#以下命令为分区时的交互命令
# 把整个存储作为扩展分区:
#n→e→1(数字1)→回车→回车
#然后在这个扩展分区上创建所需的逻辑分区:
#以下3个分区用作OCR和Voting Disk
#n→l(字母L)→回车→ +2G 添加一个大小为2G的逻辑分区
#n→l(字母L)→回车→ +2G 添加一个大小为2G的逻辑分区
#n→l(字母L)→回车→ +2G 添加一个大小为2G的逻辑分区
#以下2个分区用作存储数据
#n→l(字母L)→回车→ +25G 添加一个大小为25G的逻辑分区
#n→l(字母L)→回车→ +25G 添加一个大小为25G的逻辑分区
#以下2个分区用作快速恢复区
#n→l(字母L)→回车→ +7G 添加一个大小为7G的逻辑分区
#n→l(字母L)→回车→ +7G 添加一个大小为7G的逻辑分区
#w 保存更改并退出
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
虽然是在rac1上做的分区,但从rac2上可以看到,分区已经同步过来了

4.11 进行裸设备绑定(两个节点均需操作)

#新建规则文件,文件号在udev绑定之后
[root@rac1 ~]# vim /etc/udev/rules.d/76-raw.rules
----------------------------------------------------
ACTION=="add", KERNEL=="sdb5", RUN+="/bin/raw /dev/raw/raw1 %N"
ACTION=="add", KERNEL=="sdb6", RUN+="/bin/raw /dev/raw/raw2 %N"
ACTION=="add", KERNEL=="sdb7", RUN+="/bin/raw /dev/raw/raw3 %N"
ACTION=="add", KERNEL=="sdb8", RUN+="/bin/raw /dev/raw/raw4 %N"
ACTION=="add", KERNEL=="sdb9", RUN+="/bin/raw /dev/raw/raw5 %N"
ACTION=="add", KERNEL=="sdb10", RUN+="/bin/raw /dev/raw/raw6 %N"
ACTION=="add", KERNEL=="sdb11", RUN+="/bin/raw /dev/raw/raw7 %N"
KERNEL=="raw[1-7]", MODE="0660", GROUP="asmadmin", OWNER="grid"
----------------------------------------------------
#启动udev
[root@rac1 ~]# start_udev
Starting udev: [ OK ]
#验证绑定情况
[root@rac1 ~]# ll /dev/raw/raw*
crw-rw---- 1 grid asmadmin 162, 1 Dec 24 10:36 /dev/raw/raw1
crw-rw---- 1 grid asmadmin 162, 2 Dec 24 10:36 /dev/raw/raw2
crw-rw---- 1 grid asmadmin 162, 3 Dec 24 10:36 /dev/raw/raw3
crw-rw---- 1 grid asmadmin 162, 4 Dec 24 10:36 /dev/raw/raw4
crw-rw---- 1 grid asmadmin 162, 5 Dec 24 10:36 /dev/raw/raw5
crw-rw---- 1 grid asmadmin 162, 6 Dec 24 10:36 /dev/raw/raw6
crw-rw---- 1 grid asmadmin 162, 7 Dec 24 10:36 /dev/raw/raw7
crw-rw---- 1 root disk 162, 0 Dec 24 10:36 /dev/raw/rawctl
#将rules文件传输给节点2,在节点2执行start_udev命令
#如果执行完start_udev命令后/dev/raw/下没有对应的设备生成,可以重启下机器再看下
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
4.12 配置节点间免秘钥通信
配置grid用户节点间免秘钥通信

#节点1
[root@rac1 ~]# su - grid
[grid@rac1 ~]$ ssh-keygen -t rsa #一路回车按下去
[grid@rac1 ~]$ ssh-keygen -t dsa #一路回车按下去
[grid@rac1 ~]$ cd .ssh
[grid@rac1 .ssh]$ cat *.pub > authorized_keys
#节点2
[root@rac2 ~]# su - grid
[grid@rac2 ~]$ ssh-keygen -t rsa #一路回车按下去
[grid@rac2 ~]$ ssh-keygen -t dsa #一路回车按下去
[grid@rac2 ~]$ cd .ssh
[grid@rac2 .ssh]$ cat *.pub > authorized_keys
#节点1
[grid@rac1 .ssh]$ scp authorized_keys grid@rac2:/home/grid/.ssh/keys_rac1
#节点2
[grid@rac2 .ssh]$ cat keys_rac1 >> authorized_keys
[grid@rac2 .ssh]$ scp authorized_keys rac1:/home/grid/.ssh/
#验证免秘钥通信(两个节点都要验证,目的是消除第一次ssh通信的提示的交互)
[grid@rac1 ~]$ ssh rac1 date
[grid@rac1 ~]$ ssh rac2 date
[grid@rac1 ~]$ ssh rac1-pri date
[grid@rac1 ~]$ ssh rac2-pri date
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
配置oracle用户节点间免秘钥通信并验证,方式同上,不在此加以赘述

5. 安装Grid
5.1 上传Oracle镜像,并做本地挂载(在节点1操作即可)
参考单实例Oracle安装,做镜像文件本地挂载
解压第3个文件到/tmp目录下


[root@rac1 ~]# su - grid
[grid@rac1 ~]$ cd /mnt/oracle/
[grid@rac1 oracle]$ unzip p13390677_112040_Linux-x86-64_3of7.zip -d /tmp/
... #解压过程略
[grid@rac1 oracle]$ cd /tmp/grid/
#进行安装前检测,将检测结果输入到result.txt文件
[grid@rac1 grid]$ ./runcluvfy.sh stage -pre crsinst -n rac1,rac2 -fixup -verbose > /tmp/result.txt
#查看result.txt文件,针对其中检查失败的项做修正
#发现依赖包部分的检查未通过,依照检测内容安装对应依赖包
#部分系统ksh包无法安装,该包的安装可以忽略
[root@rac1 ~]# yum install compat-libcap1 compat-libstdc++-33 libstdc++-devel gcc gcc-c++ ksh glibc-devel libaio-devel -y
[root@rac2 ~]# yum install compat-libcap1 compat-libstdc++-33 libstdc++-devel gcc gcc-c++ ksh glibc-devel libaio-devel -y
#绝大部分的检测失败均可依照提示修正,如依照提示修正后依旧存在失败,可以尝试重启失败节点或者百度一下失败的原因
1
2
3
4
5
6
7
8
9
10
11
12
13
5.2 开始安装grid(在节点1做即可)
grid用户下操作

#为其他用户开发图形化权限
[root@rac1 Desktop]# xhost +
#切换到grid用户
[root@rac1 Desktop]# su - grid
#切换至安装包目录
[grid@rac1 ~]# cd /tmp/grid
#开始安装
[grid@rac1 ~]# ./runInstaller
1
2
3
4
5
6
7
8
等待图形化安装界面出现
跳过软件更新

为集群安装配置OGI

自定义安装

添加简体中文支持

检查SCAN Name如果与自己的预设不符,请检查并修改

点击Add添加节点2的公有IP主机名和虚拟IP主机名
配置好后点击OK添加,然后Next进入下一步

确认公有IP和私有IP的网段以及对应的网卡

选择ASM存储

指定OCR&Voting Disk磁盘组的名字为OVDATA
选择对应的设备

指定OGI的管理员账户的密码(注意:有密码策略,需要大小写字母及数字)

没有对应设备,选择不使用IPMI,下一步

检查组名是否对应正确

检查路径是否正确

默认选择,下一步

然后是安装前检查

cvuqdisk安装包是在解压的压缩包里面,安装一下(/tmp/grid/rpm下)

[root@rac1 ~]# cd /tmp/grid/rpm
[root@rac1 rpm]# rpm -ivh cvuqdisk-1.0.9-1.rpm
#节点1安装完之后,将安装包传输至节点2,节点2也需要安装
[root@rac1 rpm]# scp cvuqdisk-1.0.9-1.rpm rac2:/tmp/
[root@rac2 tmp]# rpm -ivh cvuqdisk-1.0.9-1.rpm
1
2
3
4
5
点击Check Again再次进行安装前检查
NTP这个报错可以选择忽略,点击Next进行下一步

安装前汇总报告,点击Next进行安装

开始安装

使用root用户执行脚本,注意不可以两个节点同时执行脚本,节点1执行完之后,再在节点2执行


#节点1
[root@rac1 ~]# /u01/app/oraInventory/orainstRoot.sh
#节点2
[root@rac2 ~]# /u01/app/oraInventory/orainstRoot.sh
#节点1
[root@rac1 ~]# /u01/grid/root.sh #遇到交互提示,按回车即可
#节点2
[root@rac2 ~]# /u01/grid/root.sh #同上
#如果脚本执行失败,删除节点资源重新安装(两个节点都删除资源)
#/u01/grid/crs/install/roothas.pl -deconfig -force -verbose
1
2
3
4
5
6
7
8
9
10
点击OK继续安装

报错点掉继续

点击Next进入下一步,点击Yes继续

点击Close完成安装

切换至grid用户,验证grid安装

#检查crs状态
[grid@rac1 ~]$ crsctl check crs
CRS-4638: Oracle High Availability Services is online
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
#检查Clusterware 资源
[grid@rac1 ~]$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....ER.lsnr ora....er.type ONLINE ONLINE rac1
ora....N1.lsnr ora....er.type ONLINE ONLINE rac2
ora....N2.lsnr ora....er.type ONLINE ONLINE rac1
ora....N3.lsnr ora....er.type ONLINE ONLINE rac1
ora.OVDATA.dg ora....up.type ONLINE ONLINE rac1
ora.asm ora.asm.type ONLINE ONLINE rac1
ora.cvu ora.cvu.type ONLINE ONLINE rac1
ora.gsd ora.gsd.type OFFLINE OFFLINE
ora....network ora....rk.type ONLINE ONLINE rac1
ora.oc4j ora.oc4j.type ONLINE ONLINE rac1
ora.ons ora.ons.type ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application OFFLINE OFFLINE
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip ora....t1.type ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application OFFLINE OFFLINE
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip ora....t1.type ONLINE ONLINE rac2
ora....ry.acfs ora....fs.type ONLINE ONLINE rac1
ora.scan1.vip ora....ip.type ONLINE ONLINE rac2
ora.scan2.vip ora....ip.type ONLINE ONLINE rac1
ora.scan3.vip ora....ip.type ONLINE ONLINE rac1
#检查集群节点
[grid@rac1 ~]$ olsnodes -n
rac1 1
rac2 2
#检查监听
[grid@rac1 ~]$ srvctl status listener
Listener LISTENER is enabled
Listener LISTENER is running on node(s): rac2,rac1
#确认针对 Oracle Clusterware 文件的 Oracle ASM 功能
[grid@rac1 ~]$ srvctl status asm -a
ASM is running on rac2,rac1
ASM is enabled.
#检查 Oracle 集群注册表 (OCR)
[grid@rac1 ~]$ ocrcheck
Status of Oracle Cluster Registry is as follows :
Version : 3
Total space (kbytes) : 262120
Used space (kbytes) : 2816
Available space (kbytes) : 259304
ID : 567564319
Device/File Name : +OVDATA
Device/File integrity check succeeded

Device/File not configured

Device/File not configured

Device/File not configured

Device/File not configured

Cluster registry integrity check succeeded

Logical corruption check bypassed due to non-privileged user
#检查表决盘
[grid@rac1 ~]$ crsctl query css votedisk
## STATE File Universal Id File Name Disk group
-- ----- ----------------- --------- ---------
1. ONLINE 14e34eae15504fafbf7d0ed0198e7010 (/dev/raw/raw1) [OVDATA]
2. ONLINE 0319e59950e64fa6bf3a7cc5c3f9e26d (/dev/raw/raw2) [OVDATA]
3. ONLINE 309f30ca53364fc0bf77a4d78f061b4a (/dev/raw/raw3) [OVDATA]
Located 3 voting disk(s).
#验证结束,可以在节点2再验证一遍
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
6. 安装Oracle软件
6.1 配置ASM,为数据文件和快速恢复区创建磁盘组(在节点1操作即可)
grid用户下操作

#为其他用户开发图形化权限
[root@rac1 Desktop]# xhost +
#切换到grid用户
[root@rac1 Desktop]# su - grid
#打开ASMCA
[grid@rac1 ~]# asmca
1
2
3
4
5
6
点击create开始创建磁盘组

创建数据磁盘组RACDATA,选择磁盘,点击OK完成创建

同样的方式,为快速恢复区创建磁盘组

检查两个节点是否均有挂载磁盘组,如果有1个节点或者2个节点均为挂载,点击Mount All挂载一下

完成创建磁盘组,点击Exit退出即可

6.2 开始安装Oracle软件(在节点1操作即可)
解压压缩包1和压缩包2到指定目录(用oracle用户操作)

#为其他用户开发图形化权限
[root@rac1 Desktop]# xhost +
#切换到oracle用户
[root@rac1 Desktop]# su - oracle
#解压
[oracle@rac1 ~]$ cd /mnt/oracle
[oracle@rac1 oracle]$ unzip p13390677_112040_Linux-x86-64_1of7.zip -d /tmp/
[oracle@rac1 oracle]$ unzip p13390677_112040_Linux-x86-64_2of7.zip -d /tmp/
#开始安装
[oracle@rac1 oracle]$ cd /tmp/database
[oracle@rac1 database]$ ./runInstaller
1
2
3
4
5
6
7
8
9
10
11
去掉该选项,下一步

跳过更新,下一步

只安装软件,下一步

集群安装,默认即可

简体中午支持,下一步

企业版安装,下一步

默认选择(依照环境变量),下一步

默认选择,下一步

安装前检测(时间已同步,忽略时间同步),下一步

点击Install,开始安装

开始安装

以root用户执行脚本,先节点1,再节点2(遇到交互,回车继续即可),执行完点击OK

点击Close完成安装

由于下一步是搭建单实例到RAC的DG,所以不进行建库操作

步骤3:搭建DG
1. 主库准备(orasgl)
1.1 检查主库是否是开启归档模式

#检查归档是否开启
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 9
Current log sequence 11

#创建归档路径
SQL> !mkdir /home/oracle/archlog #在sqlplus中执行linux命令前面需要加'!'

#开启归档模式
#一致性停库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

#开启到mount状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 541068368 bytes
Database Buffers 289406976 bytes
Redo Buffers 2371584 bytes
Database mounted.

#打开归档模式
SQL> alter database archivelog;
Database altered.

#打开数据库
SQL> alter database open;
Database altered.

#修改归档路径
SQL> alter system set log_archive_dest_1='location=/home/oracle/archlog';
System altered.

#检查归档是否开启
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/archlog
Oldest online log sequence 9
Next log sequence to archive 11
Current log sequence 11
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
1.2 启用强日志模式

SQL> alter database force logging;
Database altered.
1
2
1.3 设置DG相关参数

#检查remote_login_passwordfile 参数(EXCLUSIVE)
SQL> show parameter remote_login_passwordfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string EXCLUSIVE

#检查standby_file_management 参数(AUTO)
SQL> show parameter standby_file_management
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
standby_file_management string MANUAL
#不是AUTO,修改为AUTO
SQL> alter system set standby_file_management=AUTO scope=both;
System altered.

#检查db_unique_name (有唯一名)
SQL> show parameter db_unique_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name string orasgl

#打开DG开关(orasgl为本库唯一名,orarac为RAC库唯一名)
SQL> alter system set log_archive_config='dg_config=(orasgl,orarac)';
System altered.

#配置本地归档
SQL> alter system set log_archive_dest_1='location=/home/oracle/archlog valid_for=(all_logfiles,all_roles) db_unique_name=orasgl';
System altered.
#激活归档路径1
SQL> alter system set log_archive_dest_state_1='enable';
System altered.

#配置远程归档
SQL> alter system set log_archive_dest_2='service=orarac valid_for=(online_logfiles,primary_role) db_unique_name=orarac';
System altered.
#激活归档路径2
SQL> alter system set log_archive_dest_state_2='enable';
System altered.

#配置fal_client、fal_server
SQL> alter system set fal_client='orasgl';
System altered.

SQL> alter system set fal_server='orarac';
System altered.

#配置文件路径转换(前面为远程库的数据文件路径,后面为本地库的数据文件路径)
SQL> alter system set db_file_name_convert='+RACDATA/oradata/orarac/','/u01/app/oracle/oradata/orasgl/' scope=spfile;
System altered.

SQL> alter system set log_file_name_convert='+RACDATA/oradata/orarac/','/u01/app/oracle/oradata/orasgl/' scope=spfile;
System altered.
#重启数据库,检查scope=spfile选项的配置
SQL> show parameter convert;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string +RACDATA/oradata/orarac/, /u01/app/or
acle/oradata/orasgl/
log_file_name_convert string +RACDATA/oradata/orarac/, /u01/app/or
acle/oradata/orasgl/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
1.4 将参数文件、密码文件传输给RAC库

#创建pfile文件
SQL> create pfile from spfile;
File created.
#将参数文件传输给rac1节点
[oracle@orclsgl ~]$ cd $ORACLE_HOME/dbs
[oracle@orclsgl dbs]$ scp initorasgl.ora 172.17.10.203:/tmp
#将密码文件传输给rac1、rac2节点
[oracle@orclsgl dbs]$ scp orapworasgl 172.17.10.203:/tmp
[oracle@orclsgl dbs]$ scp orapworasgl 172.17.10.204:/tmp
1
2
3
4
5
6
7
8
9
2. 备库准备(orarac)
2.1 将rac1、rac2节点的文件拷贝到指定位置

#rac1节点
[oracle@rac1 tmp]$ mv orapworasgl initorasgl.ora $ORACLE_HOME/dbs
#rac2节点
[oracle@rac2 tmp]$ mv orapworasgl $ORACLE_HOME/dbs
#根据SID修改文件名
#rac1节点
[oracle@rac1 ~]$ cd $ORACLE_HOME/dbs
[oracle@rac1 dbs]$ mv initorasgl.ora initorarac1.ora
[oracle@rac1 dbs]$ mv orapworasgl orapworarac1
#rac2节点
[oracle@rac2 ~]$ cd $ORACLE_HOME/dbs
[oracle@rac2 dbs]$ mv orapworasgl orapworarac2
1
2
3
4
5
6
7
8
9
10
11
12
2.2 将pfile修改为适用于备库的参数文件

#依照如下配置做修改
[oracle@rac1 dbs]$ vim initorarac1.ora
--------------------------------------------
*.db_domain=''
*.db_recovery_file_dest_size=4385144832
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orasglXDB)'
*.memory_target=838860800
*.open_cursors=300
*.processes=150
*.undo_tablespace='UNDOTBS1'

#以下参数需要注意

#该参数为数据库名,不可修改
*.db_name='orasgl'
#唯一名,修改为RAC库的唯一名
*.db_unique_name='orarac'
#审计文件所在路径
*.audit_file_dest='/u01/app/oracle/admin/orarac/adump'
#自诊断档案库文件所在路径
*.diagnostic_dest='/u01/app/oracle'
#控制文件放于ASM磁盘组对应位置
*.control_files='+RACDATA/oradata/orarac/control01.ctl','+RACFRA/oracle/fast_recovery_area/orarac/control02.ctl'
#快速恢复区对应路径(直接用磁盘组)
*.db_recovery_file_dest='+RACFRA'
#DG配置,不用改
*.log_archive_config='dg_config=(orasgl,orarac)'
#本地归档路径修改为ASM磁盘组路径,唯一名修改为RAC库唯一名
*.log_archive_dest_1='location=+RACFRA/oracle/archlog valid_for=(all_logfiles,all_roles) db_unique_name=orarac'
#服务名和唯一名修改为单实例库对应的名字
*.log_archive_dest_2='service=orasgl valid_for=(online_logfiles,primary_role) db_unique_name=orasgl'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
#修改为RAC库唯一名
*.fal_client='orarac'
#修改为单实例库唯一名
*.fal_server='orasgl'
#与单实例库配置正好相反
*.db_file_name_convert='/u01/app/oracle/oradata/orasgl/','+RACDATA/oradata/orarac/'
#与单实例库配置正好相反
*.log_file_name_convert='/u01/app/oracle/oradata/orasgl/','+RACDATA/oradata/orarac/'
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
--------------------------------------------
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
33
34
35
36
37
38
39
40
41
42
43
44
2.3 根据参数文件中出现的路径,创建对应的目录

#本地目录
#rac1节点
[oracle@rac1 dbs]$ mkdir -p /u01/app/oracle/admin/orarac/adump
#rac2节点
[oracle@rac2 ~]$ mkdir -p /u01/app/oracle/admin/orarac/adump
#ASM磁盘组目录(切换至grid用户,在其中一个节点上操作即可)
[grid@rac2 ~]$ asmcmd
ASMCMD> cd +RACDATA
ASMCMD> mkdir oradata
ASMCMD> cd oradata
ASMCMD> mkdir orarac
ASMCMD> cd +RACFRA
ASMCMD> mkdir oracle
ASMCMD> cd oracle
ASMCMD> mkdir fast_recovery_area
ASMCMD> cd fast_recovery_area
ASMCMD> mkdir orarac
ASMCMD> cd +RACFRA/oracle
ASMCMD> mkdir archlog
#通过命令检查配置文件中涉及到的目录是否均已创建
#rac1节点
[oracle@rac1 dbs]$ ll /u01/app/oracle/admin/orarac/adump
#rac2节点
[oracle@rac2 ~]$ ll /u01/app/oracle/admin/orarac/adump
#ASM磁盘组
[grid@rac2 ~]$ asmcmd
ASMCMD> ls -l +RACDATA/oradata/orarac/
ASMCMD> ls -l +RACFRA/oracle/fast_recovery_area/orarac/
ASMCMD> ls -l +RACFRA/oracle/fast_recovery_area
Type Redund Striped Time Sys Name
N orarac/
ASMCMD> ls -l +RACFRA/oracle/archlog
ASMCMD> ls -l +RACDATA/oradata/orarac/
#没提示报错即为正常
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
33
34
2.4 在rac1节点通过pfile启动数据库到nomount状态

[oracle@rac1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 24 17:58:44 2018

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

Connected to an idle instance.

SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initorarac1.ora'
ORACLE instance started.

Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 541068368 bytes
Database Buffers 289406976 bytes
Redo Buffers 2371584 bytes
SQL>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
3.配置监听
3.1 配置主库监听(orasgl)
配置主库的listener.ora文件

[oracle@orclsgl ~]$ cd $ORACLE_HOME/network/admin
[oracle@orclsgl admin]$ vim listener.ora
-------------------------------------------
LISTENER=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=172.17.10.209)(PORT=1521))
)

SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orasgl)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_home)
(SID_NAME=orasgl)
)
)
-------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
启动监听

[oracle@orclsgl admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-DEC-2018 18:35:21

Copyright (c) 1991, 2013, Oracle. All rights reserved.

Starting /u01/app/oracle/product/11.2.0/db_home/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/db_home/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/orclsgl/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.17.10.209)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.17.10.209)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 24-DEC-2018 18:35:21
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/db_home/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/orclsgl/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.17.10.209)(PORT=1521)))
Services Summary...
Service "orasgl" has 1 instance(s).
Instance "orasgl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
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
配置主库的tnsnames.ora文件

[oracle@orclsgl admin]$ vim tnsnames.ora
-------------------------------------------
orasgl=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=172.17.10.209)(PORT=1521))
)
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=orasgl)
)
)

orarac=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=172.17.10.203)(PORT=1521))
)
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=orarac)
)
)
-------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
3.2 配置RAC集群监听(orarac)
配置备库的listener.ora文件
注意RAC集群的监听需在grid用户下配置(节点1配置)

#加入静态监听配置
[grid@rac1 ~]$ cd /u01/grid/network/admin/
[grid@rac1 admin]$ vim listener.ora
-------------------------------------
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orarac)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1) #此处为oracle的ORACLE_HOME
(SID_NAME=orarac1)
)
)
-------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
重载监听

[grid@rac1 admin]$ lsnrctl reload

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-DEC-2018 19:19:45

Copyright (c) 1991, 2013, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
The command completed successfully
[grid@rac1 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-DEC-2018 19:19:48

Copyright (c) 1991, 2013, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 24-DEC-2018 13:04:17
Uptime 0 days 6 hr. 15 min. 30 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/rac1/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
Services Summary...
Service "orarac" has 1 instance(s).
Instance "orarac1", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

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
33
配置备库的tnsnames.ora文件
在oracle用户下建

[oracle@rac1 ~]$ cd /u01/app/oracle/product/11.2.0/db_1/network/admin/
[oracle@rac1 admin]$ vi tnsnames.ora
-------------------------------------
orasgl=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=172.17.10.209)(PORT=1521))
)
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=orasgl)
)
)

orarac=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=172.17.10.203)(PORT=1521))
)
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=orarac)
)
)
-------------------------------------
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
配置完成后传输给rac2节点一份

[oracle@rac1 admin]$ scp tnsnames.ora rac2:/u01/app/oracle/product/11.2.0/db_1/network/admin/
tnsnames.ora 100% 388 0.4KB/s 00:00
1
2
3.3 监听连接测试
单实例测试:

[oracle@orclsgl ~]$ sqlplus sys/oracle@orasgl as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 24 19:29:44 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter db_unique_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name string orasgl

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@orclsgl ~]$ sqlplus sys/oracle@orarac as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 24 19:30:42 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> show parameter db_unique_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name string orarac

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
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
33
34
35
36
37
集群测试:

[oracle@rac1 ~]$ sqlplus sys/oracle@orasgl as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 24 19:33:00 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter db_unique_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name string orasgl

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@rac1 ~]$ sqlplus sys/oracle@orarac as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 24 19:33:16 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> show parameter db_unique_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_unique_name string orarac

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
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
33
34
35
36
37
4. 数据复制
在单实例数据库上通过RMAN连接单实例数据和RAC集群

[oracle@orclsgl ~]$ rman target sys/oracle@orasgl auxiliary sys/oracle@orarac

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Dec 24 19:36:12 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database: ORASGL (DBID=4180087413)
connected to auxiliary database: ORASGL (not mounted)

RMAN> duplicate target database for standby from active database;
...
...
#过程略
#复制脚本自动运行完exit退出rman即可
#此时rac1节点库已经是mount状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
可以登录grid用户,查看文件是否复制正确(主要看数据文件和归档文件)

[root@rac2 ~]# su - grid
[grid@rac2 ~]$ asmcmd
ASMCMD> cd +RACDATA/oradata/orarac
ASMCMD> ls
control01.ctl
example01.dbf
redo01.log
redo02.log
redo03.log
sysaux01.dbf
system01.dbf
undotbs01.dbf
users01.dbf
ASMCMD> cd +RACFRA/oracle/archlog
ASMCMD> ls
1_24_995225080.dbf
1_25_995225080.dbf
1_26_995225080.dbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
检查归档是否可以正常传输

#主库操作(orasgl)
SQL> select group#,sequence#,status from v$log;
GROUP# SEQUENCE# STATUS
---------- ---------- ----------------
1 28 INACTIVE
2 29 CURRENT
3 27 INACTIVE
#目前的current日志组的seqence#是29号
#切换日志组
SQL> alter system switch logfile;
System altered.
#查看归档是否生成
[oracle@orclsgl ~]$ cd /home/oracle/archlog/
[oracle@orclsgl archlog]$ ls *29*
1_29_995225080.dbf

#备库操作(orarac)
#登录grid用户,查看asm磁盘组归档路径是否有29号文件
[grid@rac2 ~]$ asmcmd
ASMCMD> cd +RACFRA/oracle/archlog
ASMCMD> ls
1_24_995225080.dbf
1_25_995225080.dbf
1_26_995225080.dbf
1_27_995225080.dbf
1_28_995225080.dbf
1_29_995225080.dbf

#验证成功,归档可以正常传输
#如果归档未正常传输,可以用以下SQL排查
#主库运行:select error from v$archive_dest where dest_id=2; (dest_id为远程归档路径对应的ID)
#根据错误提示排查错误
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
5. 添加日志组
5.1 主库(orasgl)添加日志组 (为主库切换为备库做准备)

SQL> show parameter standby_file_management
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
standby_file_management string AUTO

#先改为手动模式
SQL> alter system set standby_file_management=manual;
System altered.

SQL> select a.group#,member,thread#,bytes/1024/1024 MB from v$logfile a, v$log b where a.group#=b.group#;
GROUP# MEMBER THREAD# MB
---------- -------------------------------------------------- ---------- ----------
3 /u01/app/oracle/oradata/orasgl/redo03.log 1 50
2 /u01/app/oracle/oradata/orasgl/redo02.log 1 50
1 /u01/app/oracle/oradata/orasgl/redo01.log 1 50
3 rows selected.

#根据redolog的大小设置对应的standbylog
SQL> alter database add standby logfile thread 1 '/u01/app/oracle/oradata/orasgl/standby01.log' size 50m;
Database altered.

SQL> alter database add standby logfile thread 1 '/u01/app/oracle/oradata/orasgl/standby02.log' size 50m;
Database altered.

SQL> alter database add standby logfile thread 1 '/u01/app/oracle/oradata/orasgl/standby03.log' size 50m;
Database altered.

#增加rac2节点使用的redo和standby日志
SQL> alter database add logfile thread 2 '/u01/app/oracle/oradata/orasgl/redo04.log' size 50m;
Database altered.

SQL> alter database add logfile thread 2 '/u01/app/oracle/oradata/orasgl/redo05.log' size 50m;
Database altered.

SQL> alter database add logfile thread 2 '/u01/app/oracle/oradata/orasgl/redo06.log' size 50m;
Database altered.

SQL> alter database add standby logfile thread 2 '/u01/app/oracle/oradata/orasgl/standby04.log' size 50m;
Database altered.

SQL> alter database add standby logfile thread 2 '/u01/app/oracle/oradata/orasgl/standby05.log' size 50m;
Database altered.

SQL> alter database add standby logfile thread 2 '/u01/app/oracle/oradata/orasgl/standby06.log' size 50m;
Database altered.

#启用thread2
SQL> alter database enable thread 2;
Database altered.

#改回自动模式
SQL> alter system set standby_file_management=auto;
System altered.
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
5.2 备库(orarac)添加日志组

SQL> show parameter standby_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
standby_file_management string AUTO

SQL> alter system set standby_file_management=manual;
System altered.
#先修改为手动

#查看redolog位置及大小
SQL> select a.group#,member,thread#,bytes/1024/1024 MB from v$logfile a, v$log b where a.group#=b.group#;
GROUP# MEMBER THREAD# MB
---------- -------------------------------------------------- ---------- ----------
1 +RACDATA/oradata/orarac/redo01.log 1 50
2 +RACDATA/oradata/orarac/redo02.log 1 50
3 +RACDATA/oradata/orarac/redo03.log 1 50

#创建对应的standbylog
SQL> alter database add standby logfile thread 1 '+RACDATA/oradata/orarac/standby01.log' size 50m;
Database altered.

SQL> alter database add standby logfile thread 1 '+RACDATA/oradata/orarac/standby02.log' size 50m;
Database altered.

SQL> alter database add standby logfile thread 1 '+RACDATA/oradata/orarac/standby03.log' size 50m;
Database altered.

#为rac2节点创建对应的redolog和standbylog
SQL> alter database add logfile thread 2 '+RACDATA/oradata/orarac/redo04.log' size 50m;
Database altered.

SQL> alter database add logfile thread 2 '+RACDATA/oradata/orarac/redo05.log' size 50m;
Database altered.

SQL> alter database add logfile thread 2 '+RACDATA/oradata/orarac/redo06.log' size 50m;
Database altered.

SQL> alter database add standby logfile thread 2 '+RACDATA/oradata/orarac/standby04.log' size 50m;
Database altered.

SQL> alter database add standby logfile thread 2 '+RACDATA/oradata/orarac/standby05.log' size 50m;
Database altered.

SQL> alter database add standby logfile thread 2 '+RACDATA/oradata/orarac/standby06.log' size 50m;
Database altered.

#改回为自动
SQL> alter system set standby_file_management=auto;
System altered.
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
6.打开数据库,测试数据同步
#在rac1节点操作
#打开数据库
SQL> alter database open;
Database altered.

#开启日志实时应用
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.

#检查日志同步情况
SQL> select sequence#,applied from v$archived_log order by 1;
SEQUENCE# APPLIED
---------- ---------
1 YES
24 YES
25 YES
26 YES
27 YES
28 YES
29 YES

#在主库(orasgl)操作更新表,检查同步
SQL> create table scott.test as select * from scott.emp;
Table created.

SQL> alter system switch logfile;
System altered.

#在备库(orarac)检查同步情况
SQL> select count(*) from scott.test;

COUNT(*)
----------
14
#同步正常
#可以通过以下SQL检查DG备库运行状态
SQL> select * from v$dataguard_stats;
NAME VALUE UNIT TIME_COMPUTED DATUM_TIME
-------------------------------- -------------------- ------------------------------ ------------------------------ ------------------------------
transport lag +00 00:00:00 day(2) to second(0) interval 12/25/2018 10:24:18 12/25/2018 10:24:18
apply lag +00 00:00:00 day(2) to second(0) interval 12/25/2018 10:24:18 12/25/2018 10:24:18
apply finish time +00 00:00:00.000 day(2) to second(3) interval 12/25/2018 10:24:18
estimated startup time 16 second 12/25/2018 10:24:18
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
33
34
35
36
37
38
39
40
41
42
43
8. 创建spfile到ASM磁盘组
在rac1节点操作

#通过pfile创建spfile
SQL> create spfile='+RACDATA/oradata/spfileorarac.ora' from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initorarac1.ora';
File created.

#修改rac1节点的pfile
#备份原pfile
[oracle@rac1 dbs]$ cp initorarac1.ora initorarac1.ora_bak
#修改rac1的pfile(清空文件内容,修改为如下内容)
[oracle@rac1 dbs]$ vim initorarac1.ora
-------------------------------------------
spfile='+RACDATA/oradata/spfileorarac.ora'
-------------------------------------------

#关闭数据库,重启,验证spfile是否正常
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 541068368 bytes
Database Buffers 289406976 bytes
Redo Buffers 2371584 bytes
Database mounted.
Database opened.

#开启实时同步
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.


#将pfile传给rac2节点,并修改成对应的文件名
[oracle@rac1 dbs]$ scp initorarac1.ora rac2:/u01/app/oracle/product/11.2.0/db_1/dbs/initorarac2.ora
initorarac1.ora 100% 43 0.0KB/s 00:00
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
33
34
35
36
37
7. 注册到CRS资源管理
在rac1节点操作即可(oracle用户操作)

#注册数据库
[oracle@rac1 ~]$ srvctl add database -d orarac -n orasgl -o /u01/app/oracle/product/11.2.0/db_1 -p +RACDATA/oradata/spfileorarac.ora -r physical_standby -a "RACDATA,RACFRA"
#各选项代表的意义可以通过srvctl add database -h查看帮助

#注册节点
[oracle@rac1 ~]$ srvctl add instance -d orarac -i orarac1 -n rac1
[oracle@rac1 ~]$ srvctl add instance -d orarac -i orarac2 -n rac2

#检查资源配置
[oracle@rac1 ~]$ srvctl config database -d orarac
Database unique name: orarac
Database name: orasgl
Oracle home: /u01/app/oracle/product/11.2.0/db_1
Oracle user: oracle
Spfile: +RACDATA/oradata/spfileorarac.ora
Domain:
Start options: open
Stop options: immediate
Database role: PHYSICAL_STANDBY
Management policy: AUTOMATIC
Server pools: orarac
Database instances: orarac1,orarac2
Disk Groups: RACDATA,RACFRA
Mount point paths:
Services:
Type: RAC
Database is administrator managed
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
8. 将rac2节点开启
#为rac2节点配置自己的UNDOTBS
#主库(orasgl)操作
SQL> select file_name,bytes/1024/1024 from dba_data_files;
FILE_NAME BYTES/1024/1024
-------------------------------------------------- ---------------
/u01/app/oracle/oradata/orasgl/users01.dbf 5
/u01/app/oracle/oradata/orasgl/undotbs01.dbf 100
/u01/app/oracle/oradata/orasgl/sysaux01.dbf 600
/u01/app/oracle/oradata/orasgl/system01.dbf 750
/u01/app/oracle/oradata/orasgl/example01.dbf 313.125

#在主库添加UNDOTBS2,RAC库同步(加完可以切一下日志)
SQL> create undo tablespace undotbs2 datafile '/u01/app/oracle/oradata/orasgl/undotbs02.dbf' size 100m;
Tablespace created.

#备库(orarac)操作
#检查UNDOTBS2是否已经同步过来
SQL> select file_name from dba_data_files

FILE_NAME
--------------------------------------------------------------------------------
+RACDATA/oradata/orarac/users01.dbf
+RACDATA/oradata/orarac/undotbs01.dbf
+RACDATA/oradata/orarac/sysaux01.dbf
+RACDATA/oradata/orarac/system01.dbf
+RACDATA/oradata/orarac/example01.dbf
+RACDATA/oradata/orarac/undotbs02.dbf

#将数据库转换为rac模式
SQL> alter system set cluster_database=true scope=spfile;
System altered.

SQL> alter system set cluster_database_instances=2 scope=spfile;
System altered.

SQL> alter system set instance_number=1 scope=spfile sid='orarac1';
System altered.

SQL> alter system set instance_number=2 scope=spfile sid='orarac2';
System altered.

SQL> alter system set thread=1 scope=spfile sid='orarac1';
System altered.

SQL> alter system set thread=2 scope=spfile sid='orarac2';
System altered.

SQL> alter system set undo_tablespace=undotbs1 scope=spfile sid='orarac1';
System altered.

SQL> alter system set undo_tablespace=undotbs2 scope=spfile sid='orarac2';
System altered.

#重启数据库(rac1节点)
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 603982928 bytes
Database Buffers 226492416 bytes
Redo Buffers 2371584 bytes
Database mounted.
Database opened.

SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.

#启动数据库(rac2节点)
SQL> startup
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 603982928 bytes
Database Buffers 226492416 bytes
Redo Buffers 2371584 bytes
Database mounted.
Database opened.

#测试数据同步
#主库(orasgl)更新表
SQL> insert into scott.test select * from scott.emp;
14 rows created.

SQL> commit;
Commit complete.

SQL> alter system switch logfile;
System altered.

#备库(orarac)节点1检测
SQL> select count(*) from scott.test;

COUNT(*)
----------
28

#备库(orarac)节点2检测
SQL> select count(*) from scott.test;

COUNT(*)
----------
28

#至此完成DG部分的所有操作
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
步骤4:切换主备
注意:切换之前,除了用于做同步的rac1节点保留,其它节点均需关闭

#关闭rac2节点
[oracle@rac1 ~]$ srvctl stop instance -d orarac -i orarac2

#检查主库(orasgl)状态
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY TO STANDBY

#将主库(orasgl)切换为备库
SQL> alter database commit to switchover to physical standby with session shutdown;
Database altered.

#将新备库(orasgl)启动到mount状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 541068368 bytes
Database Buffers 289406976 bytes
Redo Buffers 2371584 bytes
Database mounted.

#将备库(orarac)切换为主库
SQL> alter database commit to switchover to primary;
Database altered.

#将新主库(orarac)打开
SQL> alter database open;
Database altered.

#将新备库(orasgl)打开
SQL> alter database open;
Database altered.

#检查新主备状态
#主库(orarac)状态
SQL> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
ORASGL PRIMARY TO STANDBY

#备库(orasgl)状态
SQL> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
--------- ---------------- --------------------
ORASGL PHYSICAL STANDBY RECOVERY NEEDED

#备库开启日志应用
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.

#开启rac2节点
[oracle@rac1 ~]$ srvctl start instance -d orarac -i orarac2

#测试归档是否可以正常传输
#查看当前归档文件编号,主库操作(orarac)
SQL> select sequence#,status from v$log;
SEQUENCE# STATUS
---------- ----------------
46 CURRENT
44 INACTIVE
45 INACTIVE
8 INACTIVE
9 INACTIVE
10 CURRENT

#可以看出46号文件是rac1节点的,10号文件是rac2节点的
#两个节点分别执行切换日志命令
SQL> alter system switch logfile;

#在备库(orasgl)检查是否有归档过来
[oracle@orclsgl ~]$ cd /home/oracle/archlog
[oracle@orclsgl archlog]$ ls 2_10*
2_10_995225080.dbf
[oracle@orclsgl archlog]$ ls 1_46*
1_46_995225080.dbf

#测试数据同步
#主库(orarac)rac1节点操作
SQL> insert into scott.test select * from scott.emp;
14 rows created.

SQL> commit;
Commit complete.

SQL> select count(*) from scott.test;
COUNT(*)
----------
42

#备库(orasgl)检查
SQL> select count(*) from scott.test;
COUNT(*)
----------
42

#主库(orarac)rac2节点操作
SQL> insert into scott.test select * from scott.emp;
14 rows created.

SQL> commit;
Commit complete.

SQL> select count(*) from scott.test;
COUNT(*)
----------
56

#备库(orasgl)检查
SQL> select count(*) from scott.test;
COUNT(*)
----------
56

#切换成功
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
至此,单实例通过DG的方式迁移至RAC库的实验已完成
望各位同僚在生产中操作之前也最好先实验一下。
————————————————
版权声明:本文为CSDN博主「术士起个门」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43767002/article/details/85007321

标签:11g,RAC,rac1,orclsgl,oracle,grid,SQL,Oracle,root
来源: https://www.cnblogs.com/yaoyangding/p/14933268.html