CentOS7.6安装ORACLE 12C RAC + DATAGUARD

一. 网络设计

#Public IP

192.168.247.5    RAC1

192.168.247.6    RAC2

#Private IP

192.168.68.5       RAC1-priv

192.168.68.6       RAC2-priv

#Virtual IP

192.168.247.15       RAC1-vip

192.168.247.16       RAC2-vip

#Scan IP

192.168.247.7      RAC-scan

# DG

192.168.247.8     DataGuard

二.磁盘规划

懒惰的我,装虚拟机时选择了默认

三.内存规划

RAC1        8g

RAC2       8g

DG           8g

四.系统安装及设置

1.安装系统

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第1张图片

勾选Server with GUI

安装工具里面勾选:Performance Tools

                                Development Tools

                                Security Tools

                                System  Administration Tools

2.设置主机名(演示RAC1节点)

vim /etc/hostname

3.配置IP地址

cd /etc/sysconfig/network-scripts/

vim ifcfg-ens33

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第2张图片

上图网关单词写错,应该: GATEWAY

vim ifcfg-ens34

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第3张图片

上图网关单词写错,应该: GATEWAY

vim /etc/resolv.conf --添加DNS

vi    /etc/sysconfig/network-scripts/route-ens33  ---添加静态路由

4. 同步系统时间

chmod +x /etc/rc.d/rc.local
vim /etc/rc.d/rc.local
/usr/sbin/ntpdate ntp.aliyun.com

5. 关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

6. 关闭selinux

vi /etc/selinux/config
SELINUX=disabled

7. 配置/etc/hosts

#Public IP
192.168.247.5  rac1
192.168.247.6  rac2

# Private IP
192.168.68.5   rac1-priv
192.168.68.6   rac2-priv

# Virtual IP
192.168.247.15  rac1-vip
192.168.247.16  rac1-vip

# Scan IP
192.168.247.7  rac-scan

# DG IP
192.168.247.8  DataGuard
 

8. 配置资源限制

vi /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 3145728
oracle hard stack 3145728
oracle soft memlock 3145728
oracle hard memlock 3145728

grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
grid soft stack 3145728
grid hard stack 3145728

9. 配置/dev/shm

vi /etc/fstab

tmpfs /dev/shm tmpfs defaults,size=6G 0 0
mount -o remount /dev/shm

10. 配置内核参数

touch /etc/sysctl.d/97-oracledatabase-sysctl.conf

vi /etc/sysctl.d/97-oracledatabase-sysctl.conf

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 1572864
kernel.shmmax = 6442450944

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 = 1048576

sysctl --system(立即生效)
sysctl -a|grep shmmax
sysctl -a|grep shmall

11. 添加账户

groupadd oinstall
groupadd dba
groupadd oper
groupadd asmadmin
groupadd asmoper
groupadd asmdba
useradd -g oinstall -G dba,asmoper,asmadmin,asmdba grid
useradd -g oinstall -G dba,oper,asmdba,asmadmin oracle
passwd grid
passwd oracle

id oracle
id grid
2个节点的用户号必须一样

12. 创建目录

mkdir -p /u01/app/grid  #grid的ORACLE_BASE
mkdir -p /u01/app/12.2.0.1/grid    #grid的ORACLE_HOME,不能是包含关系
mkdir -p /u01/app/oracle/product/12.2.0.1/db_1
chown -R oracle:oinstall /u01
chown -R grid:oinstall /u01/app/grid
chown -R grid:oinstall /u01/app/12.2.0.1
chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01

13. 配置环境变量

Grid Infrastructure
.bash_profile
export ORACLE_SID=+ASM1
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/12.2.0.1/grid
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH

export ORACLE_SID=+ASM2
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/12.2.0.1/grid
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH

Oracle Database
.bash_profile
export ORACLE_SID=orcl1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/db_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH

export ORACLE_SID=orcl2
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/12.2.0.1/db_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH

