概述
RAC全称是Real Application Clusters,中文译为“实时应用集群”,是ORACLE甲骨文公司提供的在低成本服务器上构建高可用性数据库系统的解决方案,部署自由,无需购买额外部件,就可以实现多节点的负载均衡和故障转移功能,满足7*24业务不间断的需求,而且,结合“Oracle数据卫士”(OracleData Guard),Oracle RAC所受到的保护就能抵御重大的场地故障、人为误操作、自然灾害等,真正实现负载均衡+异地容灾+灾难恢复。关于rac+dg的优点这里就不一一赘述了,下面进入实战部署环节。
RAC + DataGuard有四种组合,这里我们选择RAC + Single standby 的模式。
RAC Primary Database 环境:
服务器主机名 rac1 rac2
公共IP地址(eth0) 192.168.56.101 192.168.56.102
虚拟IP地址(eth0) 192.168.56.201 192.168.56.202
私有IP地址(eth1) 10.10.10.101 10.10.10.102
ORACLE RAC SID rac1 rac2
集群实例名称 rac-scan
SCAN IP 192.168.56.100
Standby Database 环境:
公共IP地址(eth0) 192.168.56.10
ORACLE_SID rac
二、RAC环境部署
以下操作均在两个节点配置!!!
1、网卡配置
[root@rac1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:58:EA:A5
TYPE=Ethernet
UUID=69c53a7f-749f-46e3-90e4-2f1e739a6c2f
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPADDR=192.168.56.101
NETMASK=255.255.255.0
GATEWAY=192.168.56.1
[root@rac1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPADDR=10.10.10.101
NETMASK=255.255.255.0
GATEWAY=10.10.10.1
2、修改/etc/hosts文件
[root@rac1 ~]# vi /etc/hosts
#public IP
192.168.56.101 rac1
192.168.56.102 rac2
#virtual IP
192.168.56.201 rac1-vip
192.168.56.202 rac2-vip
#private IP
10.10.10.101 rac1-priv
10.10.10.102 rac2-priv
#SCAN IP
192.168.56.100 rac-scan
3、配置yum源
[root@rac1 ~]# mv /etc/yum.repos.d/rhel-source.repo /etc/yum.repos.d/rhel-source.repo.bak
[root@rac1 ~]# vi /etc/yum.repos.d/rhel-local.repo
[local_repo]
name=local_repo
baseurl=file:///media/rhel_local/
enabled=1
gpgcheck=0
4、创建挂载目录
[root@rac1 ~]# mkdir /media/rhel_local/
[root@rac1 ~]# mount /dev/sr0/ /media/rhel_local/
[root@rac1 ~]# yum clean all
[root@rac1 ~]# yum repolist
5
、安装
oracle
必需的依赖包
[root@rac1 ~]# yum install -y binutils compat-libcap1 compat-libstdc++* gcc gcc-c++ glibc glibc-devel libgcc libstdc++ libstdc++-devel libaio libaio-devel sysstat make elfutils-libelf-devel
[root@rac1 ~]# yum install -y xorg-x11-apps.x86_64
[root@rac1 ~]# yum install -y xterm-253-1.el6.x86_64
[root@rac1 ~]# rpm -ivh pdksh-5.2.14-37.el5_8.1.x86_64.rpm
[root@rac1 rpm]# rpm -ivh cvuqdisk-1.0.9-1.rpm
注:1、xorg-x11-apps.x86_64和 xterm-253-1.el6.x86_64用于使用xstart远程弹出图像化界面;
2、pdksh-5.2.14-37.el5_8.1.x86_64.rpm也是oracle安装必需的安装包,但是在系统的ISO文件里边是没有的,需要自己到网上下载;不安装也是可以的,选择忽略即可。
3、cvuqdisk-1.0.9-1.rpm包是解压数据库安装包之后,位于database/rpm目录下,需要通过scp命令上传到节点2进行安装,命令如下:
[root@rac1 rpm]# scp cvuqdisk-1.0.9-1.rpm rac2:/tmp/
6、关闭防火墙
[root@rac1 ~]# chkconfig iptables off
[root@rac1 ~]# service iptables stop
[root@rac1 ~]# chkconfig iptables --list
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
7、关闭NetworkManager
[root@rac1 ~]# chkconfig NetworkManager off
[root@rac1 ~]# service NetworkManager stop
[root@rac1 ~]# chkconfig NetworkManager --list
NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off
8、禁用SELinux
[root@rac1 ~]# vim /etc/selinux/config
SELINUX=disabled
[root@rac1 ~]# sestatus
SELinux status: disabled
[root@rac1 ~]# getenforce
Disabled
9、禁用时间同步
[root@rac1 rpm]# mv /etc/ntp.conf /etc/ntp.conf.bak
10、创建oracle和grid用户及其用户组
[root@rac1 ~]# groupadd -g 201 oinstall
[root@rac1 ~]# groupadd -g 202 dba
[root@rac1 ~]# useradd -m -u 203 -g oinstall -G dba -d /home/grid -s /bin/bash grid
[root@rac1 ~]# useradd -m -u 202 -g oinstall -G dba -d /home/oracle -s /bin/bash oracle
11、验证用户并修改密码
[root@rac1 ~]# id oracle
[root@rac1 ~]# id grid
[root@rac1 ~]# id nobody
修改密码:
[root@rac1 ~]# passwd oracle
[root@rac1 ~]# passwd grid
12、创建目录结构并授予权限
[root@rac1 ~]# mkdir -p /u01/grid/app/11.2.0
[root@rac1 ~]# mkdir -p /u01/grid/app/grid
[root@rac1 ~]# mkdir -p /u01/oracle/app/11.2.0
[root@rac1 ~]# chown -R grid:oinstall /u01/grid
[root@rac1 ~]# chown -R oracle:oinstall /u01/oracle
13、配置grid和oracle用户环境变量
[root@rac1 ~]# vi /home/grid/.bash_profile
export ORACLE_SID=+ASM1
export ORACLE_BASE=/u01/grid/app/grid
export ORACLE_HOME=/u01/grid/app/11.2.0
export PATH=$ORACLE_HOME/bin:$PATH:/usr/local/bin/:.
export TEMP=/tmp
export TMP=/tmp
export TMPDIR=/tmp
umask 022
[root@rac1 ~]# vi /home/oracle/.bash_profile
export ORACLE_SID=rac1
export ORACLE_BASE=/u01/oracle/app
export ORACLE_HOME=$ORACLE_BASE/11.2.0
export ORACLE_UNQNAME=rac
export PATH=$ORACLE_HOME/bin:$PATH
umask 022
注:grid的home目录不能在base目录下
14、用户资源配置
[root@rac1 ~]# vi /etc/security/limits.conf
grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
15、
修改登录限制,添加以下行
[root@rac1 ~]# vi /etc/pam.d/login
session required pam_limits.so
16、修改内核配置文件
[root@rac1 ~]# vi /etc/sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 4194304
kernel.shmmax = 12884901887
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
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
net.ipv4.tcp_wmem = 262144 262144 262144
net.ipv4.tcp_rmem = 4194304 4194304 4194304
使配置生效
[root@rac1 ~]# sysctl -p
注:1、kernel.shmmax用于定义单个共享内存段的最大值,设置应该足够大,能够在一个共享内存段下容纳整个的SGA,这个值是可以通过公式来计算的,例如12G的物理内存设置值为:kernel.shmmax=12*1024*1024*1024-1=12884901887
2、kernel.shmall用于控制可以使用的共享内存的总页数,Linux共享内存页大小为4kb,而且一个共享内存段的最大大小是16GB,那么需要的内存页数是:kernel.shmall=16G/4kb=16*1024*1024*1024/(4*1024)=4194304
如果这个两个参数设置不合理,那么在安装的过程中就可能报错:SGA can not be greater than maximum shared memory segment size(0) 或者ORA-27102:outof memory的错误。
17、禁用大页内存
[root@rac1 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[root@rac1 ~]# grep AnonHugePages /proc/meminfo
AnonHugePages: 34816 kB
[root@rac1 ~]# vi /etc/grub.conf
transparent_hugepage=never
18、配置磁盘udev规则
[root@rac1 rpm]# lsblk
[root@rac1 rpm]# /sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/sdb
[root@rac1 rpm]# /sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/sdc
[root@rac1 rpm]# /sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/sdd
[root@rac1 rpm]# /sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/sde
[root@rac1 rpm]# /sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/sdf
[root@rac1 rpm]# /sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/sdg
[root@rac1 rpm]# vim /etc/udev/rules.d/99-oracle.rules
KERNEL=="sd*", BUS=="scsi", PROGRAM=="scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c29752a07064d7f4bee3c21493f6", NAME="asm-data1", OWNER="grid", GROUP="dba", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c29a44da3235cca533f6ed2b0b08", NAME="asm-data2", OWNER="grid", GROUP="dba", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c2941f88cb68ebe1de205a2404ca", NAME="asm-ocr1", OWNER="grid", GROUP="dba", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c29b2b10f5dd7045d3726f8b1df5", NAME="asm-ocr2", OWNER="grid", GROUP="dba", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c29e13ab98faf53fa16329cadfec", NAME="asm-ocr3", OWNER="grid", GROUP="dba", MODE="0660"
[root@rac1 ~]# start_udev
[root@rac1 ~]# ls /dev/asm*
/dev/asm-data1 /dev/asm-data2 /dev/asm-ocr1 /dev/asm-ocr2 /dev/asm-ocr3
注:1、如果是VMware Station虚拟机环境,获取不到磁盘UUID的话,则要在两个节点的.vmx文件中添加以下两个参数行后,重启
disk.locking="FALSE"
disk.EnableUUID = "TRUE"
2、如果是VirtualBox虚拟机环境,只要在虚拟介质管理把磁盘属性设置成共享即可。
19、使用secureCRT的sftp工具,上传安装包到服务器
sftp> cd /u01/soft/
sftp> lcd E:\oracle11g
sftp> lls
p13390677_112040_Linux-x86-64_1of7.zip p13390677_112040_Linux-x86-64_2of7.zip
p13390677_112040_Linux-x86-64_3of7.zip
sftp> put *
20、解压安装包
[root@rac1 ~]# cd /u01/soft/
[root@rac1 soft]# ls
p13390677_112040_Linux-x86-64_1of7.zip p13390677_112040_Linux-x86-64_2of7.zip p13390677_112040_Linux-x86-64_3of7.zip
[root@rac1 soft]# unzip p13390677_112040_Linux-x86-64_1of7.zip
[root@rac1 soft]# unzip p13390677_112040_Linux-x86-64_2of7.zip
[root@rac1 soft]# unzip p13390677_112040_Linux-x86-64_3of7.zip
[root@rac1 soft]# ll
total 3664224
drwxr-xr-x 7 root root 4096 Aug 27 2013 database
drwxr-xr-x 7 root root 4096 Aug 27 2013 grid
-rw-r--r-- 1 root root 1395582860 Oct 26 2015 p13390677_112040_Linux-x86-64_1of7.zip
-rw-r--r-- 1 root root 1151304589 Oct 26 2015 p13390677_112040_Linux-x86-64_2of7.zip
-rw-r--r-- 1 root root 1205251894 Mar 21 15:58 p13390677_112040_Linux-x86-64_3of7.zip
21、如果是vsphereclient的话,可以直接打开控制台,此时安装是最为方便的,但是如果需要远程安装的话,推荐使用xmanager的xstart工具,它能远程弹出图形化界面,就不必要到机房安装了。这里先安装集群软件。
[root@rac1 ~]# xclock
[root@rac1 ~]# xhost +
access control disabled, clients can connect from any host
[root@rac1 ~]# su - grid
[grid@rac1 ~]$ export DISPLAY=192.168.56.1:0.0
[grid@rac1 ~]$ cd /u01/soft/grid
[grid@rac1 grid]$ ./runInstaller
注:这里有个小技巧,如果我们按照以上方法还是弹不出安装界面的话,可以尝试直接使用grid用户登录,后边安装oracle库软件和dbca建库的时候也是如此。
22、由于篇幅有限,安装过程就不一一罗列了(需要的朋友可以留言,QQ或者邮箱单独发给您)。但是需要注意的是,过程中会提示我们使用root用户执行两个脚本命令,注意先后顺序、注意先节点一,再节点二。
[root@rac1 ~]# /u01/grid/app/oraInventory/orainstRoot.sh
[root@rac1 ~]# /u01/grid/app/11.2.0/root.sh
23、同理,接下来安装oracle库软件(选择install database software only)
[root@rac1 ~]# su - oracle
[oracle@rac1 ~]$ export DISPLAY=192.168.56.1:0.0
[oracle@rac1 ~]$ cd /u01/soft/database
[oracle@rac1 database]$ ./runInstaller
[root@rac1 ~]# /u01/oracle/app/oraInventory/orainstRoot.sh
[root@rac1 ~]# /u01/oracle/app/11.2.0/root.sh
24、接下来使用grid用户执行asmca创建磁盘组,使用oracle用户执行dbca命令安装数据库
25、检查已经安装成功
[grid@rac1 ~]$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.DATA.dg ora....up.type ONLINE ONLINE rac1
ora.DATA2.dg ora....up.type OFFLINE OFFLINE
ora....ER.lsnr ora....er.type ONLINE ONLINE rac1
ora....N1.lsnr ora....er.type ONLINE ONLINE rac1
ora.VOTE.dg ora....up.type ONLINE ONLINE rac1
ora.VOTE2.dg ora....up.type OFFLINE OFFLINE
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.rac.db ora....se.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 rac1
前面部分我们已经搭建了RAC环境了,此时我们需要另外一台服务器做standby database,在以下步骤之前,请确保该服务器已经安装好oracle库软件。
主库配置及相关操作
1、确认主库处于归档模式
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +DATA
Oldest online log sequence 135
Next log sequence to archive 136
Current log sequence 136
2、如果不是归档模式,必须先调整为归档模式
SQL> alter database archivelog;
3、主库设为FORCE LOGGING模式
SQL> alter database force logging;
SQL> select name,log_mode,force_logging from v$database;
NAME LOG_MODE FOR
--------- ------------ ---
RAC ARCHIVELOG YES
4、查询主库日志文件
SQL> select thread#,group#,members,bytes/1024/1024 from v$log;
THREAD# GROUP# MEMBERS BYTES/1024/1024
---------- ---------- ---------- ---------------
1 1 1 50
1 2 1 50
2 3 1 50
2 4 1 50
5、为主库添加6组standby log文件,以便它们自动被传送到备库。(一般比主库多一组)
SQL> alter database add standby logfile thread 1 group 11 size 50m;
SQL> alter database add standby logfile thread 1 group 12 size 50m;
SQL> alter database add standby logfile thread 1 group 13 size 50m;
SQL> alter database add standby logfile thread 2 group 14 size 50m;
SQL> alter database add standby logfile thread 2 group 15 size 50m;
SQL> alter database add standby logfile thread 2 group 16 size 50m;
查询添加的日志文件
SQL> select group#,thread#,bytes/1024/1024,status from v$standby_log;
GROUP# THREAD# BYTES/1024/1024 STATUS
---------- ---------- --------------- ----------
11 1 50 UNASSIGNED
12 1 50 UNASSIGNED
13 1 50 UNASSIGNED
14 2 50 UNASSIGNED
15 2 50 UNASSIGNED
16 2 50 UNASSIGNED
6 rows selected.
6、修改主库初始化参数文件
SQL> alter system set log_archive_config='DG_CONFIG=(rac,rac_dg)' scope=both sid='*';
SQL> alter system set log_archive_dest_2='SERVICE=o4db_dg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=rac_dg' scope=both sid='*';
SQL> alter system set log_archive_format='%t_%s_%r.arc' scope=spfile sid='*';
SQL> alter system set log_archive_max_processes=8 scope=both sid='*';
SQL> alter system set db_file_name_convert='/oradata/rac/','+DATA/rac/datafile' scope=spfile sid='*';
SQL> alter system set log_file_name_convert='/oradata/rac/','+DATA/rac/onlinelog' scope=spfile sid='*';
SQL> alter system set standby_file_management=AUTO scope=both sid='*';
SQL> alter system set fal_server='rac_dg' scope=both sid='*';
7、查看配置是否生效,通过下列语句查询
SQL> set linesize 500 pages 0
SQL> col value for a90
SQL> col name for a50
SQL> select name, value from v$parameter where name in ('db_name','db_unique_name','log_archive_config', 'log_archive_dest_1','log_archive_dest_2','log_archive_dest_state_1','log_archive_dest_state_2','remote_login_passwordfile','log_archive_format','log_archive_max_processes','fal_server','db_file_name_convert', 'log_file_name_convert', 'standby_file_management');
db_file_name_convert /oradata/rac, +DATA/rac/datafile
log_file_name_convert /oradata/rac, +DATA/rac/onlinelog
log_archive_dest_1 LOCATION=+DATA
log_archive_dest_2 SERVICE=rac_dg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=rac_dg
log_archive_dest_state_1 enable
log_archive_dest_state_2 ENABLE
fal_server rac_dg
log_archive_config DG_CONFIG=(rac,rac_dg)
log_archive_format %t_%s_%r.arc
log_archive_max_processes 8
standby_file_management AUTO
remote_login_passwordfile EXCLUSIVE
db_name rac
db_unique_name rac
14 rows selected.
8、配置主库本地NET服务名(两个节点,包括standby database节点)
[oracle@rac1 ~]$ vi /u01/oracle/app/11.2.0/network/admin/tnsnames.ora
RAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
)
)
RAC_DG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.10)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac_dg)
)
)
9、在主库中创建StandbyControl File,并上传到standby节点
SQL> alter database create standby controlfile as '/tmp/control_dg.ctl';
[oracle@rac1 ~]$ scp /tmp/control_dg.ctl 192.168.56.10:/oradata/rac/control01.ctl
10、主库做全库备份
RMAN> backup database format '/u01/oracle/backup/rac_%T_%s';
Starting backup at 25-MAY-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=34 instance=rac1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA/rac/datafile/system.256.939291779
input datafile file number=00002 name=+DATA/rac/datafile/sysaux.257.939291779
input datafile file number=00003 name=+DATA/rac/datafile/undotbs1.258.939291779
input datafile file number=00005 name=+DATA/rac/datafile/undotbs2.264.939292069
input datafile file number=00004 name=+DATA/rac/datafile/users.259.939291779
input datafile file number=00006 name=+DATA/rac/datafile/test.411.944053153
input datafile file number=00007 name=+DATA/rac/datafile/test.412.944053495
channel ORA_DISK_1: starting piece 1 at 25-MAY-17
channel ORA_DISK_1: finished piece 1 at 25-MAY-17
piece handle=/u01/oracle/backup/rac_20170525_10 tag=TAG20170525T211359 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:08
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 25-MAY-17
channel ORA_DISK_1: finished piece 1 at 25-MAY-17
piece handle=/u01/oracle/backup/rac_20170525_11 tag=TAG20170525T211359 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-MAY-17
11、scp备份集到standby节点
[oracle@rac1 backup]$ scp /u01/oracle/backup/* 192.168.56.10:/oradata/backup/
[email protected]'s password:
rac_20170525_10 100% 1261MB 7.5MB/s 02:48
rac_20170525_11 100% 18MB 18.0MB/s 00:01
12、为standby创建密码文件
[oracle@rac1 ~]$ scp /u01/oracle/app/11.2.0/dbs/orapwrac1 192.168.56.10:/u01/oracle/app/11.2.0/dbs/orapwrac
[email protected]'s password:
orapwrac1 100% 1536 1.5KB/s 00:00
standbydatabase配置部分
1、修改初始化文件如下
[oracle@racdg dbs]$ cat /u01/oracle/app/11.2.0/dbs/initrac.ora
*.audit_file_dest='/u01/oracle/app/admin/rac/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/oradata/rac/control01.ctl'
*.db_block_size=8192
*.db_create_file_dest='/oradata/rac'
*.db_domain=''
*.db_name='rac'
*.db_unique_name='rac_dg'
*.diagnostic_dest='/u01/oracle/app'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racXDB)'
*.fal_server='rac'
*.log_archive_config='DG_CONFIG=(rac,rac_dg)'
*.log_archive_dest_1='LOCATION=/oradata/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=rac_dg'
#*.log_archive_dest_2='SERVICE=rac LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=rac OPTIONAL PROPEN=15 MAX_FAILURE=10 NET_TIMEOUT=30'
*.log_archive_dest_2='SERVICE=rac LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=rac'
*.log_archive_dest_state_2='enable'
*.log_file_name_convert='+DATA/rac/onlinelog','/oradata/rac'
*.db_file_name_convert='+DATA/rac/datafile','/oradata/rac'
*.log_archive_format='%t_%s_%r.dbf'
*.log_archive_max_processes=8
*.open_cursors=300
*.pga_aggregate_target=536870912
*.processes=150
*.remote_login_passwordfile='exclusive'
*.standby_file_management='AUTO'
*.sga_target=2147483648
*.undo_tablespace='UNDOTBS1'
2、创建相关目录路径
[oracle@racdg dbs]$ mkdir -p /u01/oracle/app/admin/rac/adump
[oracle@racdg dbs]$ mkdir -p /oradata/rac
[oracle@racdg dbs]$ mkdir -p /oradata/arch
3、创建监听器
[oracle@racdg dbs]$ vi /u01/oracle/app/11.2.0/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = racdg)(PORT = 1521)))
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/oracle/app
4、配置备库本地NET服务名(与主库一致)
[oracle@racdg dbs]$ cat /u01/oracle/app/11.2.0/network/admin/tnsnames.ora
RAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.100)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
)
)
rac_dg =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.10)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac_dg)
)
)
主库tnsping测试(确保监听打开)
[oracle@rac1 tmp]$ tnsping rac_dg
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 26-MAY-2017 00:37:30
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.10)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = rac_dg)))
OK (0 msec)
备库tnsping测试(确保监听打开)
[oracle@racdg dbs]$ tnsping rac
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 25-MAY-2017 22:32:43
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.100)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = rac)))
OK (0 msec)
5、启动到mount状态
SQL> startup mount;
ORACLE instance started.
Total System Global Area 2137886720 bytes
Fixed Size 2254952 bytes
Variable Size 553650072 bytes
Database Buffers 1577058304 bytes
Redo Buffers 4923392 bytes
Database mounted.
6、使用rman恢复备库
[oracle@racdg ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu May 25 22:36:41 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: RAC (DBID=2527273880, not open)
RMAN> catalog start with '/oradata/backup';
using target database control file instead of recovery catalog
searching for all files that match the pattern /oradata/backup
List of Files Unknown to the Database
=====================================
File Name: /oradata/backup/rac_20170525_11
File Name: /oradata/backup/rac_20170525_10
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /oradata/backup/rac_20170525_11
File Name: /oradata/backup/rac_20170525_10
RMAN> run {
2> allocate channel ch00 type disk;
3> allocate channel ch01 type disk;
4> allocate channel ch02 type disk;
5> allocate channel ch03 type disk;
6> set newname for datafile 1 to '/oradata/rac/system.dbf';
7> set newname for datafile 2 to '/oradata/rac/sysaux.dbf';
8> set newname for datafile 3 to '/oradata/rac/undotbs1.dbf';
9> set newname for datafile 4 to '/oradata/rac/users.dbf';
10> set newname for datafile 5 to '/oradata/rac/undotbs2.dbf';
11> set newname for datafile 6 to '/oradata/rac/test.dbf';
12> set newname for datafile 7 to '/oradata/rac/test01.dbf';
13> restore database;
14> switch datafile all;
15> release channel ch00;
16> release channel ch01;
17> release channel ch02;
18> release channel ch03;
19> }
allocated channel: ch00
channel ch00: SID=148 device type=DISK
allocated channel: ch01
channel ch01: SID=24 device type=DISK
allocated channel: ch02
channel ch02: SID=149 device type=DISK
allocated channel: ch03
channel ch03: SID=25 device type=DISK
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 25-MAY-17
channel ch00: starting datafile backup set restore
channel ch00: specifying datafile(s) to restore from backup set
channel ch00: restoring datafile 00001 to /oradata/rac/system.dbf
channel ch00: restoring datafile 00002 to /oradata/rac/sysaux.dbf
channel ch00: restoring datafile 00003 to /oradata/rac/undotbs1.dbf
channel ch00: restoring datafile 00004 to /oradata/rac/users.dbf
channel ch00: restoring datafile 00005 to /oradata/rac/undotbs2.dbf
channel ch00: restoring datafile 00006 to /oradata/rac/test.dbf
channel ch00: restoring datafile 00007 to /oradata/rac/test01.dbf
channel ch00: reading from backup piece /oradata/backup/rac_20170525_10
channel ch00: piece handle=/oradata/backup/rac_20170525_10 tag=TAG20170525T211359
channel ch00: restored backup piece 1
channel ch00: restore complete, elapsed time: 00:00:45
Finished restore at 25-MAY-17
datafile 1 switched to datafile copy
input datafile copy RECID=10 STAMP=944955143 file name=/oradata/rac/system.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=11 STAMP=944955143 file name=/oradata/rac/sysaux.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=12 STAMP=944955143 file name=/oradata/rac/undotbs1.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=13 STAMP=944955143 file name=/oradata/rac/users.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=14 STAMP=944955143 file name=/oradata/rac/undotbs2.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=15 STAMP=944955143 file name=/oradata/rac/test.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=16 STAMP=944955143 file name=/oradata/rac/test01.dbf
released channel: ch00
released channel: ch01
released channel: ch02
released channel: ch03
7、standby开启日志应用
SQL> alter database recover managed standby database using current logfile disconnect from session;
8、备库查询进程状态(注意RFS进程和MRP0进程)
SQL> select process, client_process, sequence#,thread#,status from v$managed_standby;
PROCESS CLIENT_P SEQUENCE# THREAD# STATUS
--------- -------- ---------- ---------- ------------
ARCH ARCH 0 0 CONNECTED
ARCH ARCH 0 0 CONNECTED
ARCH ARCH 0 0 CONNECTED
ARCH ARCH 0 0 CONNECTED
ARCH ARCH 0 0 CONNECTED
ARCH ARCH 140 1 CLOSING
ARCH ARCH 48 2 CLOSING
ARCH ARCH 0 0 CONNECTED
RFS ARCH 0 0 IDLE
RFS ARCH 0 0 IDLE
RFS LGWR 49 2 IDLE
RFS UNKNOWN 0 0 IDLE
RFS UNKNOWN 0 0 IDLE
RFS UNKNOWN 0 0 IDLE
RFS UNKNOWN 0 0 IDLE
RFS LGWR 141 1 IDLE
RFS UNKNOWN 0 0 IDLE
RFS UNKNOWN 0 0 IDLE
RFS UNKNOWN 0 0 IDLE
RFS UNKNOWN 0 0 IDLE
RFS UNKNOWN 0 0 IDLE
MRP0 N/A 141 1 APPLYING_LOG
22 rows selected.
9、主库查询进程状态(注意LNS进程)
SQL> select process, client_process, sequence#,thread#,status from v$managed_standby;
PROCESS CLIENT_P SEQUENCE# THREAD# STATUS
--------- -------- ---------- ---------- ------------
ARCH ARCH 139 1 CLOSING
ARCH ARCH 0 0 CONNECTED
ARCH ARCH 139 1 CLOSING
ARCH ARCH 0 0 CONNECTED
ARCH ARCH 140 1 CLOSING
ARCH ARCH 137 1 CLOSING
ARCH ARCH 136 1 CLOSING
ARCH ARCH 137 1 CLOSING
LNS LNS 141 1 WRITING
9 rows selected.
10、对比主备库日志序列号
SQL> select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;
SEQUENCE# FIRST_TIM NEXT_TIME APPLIED
---------- --------- --------- ---------
44 25-MAY-17 25-MAY-17 YES
45 25-MAY-17 25-MAY-17 YES
46 25-MAY-17 25-MAY-17 YES
47 25-MAY-17 25-MAY-17 YES
48 25-MAY-17 25-MAY-17 YES
49 25-MAY-17 25-MAY-17 IN-MEMORY
136 25-MAY-17 25-MAY-17 YES
137 25-MAY-17 25-MAY-17 YES
138 25-MAY-17 25-MAY-17 YES
139 25-MAY-17 25-MAY-17 YES
140 25-MAY-17 25-MAY-17 YES
11 rows selected.
11、主库手动切换日志
SQL> alter system switch logfile;
备库查询日志序列号
SQL> select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;
SEQUENCE# FIRST_TIM NEXT_TIME APPLIED
---------- --------- --------- ---------
44 25-MAY-17 25-MAY-17 YES
45 25-MAY-17 25-MAY-17 YES
46 25-MAY-17 25-MAY-17 YES
47 25-MAY-17 25-MAY-17 YES
48 25-MAY-17 25-MAY-17 YES
49 25-MAY-17 25-MAY-17 YES
136 25-MAY-17 25-MAY-17 YES
137 25-MAY-17 25-MAY-17 YES
138 25-MAY-17 25-MAY-17 YES
139 25-MAY-17 25-MAY-17 YES
140 25-MAY-17 25-MAY-17 YES
141 25-MAY-17 25-MAY-17 IN-MEMORY
12 rows selected.
由此得知,standby已经实时应用日志了。
12、Data Guard切换到打开模式,首先需要停止日志应用
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database open read only;
Database altered.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
13、测试操作
在主库新建一张表aa,从备库能实时查询
SQL> create table aa as select * from scott.emp;
Table created.
主备库查询数据一致:
SQL> select count(*) from aa;
COUNT(*)
----------
14
需要注意的是,数据库只读打开后,只可以进行查询并恢复PRIMARY数据库的日志,但是不能进行修改数据。
至此,rac+dg的搭建部署已经完成。