14. 修改/etc/nsswitch.conf

修改行
hosts:      files dns myhostname

hosts:      files dns nis

15. 关闭透明大页

cat /sys/kernel/mm/transparent_hugepage/enabled
[always]代表启用
[never]代表禁用
vi /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet transparent_hugepage=never"
grub2-mkconfig -o /boot/grub2/grub.cfg
重启系统
cat /proc/cmdline

16. 禁止ntp服务

systemctl stop chronyd
systemctl disable chronyd
mv /etc/chrony.conf /etc/chrony.conf.bak
 

17. 禁止avahi-daemon服务

avahi-daemon 服务会影响 oracle的多波通信,进而导致节点重启
因此,oracle环境下不能启用 avahi-daemon 服务
systemctl stop avahi-daemon.service
systemctl disable avahi-daemon.service

18. 配置network文件

vi /etc/sysconfig/network
NOZEROCONF=yes

19. 添加共享磁盘

Share1 20G

Share2 25G

20. 配置共享磁盘.

配置vmx文件,添加如下内容:
scsi1:0.deviceType = "disk"
scsi1:1.deviceType = "disk"
disk.locking="false"
diskLib.dataCacheMaxSize="0"
diskLib.dataCacheMaxReadAheadSize="0"
diskLib.DataCacheMinReadAheadSize="0"
diskLib.dataCachePageSize="4096"
diskLib.maxUnsyncedWrites="0"
scsi1.sharedBus="virtual"
scsi1:0.mode="independent-persistent"(设置为独立模式) -- 如果已设独立模式,可能会冲突
scsi1:1.mode="independent-persistent"

21.配置udev共享存储

查看硬盘是否双节点都有加载

fdisk -l 

vi /etc/udev/rules.d/99-oracle-asmdevices.rules

KERNEL=="sd*", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode", RESULT=="36000c29bd302d56cea04ce113585e607", RUN+="/bin/sh -c 'mknod /dev/asmdisk1 b $major $minor; chown grid:asmadmin /dev/asmdisk1; chmod 0660 /dev/asmdisk1'"
KERNEL=="sd*", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode", RESULT=="36000c29e9bbd1d9724ab6823ca21bfc1", RUN+="/bin/sh -c 'mknod /dev/asmdisk2 b $major $minor; chown grid:asmadmin /dev/asmdisk2; chmod 0660 /dev/asmdisk2'"

重启UDEV:
systemctl restart systemd-udevd.service
udevadm control --reload-rules
/sbin/udevadm trigger --type=devices --action=add
/sbin/udevadm trigger --type=devices --action=change

22. 配置节点互信

在安装群集时,只需要在一个节点安装软件即可,节点互信会自动把安装的软件复制到其他节点

首先配置RAC1,RAC2 Oracle用户的节点互信

su - oracle

mkdir ~/.ssh

chmod 700 ~/.ssh

ssh-keygen -t rsa (全回车,默认即可)

ssh-keygen -t dsa (全回车,默认即可)

(以上节点互信命令,RAC1,RAC2均要执行)

返回RAC1,执行(下面互信命令 RAC2不执行)

cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys

cat ~/.ssh/id_dsa.pub >>~/.ssh/authorized_keys

ssh RAC2 cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys

ssh RAC2 cat ~/.ssh/id_dsa.pub >>~/.ssh/authorized_keys

scp ~/.ssh/authorized_keys oracle@RAC2:~/.ssh/authorized_keys

再配置RAC1,RAC2 grid用户的节点互信

su - grid

mkdir ~/.ssh

chmod 700 ~/.ssh

ssh-keygen -t rsa (全回车,默认即可)

ssh-keygen -t dsa (全回车,默认即可)

(以上节点互信命令,RAC1,RAC2均要执行)

返回RAC1,执行(下面互信命令 RAC2不执行)

cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys

cat ~/.ssh/id_dsa.pub >>~/.ssh/authorized_keys

ssh RAC2 cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys

ssh RAC2 cat ~/.ssh/id_dsa.pub >>~/.ssh/authorized_keys

scp ~/.ssh/authorized_keys grid@RAC2:~/.ssh/authorized_keys

验证节点互信

su - grid (两个节点都要验证)

date ; ssh rac1 date;

date ; ssh rac2 date;

date; ssh rac1-priv date;

date; ssh rac2-priv date;

su - oracle(两个节点都要验证)

date ; ssh rac1 date;

date ; ssh rac2 date;

date; ssh rac1-priv date;

date; ssh rac2-priv date;

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第4张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第5张图片

 

五.安装Grid

1. 上传 linuxx64_12201_grid_home.zip 至$ORACLE_HOME

     11g可以在任意目录安装,12C需在把grid软件放置$ORACLE_HOME,在$ORACLE_HOME下安装

2.解压

su - grid

cd $ORACLE_HOME

unzip linuxx64_12201_grid_home.zip 

3.安装 cvuqdisk-1.0.10-1.rpm

su root

cd /u01/app/12.2.0.1/grid/cv/rpm

rpm -ivh cvuqdisk-1.0.10-1.rpm

scp cvuqdisk-1.0.10-1.rpm rac2:/opt  --在rac2安装此包

4.在系统包里找到并安装

compat-libcap1-1.10-7.el7.x86_64.rpm

ksh-20120801-139.el7.x86_64.rpm

libaio-devel-0.3.109-13.el7.x86_64.rpm

如果联网环境的话,可以直接yum安装依赖

yum install -y  binutils*  compat-libstdc*  elfutils-libelf*  gcc*  glibc*  ksh*  libaio*  libgcc* libstdc*  make*  sysstat*  unixODBC*  libaio-devel*  glibc-devel.i686 libaio.i686 libaio-devel.i686  libstdc++-devel.i686 unixODBC-devel.i686 compat-libcap1*  compat-libcap1.i686  expat*

5.安装前检查环境:  ./runcluvfy.sh stage -pre crsinst -n rac1,rac2  -verbose

6.设置VNC

su - grid

vncpasswd      ----设置VNC密码

vncserver  :2  (5902端口)

7.解决 ORACLE 12.2 在CentOS7.6上的Bug

bug:
2019/04/09 22:31:16 CLSRSC-400: A system reboot is required to continue installing.
The command '/u01/app/12.2.0.1/grid/perl/bin/perl -I/u01/app/12.2.0.1/grid/perl/lib -I/u01/app/12.2.0.1/grid/crs/install /u01/app/12
.2.0.1/grid/crs/install/rootcrs.pl ' execution failed

在ORACLE官网查找文档1369107.1可解决此BUG

下载补丁程序

百度网盘:https://pan.baidu.com/s/15O04kGuW8a_j_zKMOOoLfw  提取码:n9gg

文件名:p26247490_12201180417ACFSApr2018RU_Linux-x86-64.zip

8.安装Grid

./gridSetup.sh -applyOneOffs /opt/soft/26247490/26247490   --/opt/soft/26247490/26247490为补丁解压路径
./opatch lspatches

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第6张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第7张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第8张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第9张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第10张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第11张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第12张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第13张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第14张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第15张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第16张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第17张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第18张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第19张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第20张图片

Grid安装后rac1-vip , rac-scan会出现在网卡中
ifconfig   --检查一下

 

六.安装ORACLE

1.上传Oracle安装包,解压至$ORACLE_HOME

      unzip linuxx64_12201_database.zip 

2.cd $ORACALE_HOME/database

   ./runInstaller

3. 安装选项如下图

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第21张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第22张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第23张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第24张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第25张图片

DBCA

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第26张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第27张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第28张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第29张图片

CentOS7.6安装ORACLE 12C RAC + DATAGUARD_第30张图片

检查 lsnrctl status
       select instance_name , status from gv$instance ;
       select * from v$dbfile

七.DG服务器安装ORACLE单机库

 

八.配置DataGuard

前提条件:

①.RAC已经成功安装

②.dg备库已经安装完相同版本的Oracle软件,无需创建数据库(无需使用DBCA创建数据库)

③.容器数据库CDB和PDB

不能基于PDB级别进行DG安装,且主备库的CDB开启需保持一致

         主库:非CDB  备库:非CDB

          主库:CDB    备库:CDB

select cdb from v$database;  --查询数据库是否是CDB数据库

开始配置:

1.RAC开启归档

创建归档文件存放路径(任一节点)

su – grid
amscmd
cd data
mkdir arch

设置归档文件存放路径

su – oracle
sqlplus / as sysbda

--设置默认归档文件名称, sid='*' 所有节点都生效
alter system set log_archive_format='%t_%s_%r.arc' scope=spfile sid='*'; 
--将所有节点的归档都存放到+data/arch
alter system set log_archive_dest_1='LOCATION=+data/arch' scope=spfile sid='*';

开启归档

shutdown immediate;(两个节点都关闭)
startup mount(启动一个节点,另一个节点自动mount)
alter database archivelog;(一个节点执行)
alter database open;(双节点执行) 

或者使用群集命令关闭/开启数据库

srvctl stop database -d orcl -o immediate

srvctl start database -d orcl

2.启用force logging功能(任一节点)

select force_logging from v$database;
alter database force logging;

3.配置主库初始化参数

查询数据库唯一名,如果没有唯一名,需要设置一个唯一名

show parameter db_unique_name

设置唯一名

alter system set db_unique_name='orcl' scope=spfile;  --修改之后需要重启数据库
alter system set db_unique_name=ORCL scope=spfile;  --如果不打' ' FXDB是大写

alter system set log_archive_config='DG_CONFIG=(orcl,dg)' scope=both sid='*';

--任一节点执行

alter system set log_archive_dest_1='LOCATION=+data/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl' scope=both sid='*';

----设置传输日志文件参数  任一节点执行

alter system set log_archive_dest_2='SERVICE=tnsdg LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dg' scope=both sid='*';

--查看standby文件管理方式 show parameter standby_file_management

--将standby文件管理方式设置为主动

alter system set standby_file_management=auto scope=both sid='*';

--设置备库往主库传数据时的 路径映射

alter system set db_file_name_convert='/orcl/app/oracle/oradata/dg','+DATA/ORCL/DATAFILE','/orcl/app/oracle/oradata/dg','+DATA/ORCL/TEMPFILE' scope=spfile sid='*';
alter system set log_file_name_convert='/orcl/app/oracle/oradata/dg','+DATA/ORCL/ONLINELOG' scope=spfile sid='*';

--做切换时,客户端、服务端指定,注意这是备库切换到主库, 所以备库是服务端,主库是客户端

alter system set fal_client='tnsorcl' scope=both sid='*';
alter system set fal_server='tnsdg' scope=both sid='*';

--日志组大小根据 查询 SELECT * FROM v$log 主库日志大小设置

alter database add standby logfile thread 1 group 11 ('+DATA') size 200M;
alter database add standby logfile thread 1 group 12 ('+DATA') size 200M;
alter database add standby logfile thread 1 group 13 ('+DATA') size 200M;

alter database add standby logfile thread 2 group 14 ('+DATA') size 200M;
alter database add standby logfile thread 2 group 15 ('+DATA') size 200M;
alter database add standby logfile thread 2 group 16 ('+DATA') size 200M;

--查看参数设置

show parameter log 
show parameter fal

配置TNS

节点rac1:
tnsorcl =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

tnsdg =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

节点rac2:
tnsorcl =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

tnsdg =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

拷贝密码文件

11g及之前版本数据库中密码文件存储在$ORACLE_HOME/dbs下
orapwSID
12C开始,密码文件存放在ASM共享存储中。
12cRAC中:+DATA/FXDB/PASSWORD/pwdfxdb.282.1006058263
查询密码文件位置:
srvctl config database -d orcl

主库和备库的SYS密码必须一致。

su - grid

amscmd
pwcopy +DATA/FXDB/PASSWORD/pwdfxdb.282.1006058263  /tmp/mypwfile
scp  /tmp/mypwfile dg:/u01/app/oracle/product/12.2.0.1/db_1/dbs

登录DG服务器,将密码文件改名
mv mypwfile orapwdg

4.配置备库:

touch initdg.ora

db_name='orcl'  ---与主库一致  show parameter db_name
db_unique_name='dg'
sga_target=2G
pga_aggregate_target=800M
audit_file_dest='/u01/app/oracle/admin/dg/adump' ---需备库手工创建
compatible='12.2.0'  --与主库一致  show parameter compatible
remote_login_passwordfile='EXCLUSIVE'
control_files='/u01/app/oracle/oradata/dg/control01.ctl','/u01/app/oracle/oradata/dg/control02.ctl'   ---路径需备库手工创建
log_archive_config='DG_CONFIG=(orcl,dg)'  --与主库设置保持一致
---设置备库归档路径
log_archive_dest_1='LOCATION=/u01/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) 
DB_UNIQUE_NAME=dg'

log_archive_dest_2='SERVICE=tnsorcl LGWR SYNC AFFIRM 
VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'

log_archive_format='%t_%s_%r.arc'
-----查询主库数据文件路径  SELECT * FROM V$dbfile
-----查询主数据库临时文件路径  SELECT * FROM V$tempfile

db_file_name_convert='+DATA/ORCL/DATAFILE','/u01/app/oracle/oradata/dg',
'+DATA/ORCL/TEMPFILE','/u01/app/oracle/oradata/dg'
---SELECT * FROM V$LOGFILE
log_file_name_convert='+DATA/ORCL/ONLINELOG','/u01/app/oracle/oradata/dg'
fal_client='tnsdg'
fal_server='tnsorcl'
standby_file_management='AUTO'

 

su - oracle

mkdir -p /u01/app/oracle/admin/dg/adump

mkdir -p /u01/app/oracle/oradata/dg
mkdir -p /u01/arch

sqlplus / as sysdba

create spfile from pfile;

startup nomount


3.配置静态监听

listener.ora
LISTENER1 =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1522))
      )
    )
  )

SID_LIST_LISTENER1 =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcl)
      (SID_NAME = dg)
      (ORACLE_HOME = /u01/app/oracle/product/12.2.0.1/db_1)
    )
  )

lsnrctl start listener1

备库为什么一定要配置静态监听?
nomount状态下必须使用静态监听才能连接到实例


4.tns配置


tnsnames.ora
tnsorcl =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )
  
tnsdg =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

 5.测试tns


主库2节点和备库:
tnsping tnsfxdb
tnsping tnssbdb
主库和备库:
sqlplus sys/woailyoo@tnsorcl as sysdba
sqlplus sys/woailyoo@tnsdg   as sysdba
SELECT INSTANCE_NAME,STATUS FROM V$INSTANCE;


使用Duplicate创建物理standby


1.duplicate
1.1离线--rman备份集
1.2在线--duplicate,适合局域网
rman target sys/woailyoo@tnsorcl  必须指定密码
rman target /  最好不要使用---可能会有密码错误
connect auxiliary sys/woailyoo@tnsdg

rman target sys/woailyoo@tnsorcl auxiliary sys/woailyoo@tnsdg

duplicate target database for standby from active database nofilenamecheck;

添加Standby日志组并开启同步

standby日志组:redo日志组+1 2+1
standby日志组与redo日志组大小必须一致

--查看主库日志组
SELECT THREAD#,SEQUENCE#,BYTES,  MEMBERS FROM V$LOG ;
SELECT * FROM v$logfile

查看standby日志组:---备库查看

select group#,thread#,sequence#,archived,status, BYTES from v$standby_log;

备库:  --大小需根据主库 SELECT * FROM V$LOG  设置(跟主库一致)
alter database add standby logfile thread 1 group 11 ('/u01/app/oracle/oradata/dg/stredo11.log') size 200M;
alter database add standby logfile thread 1 group 12 ('/u01/app/oracle/oradata/dg/stredo12.log') size 200M;
alter database add standby logfile thread 1 group 13 ('/u01/app/oracle/oradata/dg/stredo13.log') size 200M;

alter database add standby logfile thread 2 group 14 ('/u01/app/oracle/oradata/dg/stredo14.log') size 200M;
alter database add standby logfile thread 2 group 15 ('/u01/app/oracle/oradata/dg/stredo15.log') size 200M;
alter database add standby logfile thread 2 group 16 ('/u01/app/oracle/oradata/dg/stredo16.log') size 200M;

开启同步:
alter database open;---备库

开启redo应用(实时同步)commit

alter database recover managed standby database disconnect; (12C)---备库

停止redo应用----停止实实同步
alter database recover managed standby database cancel;

查看状态:
select name,open_mode,database_role,protection_mode,protection_level from v$database;

更改保护模式:

alter database set standby database to maximize performance;最大性能
alter database set standby database to maximize availability;最大可用 ---主备都执行
alter database set standby database to maximize protection;最大保护

 

测试同步:
create table t(id int);
insert into t values(100);
commit;

备库查询:
select * from v$managed_standby;备库查询
select * from v$standby_log;

switchover主备切换

1.检查是否同步(验证是否有gap)

select status, gap_status from v$archive_dest_status where dest_id = 2;  --最保险的还要执行,insert

2.检查主备角色

select database_role from v$database;

主库: primary

备库: physical standby

3.检查是否满足切换条件

select name,database_role,switchover_status from v$database;

主库: to standby  或者  session active(有会话连接)

备库:NOT ALLOWED 

4.验证TNS(主备都验证)

tnsping tnsorcl

tnsping tnsdg

5.验证主库db_file_name_convert是否设置

sqlplus / as sysdba

show parameter db_file

show parameter fal_ 

show parameter log_file

如果没设置则设置:

alter system set db_file_name_convert='/orcl/app/oracle/oradata/dg','+DATA/ORCL/DATAFILE','/orcl/app/oracle/oradata/dg','+DATA/ORCL/TEMPFILE' scope=spfile sid='*';

alter system set fal_client='tnsorcl' scope=both sid='*';
alter system set fal_server='tnsdg' scope=both sid='*';
alter system set log_file_name_convert='/orcl/app/oracle/oradata/dg','+DATA/ORCL/ONLINELOG' scope=spfile sid='*';

6.添加standby redo log

--日志组大小根据 查询 SELECT * FROM v$log 主库日志大小设置

alter database add standby logfile thread 1 group 11 ('+DATA') size 200M;
alter database add standby logfile thread 1 group 12 ('+DATA') size 200M;
alter database add standby logfile thread 1 group 13 ('+DATA') size 200M;

alter database add standby logfile thread 2 group 14 ('+DATA') size 200M;
alter database add standby logfile thread 2 group 15 ('+DATA') size 200M;
alter database add standby logfile thread 2 group 16 ('+DATA') size 200M;

 

7.切换主备

(12C新特性)主库执行:
alter database switchover to dg verify;
alter database switchover to dg;(执行完主库所有节点自动关闭 , 备库变为mount状态)
alter database switchover to dg force;
主库:shutdown
备库:mount

--启动新备库(原主库)

startup

--新备库(原主库)开启standby同步

alter database recover managed standby database disconnect;

--启动新主库(原备库)

startup

--查看新主备状态
select name,open_mode,database_role,protection_mode,protection_level,switchover_status from v$database;

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Oracle,Oracle12C,RAC,DG,DataGuard)