dg 如何连接oracle_dg4msql oracle 连接 多个 sqlserver - CSDN
精华内容
参与话题
  • 报错信息 根据客户提供的报错信息, ORA-00604: error occurred at recursive SQL level 1 ORA-16000: database open for read-only access ...怀疑是触发器导致的问题,自己的测试...[oracle@adg1 dbs]$ sqlpl...

    报错信息

    根据客户提供的报错信息,
    
    ORA-00604: error occurred at recursive SQL level 1
    ORA-16000: database open for read-only access

    怀疑是触发器导致的问题,自己的测试环境进行测试。

     

    测试一、dg环境开启审计参数是否影响

    [oracle@adg1 dbs]$ sqlplus tt/tt@adgtns
    SQL*Plus: Release 11.2.0.4.0 Production on Sat May 4 16:56:55 2019
    SQL> 
    audit_trail string OS
    
    SQL> alter system set audit_trail=db scope=spfile;
    System altered.
    SQL> startup force;
    DG环境,备库如果开启审计功能,配置db将自动转换为OS

     

    SQL> audit select,insert,update,delete on scott.emp by access;
    Audit succeeded
    
    SQL> conn tt/tt
    Connected.
    SQL> select * from scott.emp where rownum=1;
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- --------------------
    7369 SMITH CLERK 7902 17-DEC-80 800 20
    SQL> conn / as sysdba
    Connected.
    SQL> show parameter audit
    NAME TYPE VALUE
    ------------------------------------ ----------- ------------------------------
    audit_file_dest string /u01/app/oracle/admin/tt/adump
    
    测试发现,备库开启审计功能,并不会导致无法连接。
    Sat May 4 17:31:00 2019 +08:00
    LENGTH: "267"
    SESSIONID:[10] "4294967295" ENTRYID:[1] "1" STATEMENT:[1] "1" USERID:[2] "TT" USERHOST:[4] "adg1" TERMINAL:[5]
    "pts/1" ACTION:[3] "100" RETURNCODE:[1] "0" COMMENT$TEXT:[26] "Authenticated by: DATABASE" OS$USERID:[6]
    "oracle" DBID:[10] "1969706720" PRIV$USED:[1] "5"
    Sat May 4 17:31:40 2019 +08:00
    LENGTH: "263"
    SESSIONID:[10] "4294967295" ENTRYID:[1] "2" STATEMENT:[2] "10" USERID:[2] "TT" USERHOST:[4] "adg1" TERMINAL:[5]
    "pts/1" ACTION:[1] "3" RETURNCODE:[1] "0" OBJ$CREATOR:[5] "SCOTT" OBJ$NAME:[3] "EMP" OS$USERID:[6]
    "oracle" DBID:[10] "1969706720" PRIV$USED:[2] "47"
    经过测试,备库开启审计,不会影响连接。

     

    测试二、手工创建登录触发器

    主库创建触发器
    create table UC_LOGON_OFF ( user_id VARCHAR2(
    30), session_id NUMBER(8), host VARCHAR2(30), last_program VARCHAR2(48), last_action VARCHAR2(32), last_module VARCHAR2(32), logon_day DATE, logon_time VARCHAR2(10), logoff_day DATE, logoff_time VARCHAR2(10), elapsed_minutes NUMBER(8), sid NUMBER(8), serial NUMBER(8) ) tablespace USERS pctfree 10 initrans 1 maxtrans 255; CREATE OR REPLACE TRIGGER TRIG_LOGON_AUDIT AFTER LOGON ON DATABASE BEGIN INSERT INTO sys.uc_logon_off select USER, SYS_CONTEXT ('USERENV', 'SESSIONID'), SYS_CONTEXT ('USERENV', 'HOST'), NULL, NULL, NULL, SYSDATE, TO_CHAR (SYSDATE, 'yyyy-mm-dd hh24:mi:ss'), NULL, NULL, NULL, NULL, null from dual; END; alter table uc_logon_off modify logon_time varchar2(30); SQL> alter system switch logfile;

     

    --备库开启MRP同步应用,测试前tt可以连接
    recover managed standby database disconnect from session;
    SQL> conn tt/tt
    ERROR:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-16000: database open for read-only access
    ORA-06512: at line 2
    Warning: You are no longer connected to ORACLE.
    
    alert.log 
    Sat May 04 17:10:33 2019
    Errors in file /u01/app/oracle/diag/rdbms/tt/tt/trace/tt_ora_16392.trc:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-16000: database open for read-only access
    ORA-06512: at line 2

     

    主库处理,禁用触发器
    SQL> select OWNER,TRIGGER_NAME,TRIGGERING_EVENT,TABLE_OWNER,TABLE_NAME,STATUS,ACTION_TYPE from dba_triggers where TRIGGER_NAME='TRIG_LOGON_AUDIT' OWNER TRIGGER_NAME TRIGGERING_EVENT TABLE_OWNER TABLE_NAME STATUS ACTION_TYPE ---------- ------------------------------ -------------------- ------------------------------ ------------------------------ -------- ----------- SYS TRIG_LOGON_AUDIT LOGON SYS ENABLED PL/SQL ALTER TRIGGER "SYS"."TRIG_LOGON_AUDIT" DISABLE; --备库OK SQL> conn tt/tt Connected.

      

     

    转载于:https://www.cnblogs.com/lvcha001/p/10858305.html

    展开全文
  • 实验:Oracle单实例通过DG迁移至RAC集群(Oracle 11g)步骤1:Oracle单实例搭建安装前准备:步骤2:Oracle RAC 双节点搭建步骤3:搭建DG步骤4:切换主备 步骤1:Oracle单实例搭建 操作系统:Oracle Linux 6.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 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.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.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.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.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.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.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.9 系统时间

    #系统时间是需要注意的,也可以配置时间同步,注意时区
    [root@orclsgl ~]# date
    Mon Dec 17 17:28:49 CST 2018
    

    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的设置为本人个人习惯
    

    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为本人个人习惯
    

    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	#根据数据库字符集书写
    -------------------------------------------------------------
    

    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
    

    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
    

    3.2 切换至oracle用户,解压zip包1、zip包2(单实例安装这两个压缩包即可)
    1/2of7

    [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		#开始安装
    ...稍微等一会图形化安装界面就会弹出
    

    3.3 安装单实例oracle数据库软件
    由于没有Support Password这里就取消勾选了,也没拥有过╮(╯﹏╰)╭
    由于也没填写邮箱,next的时候会出现提示,点Yes就好了
    Install-Step1
    这里选择的是跳过更新
    Install-Step2
    这里我们选择安装Oracle软件,本人的习惯是安装软件和建库分开处理
    Install-Step3
    选择单实例数据库安装
    Install-Step4
    选择简体中文,具体可按需求增加
    Install-Step5
    选择企业版安装
    Install-Step6
    选择安装路径,如果你的环境变量没问题,这里会自动填上环境变量中的路径
    Install-Step7
    同上,如果环境变量正确,oracle组权限正确,这里保持默认即可
    Install-Step8
    同上,保持默认,OSDBA对应dba,OSOPER对应oper
    Install-Step9
    安装前检查
    Install-Step10
    使用root用户安装缺少的依赖包
    Install-Step11
    安装依赖包

    [root@orclsgl ~]# yum install -y compat-libcap1 compat-libstdc++-33 libstdc++-devel \		#'\'换行
    > gcc gcc-c++ ksh glibc-devel libaio-devel
    #部分linux系统没有ksh这个包,安装前检查出现这个安装包的报错时,可以选择忽略
    

    点击Fix & Check Again,会生成修复脚本,执行修复脚本即可
    Install-Step12
    通过root用户执行修复脚本

    [root@orclsgl ~]# /tmp/CVU_11.2.0.4.0_oracle/runfixup.sh
    

    点击OK关闭修复脚本弹窗,会自动再次进行安装前检查
    有ksh包的提示的同学,可以选择忽略,然后安装
    Install-Step13
    安装Oracle软件前确认
    Install-Step14
    开始安装
    Install-Step15
    使用root身份执行脚本
    Install-Step16

    [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.
    

    执行完脚本后点击OK
    安装完成,点击Close关闭
    Install-Step17

    4. 创建Oracle数据库

    4.1 oracle用户下运行dbca命令
    欢迎界面
    DBCA-Step1
    创建一个数据库
    DBCA-Step2
    根据需求选择数据库模板(默认第一个即可)
    DBCA-Step3
    设置全局名、实例名全局名可带域名,也可不带,我这里没有带域名
    DBCA-Step4
    关闭EM,根据需求自行选择
    DBCA-Step5
    关闭自动维护任务,根据需求自行选择
    DBCA-Step6
    设置SYS和SYSTEM用户的密码(数据库管理员密码)
    可分别设置,也可统一设置,如果密码过于简单,会弹出提示,继续即可
    DBCA-Step7
    默认选择(设置存储类型及数据存储路径)
    DBCA-Step8
    默认即可(设置快速恢复区)
    DBCA-Step9
    为了方便后面做实验,勾选增加样例用户
    DBCA-Step10
    按需选择字符集(其他3个标签默认即可)
    DBCA-Step11
    建库前确认
    DBCA-Step12
    点击Finish开始建库
    DBCA-Step13
    弹出的确认窗口,点击OK即可
    开始建库
    DBCA-Step14
    安装完成点击EXIT退出
    DBCA-Step15
    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>
    

    完成单实例数据库安装

    步骤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
    

    2. 搭建DNS服务、NTP服务

    由于是实验环境,宿主机能力有限,所以DNS服务及NTP服务搭建在之前单实例Oracle的机器上
    2.1 搭建DNS服务
    安装DNS服务

    [root@orclsgl ~]# yum install bind bind-chroot -y
    

    配置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
    

    2.2 搭建NTP服务
    安装NTP服务

    [root@orclsgl ~]# yum install ntp -y
    

    参照下图配置NTP服务
    NTP-1
    修改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"
    ------------------------------------------------------
    

    启动NTP服务

    #启动NTP服务并将其设置为开机自启动
    [root@orclsgl ~]# service ntpd start
    Starting ntpd:                                             [  OK  ]
    [root@orclsgl ~]# chkconfig ntpd on
    

    3. 通过Openfiler为Oracle集群准备ISCSI共享存储

    下载Openfiler镜像,下载安装Openfiler系统(其安装过程与Liunx系统安装过程基本一致)
    镜像下载地址:http://www.openfiler.com/community/download
    共准备了3块磁盘,1块装系统,另外两块用作拉存储
    Openfiler-1
    按回车开始装系统
    Openfiler-2
    然后就是欢迎页面,键盘选择,之后会提示是否格式化磁盘,选YES就行
    再下一步就进入了这个页面,选择Create custom layout,然后下一步,对系统进行分区
    注意保留那两块磁盘
    Openfiler-3
    创建分区,创建分区的时候注意,把系统分区都创建在同一块磁盘上,保留另两块
    (在新建分区的时候,可以选择创建该分区在哪块磁盘上)
    Openfiler-4
    然后就是时区设置,取消勾选UTC,网络设置,密码设置等等,按提示下一步,直至安装系统
    (此间过程在此不贴图描述了)
    Reboot,完成安装
    Openfiler-5
    通过浏览器访问该网址即可进入UI界面
    Openfiler-6
    可以先通过root用户登录,修改主机名,将DHCP获取到的IP修改为静态IP
    通过浏览器登录网址:https://172.17.10.207:446/
    默认的用户名及密码为:openfiler/password
    Openfiler-7
    登录openfiler,点击Volumes,进入卷组管理界面
    Openfiler-8
    点击 create new physical volumes 创建物理卷
    Openfiler-9
    点击事先预留好的磁盘,给磁盘分区
    Openfiler-10
    直接将整块磁盘创建为物理卷即可
    Openfiler-11
    点击返回列表继续为第二块磁盘做操作
    Openfiler-12
    对两块磁盘均昨晚操作后,可以看到两块磁盘均分了1个区
    Openfiler-13
    点击卷组,创建卷组
    Openfiler-14
    将之前创建的两个物理卷创建为一个卷组
    点击Add volume group 创建卷组
    Openfiler-15
    创建成功,点击Add Volume创建逻辑卷
    Openfiler-16
    创建逻辑卷,Filesystem/Volume type选择block,分配的大小按需自行填写,点击Create创建
    Openfiler-17
    创建成功
    Openfiler-18
    点击System标签,为自己机器的网段开发权限
    Openfiler-19
    增加成功
    Openfiler-20
    点击Services标签,将iSCSI Target 服务设置为开机自启动,并打开iSCSI Target 服务
    Openfiler-21
    点击Volumes标签,来到iSCSI Targets配置页面,添加新的iSCSI Target
    Openfiler-22
    将刚刚添加的iSCSI Target 映射出去
    Openfielr-23
    开放访问控制
    Openfiler-24
    如果已有机器发现共享存储
    可通过Status标签、iSCSI Targets选项来查看状态
    Openfiler-25

    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地址:
    IP地址
    hosts文件(节点1为例):
    hosts文件
    4.3 修改DNS地址,并验证DNS是否可以正常解析(两个节点均需操作)
    由于使用的是图形化界面,有NetworkManager服务,所以最好通过图形化设置DNS
    如果直接修改resolv文件,重启后会被情掉
    两个节点均需操作
    NetworkManager-1
    右键点击图标,打开Edit Connections,选中Public IP的网卡,Edit(该截图来源于节点2)
    NetworkManager-2
    重启NetworkManager,使DNS配置生效
    NetworkManager-3
    验证DNS解析
    验证DNS解析
    4.4 设置NTP同步(两个节点均需操作)
    使两个节点的服务器时间与NTP服务器同步(以rac1节点为例)
    NTP同步
    修改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"
    ------------------------------------------------------
    

    配置完成后启动NTP服务并开机自启动

    [root@rac1 ~]# service ntpd start
    Starting ntpd:                                             [  OK  ]
    [root@rac1 ~]# chkconfig ntpd on
    

    通过命令检测是否正常同步(通常需要5~10分钟之后才能同步)
    还未同步
    NTP同步
    同步正常
    NTP同步验证
    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.
    

    设置环境变量 - - 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
    ---------------------------------------------------------------
    

    设置环境变量 - - 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
    ---------------------------------------------------------------
    

    创建安装目录(依照环境变量中的目录设置来创建)

    [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/
    

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

    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
    

    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
    

    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即可
    

    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							保存更改并退出
    

    虽然是在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/下没有对应的设备生成,可以重启下机器再看下
    

    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
    

    配置oracle用户节点间免秘钥通信并验证,方式同上,不在此加以赘述

    5. 安装Grid

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

    [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
    #绝大部分的检测失败均可依照提示修正,如依照提示修正后依旧存在失败,可以尝试重启失败节点或者百度一下失败的原因
    

    5.2 开始安装grid(在节点1做即可)
    grid用户下操作

    #为其他用户开发图形化权限
    [root@rac1 Desktop]# xhost +
    #切换到grid用户
    [root@rac1 Desktop]# su - grid
    #切换至安装包目录
    [grid@rac1 ~]# cd /tmp/grid
    #开始安装
    [grid@rac1 ~]# ./runInstaller
    

    等待图形化安装界面出现
    跳过软件更新
    grid-1
    为集群安装配置OGI
    grid-2
    自定义安装
    grid-3
    添加简体中文支持
    grid-4
    检查SCAN Name如果与自己的预设不符,请检查并修改
    grid-5
    点击Add添加节点2的公有IP主机名和虚拟IP主机名
    配置好后点击OK添加,然后Next进入下一步
    grid-6
    确认公有IP和私有IP的网段以及对应的网卡
    grid-7
    选择ASM存储
    grid-8
    指定OCR&Voting Disk磁盘组的名字为OVDATA
    选择对应的设备
    grid-9
    指定OGI的管理员账户的密码(注意:有密码策略,需要大小写字母及数字)
    grid-10
    没有对应设备,选择不使用IPMI,下一步
    grid-11
    检查组名是否对应正确
    grid-12
    检查路径是否正确
    grid-13
    默认选择,下一步
    grid-14
    然后是安装前检查
    grid-15
    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
    

    点击Check Again再次进行安装前检查
    NTP这个报错可以选择忽略,点击Next进行下一步
    grid-16
    安装前汇总报告,点击Next进行安装
    grid-17
    开始安装
    grid-18
    使用root用户执行脚本,注意不可以两个节点同时执行脚本,节点1执行完之后,再在节点2执行
    grid-19

    #节点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
    

    点击OK继续安装
    grid-20
    报错点掉继续
    grid-21
    点击Next进入下一步,点击Yes继续
    grid-22
    点击Close完成安装
    grid-23
    切换至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再验证一遍
    

    6. 安装Oracle软件

    6.1 配置ASM,为数据文件和快速恢复区创建磁盘组(在节点1操作即可)
    grid用户下操作

    #为其他用户开发图形化权限
    [root@rac1 Desktop]# xhost +
    #切换到grid用户
    [root@rac1 Desktop]# su - grid
    #打开ASMCA
    [grid@rac1 ~]# asmca
    

    点击create开始创建磁盘组
    ASMCA-1
    创建数据磁盘组RACDATA,选择磁盘,点击OK完成创建
    ASMCA-2
    同样的方式,为快速恢复区创建磁盘组
    ASMCA-3
    检查两个节点是否均有挂载磁盘组,如果有1个节点或者2个节点均为挂载,点击Mount All挂载一下
    ASMCA-4
    完成创建磁盘组,点击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
    

    去掉该选项,下一步
    RAC-1
    跳过更新,下一步
    RAC-2
    只安装软件,下一步
    RAC-3
    集群安装,默认即可
    RAC-4
    简体中午支持,下一步
    RAC-5
    企业版安装,下一步
    RAC-6
    默认选择(依照环境变量),下一步
    RAC-7
    默认选择,下一步
    RAC-8
    安装前检测(时间已同步,忽略时间同步),下一步
    RAC-9
    点击Install,开始安装
    RAC-10
    开始安装
    RAC-11
    以root用户执行脚本,先节点1,再节点2(遇到交互,回车继续即可),执行完点击OK
    RAC-12
    点击Close完成安装
    RAC-13
    由于下一步是搭建单实例到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 启用强日志模式

    SQL> alter database force logging;
    Database altered.
    

    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.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
    

    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
    

    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'
    --------------------------------------------
    

    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/
    #没提示报错即为正常
    

    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>
    

    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)
        )
      )
    -------------------------------------------
    

    启动监听

    [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
    

    配置主库的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)
        )
      )
      -------------------------------------------
    

    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)
        )
      )
    -------------------------------------
    

    重载监听

    [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
    
    

    配置备库的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)
        )
      )
    -------------------------------------
    

    配置完成后传输给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
    

    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
    

    集群测试:

    [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
    

    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状态
    

    可以登录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
    

    检查归档是否可以正常传输

    #主库操作(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)
    #根据错误提示排查错误
    

    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.
    

    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.
    

    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
    

    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
    

    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
    

    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部分的所有操作
    

    步骤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
    
    #切换成功
    

    至此,单实例通过DG的方式迁移至RAC库的实验已完成
    望各位同僚在生产中操作之前也最好先实验一下。

    展开全文
  • 笔者前文已介绍了ORACLE DG的成员身份与数据保护模式等相关理论知识,从本文开始,将进入ORACLE DG理论与实践相结合模式,深入理解ORACLE DG的内在原理与基本运维技能。本文讲述如何使用rman恢复方式搭建ORACLE DG...

    前言

             笔者前文已介绍了ORACLE DG的成员身份与数据保护模式等相关理论知识,从本文开始,将进入ORACLE DG理论与实践相结合模式,深入理解ORACLE DG的内在原理与基本运维技能。本文讲述如何使用rman恢复方式搭建ORACLE DG物理备库—physical standby。

    部署前规划

             oracle DG要求主备数据库的DB_NAME相同,db_unique_name不同,DG根据db_unique_name区分主备库。根据此要求,规划DG主备如下表所示,

     

    primary db

    standby db

    IP

    99.12.98.194

    55.14.17.100

    hostname

    t24app1sg

    mqserver02n

    db_name

    T24APDB

    T24APDB

    db_unique_name

    T24APDB

    T24APDBDG

    附加说明:

    • 主库

    • 备库

          安装oracle软件后使用dbca创建一个空的oracle实例。数据库名与主库保持相同,建议datafile路径、快速恢复区路径也保持与主库相同,不相同也行,只是后续需要进行文件名转换。

    主库端配置

    开启主库归档模式

    此操作详细步骤从略,以下只列出可能用到的操作SQL语句。

    • 检查数据库归档模式
    SQL> archive log list;
    • 开启归档模式(此操作需要数据库处于mount---12c)
    SQL> alter database archivelog;

    开启db的强制写日志模式

    oracle有些DDL(如create table)支持NOLOGGING子句,即建表时不会产生重做日志,由于物理备库是应用主库的重做日志而来,所以主库必须打开FORCE LOGGING模式。

    • 检查FORCE LOGGING状态
    SQL> select force_logging from v$database;
    FORCE_LOGGING
    ---------------------------------------
    NO
    • 打开force logging
    SQL> ALTER DATABASE FORCE LOGGING;
    • 再次检查force logging模式
    SQL> select force_logging from v$database;

    补充:

    • 关闭force logging模式
    SQL> ALTER DATABASE NO FORCE LOGGING;

    配置监听和tnsname

    正常情况下primary db应该是已经正常配置了监听,无需重复配置,只需查看监听状态,确认能通过监听连接到实例上。

    • 查看监听状态
    $ lsnrctl status
    
    Service "T24APDB " has 1 instance(s).
      Instance "T24APDB", status READY, has 1 handler(s) for this service...

    说明:此服务下有对应的instance,状态为ready,表示动态监听。主库由于一直正常使用,可以是动态监听。

    • 配置tns连接串(tnsnames.ora)

    1. 增加到主库自身的连接串(可用于客户端访问)。

    T24APDB =

      (DESCRIPTION =

        (ADDRESS = (PROTOCOL = TCP)(HOST = 99.12.98.194)(PORT = 1521))

        (CONNECT_DATA =

          (SERVER = DEDICATED)

          (SERVICE_NAME = T24APDB)

        )  

      )

    配置完毕后可使用tnsping进行测试。

    2. 增加主库到备库的TNS连接串

    T24APDBDG =

      (DESCRIPTION =

          (ADDRESS = (PROTOCOL = TCP)(HOST = 55.14.17.100)(PORT = 1521))

              (CONNECT_DATA =

               (SERVER = DEDICATED)

               (SERVICE_NAME = T24APDBDG)

          )  

      )

    此条TNS暂时还不能测试,因为备库还没有配置监听。

    添加data guard参数

    • 从spfile生成pfile(重新生成一个pfile,用于编辑)
    SQL> create pfile='/home/oracle/T24APDB_PR.ora' from spfile;
    • 修改pfile添加DG配置参数(主库vim T24APDB_PR.ora)
    *.db_unique_name='T24APDB '
    
    说明:db_unique_name严格区分大小写
    
    
    *.log_archive_config='dg_config=(T24APDB,T24APDBDG)'
    
    说明:dg_config参数指定的是DG环境中的db_unique_name,所有unique name通过逗号分割;
    
            
    
    *.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name= T24APDB '
    
    说明:valid_for参数的含义是当本数据库处于all_roles即任何角色时到往本地路径log_archive_dest_1下归档all_logfiles(online redo log和standby redo log),若为ASM管理,location环境ASM路径(如+ARCH);
    
    
    *.log_archive_dest_2='service=T24APDBDG reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=T24APDBDG'
    
    说明:valid_for参数的含义是当数据库为primary_role主库角色时往远程路径log_archive_dest_2下归档online_logfiles(online redo log)。其中的service= T24APDBDG,指定归档传输TNS路径;lgwr:指定redo data传输使用的传输方式,lgwr async的组合表示redo data使用lgwr进程采用异步传输的方式同步到db_unique_name 为T24APDBDG 的standby db;
    
    
    *.log_archive_dest_state_1=enable
    
    *.log_archive_dest_state_2=enable
    
    说明:启用归档目的地,该参数对应的值有三个,分别如下:
    
    enable:启用归档目的地
    
    defer:禁用归档目的地
    
    ALTERNATE:作为备用归档目的地
    
    
    *.standby_file_management='auto'
    
    说明:该参数的意思是standby db的文件管理方式是auto,而非manual。设置该参数值为auto主要目的是:主库如果添加、删除表空间或者数据文件时,会自动在备库相应的添加、删除表空间或者数据文件。
    
    
    *.fal_server='T24APDBDG'
    
    说明:指定故障转移的目标端(主库)。即出现故障时往tnsname='T24APDBDG'指定的目标端切。通常不会设置故障转移的自动切换,都是dba按照自己的意愿,往最适合接管  primary db的standby db上去切。
    
    
    *.fal_client='T24APDB
    
    说明:指定发送故障的客户端,即本地db。

    最终新加的pfile配置如下:

    用新pfile重启主库

    SQL> shutdown immediate
    SQL> create spfile from pfile='/home/oracle/T24APDB_PR.ora'
    SQL> startup

    可能的报错:

    ORA-01078: failure in processing system parameters
    ORA-16032: parameter LOG_ARCHIVE_DEST_1 destination string cannot be translated
    ORA-19801: initialization parameter DB_RECOVERY_FILE_DEST is not set

    原因:DB_RECOVERY_FILE_DEST未解析到,导致log_archive_dest_state_1解析失败;

    修改方案:将pfile文件中DB_RECOVERY_FILE_DEST放到LOG_ARCHIVE_DEST_1参数的前面;

    创建standby redo log文件

         添加standby redo log文件的目的是在后续执行rman duplicate时可以直接从主库复制standby redo log,而不用再在standby db端创建standby redo log。直接从主库复制的好处有如下几条:

    1、保证主库和备库有相同的standby redo log,即省了在备库端创建的麻烦又能保证主备库完全相同,这样在switchover时可以直接切换,无需做任何更改;

    2、如果主库有多套dg备库,所有的dg备库的standby redo log是完全相同的,这样管理起来方便。

    创建standby redo log的原则:

    • Each standby redo log file must be at least as large as the largest redo log file in the redo log of the redo source database.

    每个standby 重做日志至少和online重做日志一样大;

    • The standby redo log must have at least one more redo log group than the redo log at the redo source database, for each redo thread at the redo source database.

    standby重做日志数量至少比online重做日志多一个。

    • 查询重做日志
    select group#,type,member from v$logfile;

    • 添加standby redo log
    alter database add standby logfile '/odata/datafile/standby_01.log' size 100m;
    alter database add standby logfile '/odata/datafile/standby_02.log' size 100m;
    alter database add standby logfile '/odata/datafile/standby_03.log' size 100m;
    alter database add standby logfile '/odata/datafile/standby_04.log' size 100m;
    • 再次查询重做日志
    select group#,type,member from v$logfile;

    备库端配置

    确保备库与主库目录相同

    若不相同,后续需要进行转化;此处从略。

    生产备库的密码文件

    由于后面需要通过RMAN主库远程登录备库进行恢复,此处需要配置备库SYS用户的密码。有如下集中方法:

    1. 直接将主库的orapwT24APDB密码文件拷贝到备库;
    2. 使用orapwd命令创建密码文件
    orapwd file='/u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapwT24APDBDG' password=TEST

    • 创建standby的初始化参数

    与主库类似,创建备库的DG参数(vim initT24APDBDG.ora)。如下:

    *.db_name='T24APDB'

    *.db_recovery_file_dest='/data/T24APDBDG'

    *.db_recovery_file_dest_size=48318382080

    *.db_unique_name='T24APDBDG'

    *.dispatchers='(PROTOCOL=TCP) (SERVICE=eppsXDB)'

    *.fal_client='T24APDBDG'

    *.fal_server='T24APDB'

    *.log_archive_config='dg_config=(T24APDB,T24APDBDG)'

    *.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=T24APDBDG'

    *.log_archive_dest_2='SERVICE=T24APDB LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=T24APDB'

    *.log_archive_dest_state_1='ENABLE'

    *.log_archive_dest_state_2='ENABLE'

    用pfile 将standby 启动到nomount状态

    • 把spfile文件重命名
    $ mv spfileT24APDBDG.ora spfileT24APDBDG.ora.bak
    • 用pfile启动数据库到nomount状态
    SQL> startup nomount;

    备库端配置监听

    备库由于处于nomount状态,要想通过SYS用户链接,需要配置静态监听(vim listener.ora)。

    SID_LIST_LISTENER =

      (SID_LIST =

        (SID_DESC =

          (GLOBAL_DBNAME = T24APDBDG)

          (SID_NAME=T24APDBDG)

          (ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1)

          (SERVICE_NAME=T24APDBDG)

        )

      )

    LISTENER =

      (DESCRIPTION=

           (ADDRESS=(PROTOCOL=tcp)(HOST=mqserver02n)(PORT=1521))

      )

    注意上面的配置中,SID为实例名,GLOBAL_DBNAME为unique名,serive_name随便起(与主库配置的tnsname一致)。然后启动监听服务并查看。

    $ lsnrctl start
    $ lsnrctl status
    
    Service "T24APDBDG" has 1 instance(s).
      Instance "T24APDB", status UNKNOWN, has 1 handler(s) for this service...

    如上unknown状态的实例即为静态监听注册的实例。其中还有一个nomount状态注册的动态实例。

    配置tnsname(vim tnsnames.ora)

    T24APDBDG =

      (DESCRIPTION =

         (LOAD_BALANCE = OFF)(FAILOVER=ON)(CONNECT_TIMEOUT=3)(TRANSPORT_CONNECT_TIMEOUT=2)

               (ADDRESS = (PROTOCOL = TCP)(HOST = 55.14.17.100)(PORT = 1521))

        (CONNECT_DATA =

          (SERVER = DEDICATED)

          (SERVICE_NAME = T24APDBDG)

        )

      )

    T24APDB =

      (DESCRIPTION =

         (LOAD_BALANCE = OFF)(FAILOVER=ON)(CONNECT_TIMEOUT=3)(TRANSPORT_CONNECT_TIMEOUT=2)

               (ADDRESS = (PROTOCOL = TCP)(HOST = 99.12.98.194)(PORT = 1521))

        (CONNECT_DATA =

          (SERVER = DEDICATED)

          (SERVICE_NAME = T24APDB)

        )

      )

    测试主库和备库端tnsname配置是否正确

    配置完主备的TNS后即可测试TNS联系连通性,主备都执行如下语句:

    $tnsping T24APDB
    $tnsping T24APDBDG

    使用rman开启duplicate创建备库(主库操作)

    • 在主库上使用rman同时登录主备库,如下:
    $ rman target SYS/SYSTEM@T24APDB auxiliary SYS/SYSTEM@T24APDBDG nocatalog

    • 执行duplicate创建备库

    run {

    allocate auxiliary channel c1 device type disk;

    allocate auxiliary channel c2 device type disk;

     

    duplicate target database for standby nofilenamecheck dorecover;

    release channel c1;

    release channel c2;

    }

    报错1:auxiliary file name /odata/datafile/SYSAUX0422.dbf conflicts with a file used by the target database

    原因:目录不对应,主库这边需要加文件转换

    解决方案:

         1. 将DG备库shutdown并重新startup 称nomount状态;---因为上面的操作中将备库设置成了mount状态;

         2. 主库rman重新登录两个库;

    $ rman target SYS/SYSTEM@T24APDB auxiliary SYS/SYSTEM@T24APDBDG nocatalog

        3. 主库RMAN执行如下duplicate,其中加了文件转换。

    run {

    duplicate target database for standby from active database 

    db_file_name_convert=('/odata/datafile','/data/T24APDBDG');

    }

    最后成功后如下:

    此时备库就获得了主库完全的数据文件拷贝,备库处于mount状态。备库基本搭建完毕。

    备库启动实时重做应用redo apply

    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;

    执行完上述语句后,理论上主库与备库已经实时同步了,可以使用v$managed_standby查看备库的状态:

    SQL> select process,status from v$managed_standby;

    其中,MRP0处于APPLYING_LOG,即代表正常,此时可以查看备库的角色和打开模式。

    SYS@T24APDBDG> select database_role,open_mode from v$database;

     

    DATABASE_ROLE    OPEN_MODE

    ---------------- --------------------

    PHYSICAL STANDBY MOUNTED

    将备库设置为只读状态(可选)

             从ORACLE 11g开始,支持备库应用redo 日志的同时处于redo only状态。这样可以方法进行数据读操作。

    SQL> recover managed standby database cancel

    SQL> alter database open;

    SQL> recover managed standby database using current logfile disconnect;

             说明:以上操作就是先取消日志应用,再打开数据库,最后启用日志应用。查询数据库的打开模式和角色如下图所示--read only with apply。完毕

    总结

             本文step-by-step详细讲述了ORACLE物理备库的部署,除了rman的duplicate操作可能需要稍微注意一下,其他步骤应该不难。整个流程包含诸多知识点,如强制归档、归档模式、standby redo log、静态监听等等。读者在部署过程中要仔细琢磨各个步骤的作用,才能做到少出错或出错后懂得如何着手解决。

    展开全文
  • 1. 目的详细描述如何搭建单节点到单节点的Oracle Data Guard结构,下文简称为DG。2.环境规划环境规划,参考下面的表格。 主库 备库 机器名 dgdb1 dgdb2 IP地址 10.128.20.125 10.128.20.126 操作系统版本 ...

    1. 目的

    详细描述如何搭建单节点到单节点的Oracle Data Guard结构,下文简称为DG。

    2.环境规划

    环境规划,参考下面的表格。

    主库 备库
    机器名 dgdb1 dgdb2
    IP地址 10.128.20.125 10.128.20.126
    操作系统版本 Oracle Linux 6.5 Oracle Linux 6.5
    数据库版本 11.2.0.4 11.2.0.4
    数据库名 dgdb dgdb
    数据库实例名 dgdb1 dgdb2

    3. 搭建环境

    在服务器上安装操作系统。
    根据环境规划设置服务器的主机名和IP地址。
    在两台数据库服务器上面安装oracle软件,并在主机上创建数据库。

    4. 搭建DG

    4.1. 主库的配置

    4.1.1. 启用Forced Logging

    登录主库,执行下面的命令启用Forced Logging。

    SQL> ALTER DATABASE FORCE LOGGING;
    
    数据库已更改。

    4.1.2. 创建standby日志组
    查看现有的日志组

    SQL> select GROUP#,MEMBER from v$logfile;
    
    GROUP# MEMBER
    ------ --------------------------------------------------
         1 /u01/app/oracle/oradata/DGDB/redo01.log
         2 /u01/app/oracle/oradata/DGDB/redo02.log
         3 /u01/app/oracle/oradata/DGDB/redo03.log

    创建standby日志组要比联机日志组多一组。

    SQL> alter database add standby logfile  
    group 4 ('/u01/app/oracle/oradata/DGDB/std_redo04.log') size 50m,
    group 5 ('/u01/app/oracle/oradata/DGDB/std_redo05.log') size 50m,
    group 6 ('/u01/app/oracle/oradata/DGDB/std_redo06.log') size 50m,
    group 7 ('/u01/app/oracle/oradata/DGDB/std_redo07.log') size 50m; 
    
    数据库已更改。

    4.1.3. 启用归档模式

    查看数据库是否为归档模式

    SQL> archive log list
    数据库日志模式             非存档模式
    自动存档             禁用
    存档终点            USE_DB_RECOVERY_FILE_DEST
    最早的联机日志序列     52
    当前日志序列           54

    现在数据库为非归档模式,需要将数据库更改为归档模式
    关闭数据库

    sqlplus / as sysdba
    
    SQL*Plus: Release 11.2.0.4.0 Production on 星期四 109 06:33:01 2014
    
    Copyright (c) 1982, 2013, Oracle.  All rights reserved.
    
    
    连接到: 
    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> shutdown immediate
    数据库已经关闭。
    已经卸载数据库。
    ORACLE 例程已经关闭。

    将数据库启动到mount模式

    SQL> startup mount
    ORACLE 例程已经启动。
    
    Total System Global Area 1653518336 bytes
    Fixed Size          2253784 bytes
    Variable Size        1375734824 bytes
    Database Buffers      268435456 bytes
    Redo Buffers            7094272 bytes
    数据库装载完毕。

    将数据库更改为归档模式

    SQL> alter database archivelog;
    
    数据库已更改。
    SQL> archive log list
    数据库日志模式            存档模式
    自动存档             启用
    存档终点            USE_DB_RECOVERY_FILE_DEST
    最早的联机日志序列     51
    下一个存档日志序列   53
    当前日志序列           53

    4.1.4. 配置oracle net

    使用netca或netmgr创建listener.ora和tnsnames.ora.
    修改listener.ora文件

    # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
    # Generated by Oracle configuration tools.
    
    SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (GLOBAL_DBNAME = DGDB1)
          (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/dbhome_1)
          (SID_NAME = DGDB)
        )
      )
    
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = dgdb1.dhc.com)(PORT = 1521))
        )
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
        )
      )
    
    ADR_BASE_LISTENER = /u01/app/oracle

    修改tnsnames.ora

    DGDB2 =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 10.128.20.126)(PORT = 1521))
        )
        (CONNECT_DATA =
          (SERVICE_NAME = DGDB2)
        )
      )
    
    DGDB1 =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 10.128.20.125)(PORT = 1521))
        )
        (CONNECT_DATA =
          (SERVICE_NAME = DGDB1)
        )
      )

    4.1.5. 配置参数文件。

    创建pfile

    SQL> create pfile from spfile;
    
    文件已创建。

    然后在$ORACLE_HOME/dbs目录中找到文件initDGDB.ora。
    修改initDGDB.ora,加入或者修改以下内容。

    DB_UNIQUE_NAME='DGDB1'
    LOG_ARCHIVE_CONFIG='DG_CONFIG=(DGDB1,DGDB2)'
    LOG_ARCHIVE_DEST_1=
     'LOCATION=/arch
      VALID_FOR=(ALL_LOGFILES,ALL_ROLES) 
      DB_UNIQUE_NAME=DGDB1'
    LOG_ARCHIVE_DEST_2=
     'SERVICE=DGDB2 lgwr ASYNC
      VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) 
      DB_UNIQUE_NAME=DGDB2'
    log_archive_dest_state_1=enable
    log_archive_dest_state_2=enable
    fal_server='DGDB2'
    fal_client='DGDB1'
    standby_file_management=auto

    修改参数文件之后,还要在两个机器上创建/arch目录来保存归档日志。

    [root@dgdb1 ~]# mkdir /arch
    [root@dgdb1 ~]# chown oracle:oinstall /arch/
    [root@dgdb1 ~]# chmod 775 /arch/

    关闭数据库

    [oracle@dgdb1 dbs]$ sqlplus / as sysdba
    
    SQL*Plus: Release 11.2.0.4.0 Production on 星期四 109 06:37:26 2014
    
    Copyright (c) 1982, 2013, Oracle.  All rights reserved.
    
    
    连接到: 
    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> shutdown immediate
    数据库已经关闭。
    已经卸载数据库。
    ORACLE 例程已经关闭。

    创建spfile

    SQL> create spfile from pfile;
    
    文件已创建。

    启动数据库

    SQL> startup
    ORACLE 例程已经启动。
    
    Total System Global Area 1653518336 bytes
    Fixed Size          2253784 bytes
    Variable Size        1375734824 bytes
    Database Buffers      268435456 bytes
    Redo Buffers            7094272 bytes
    数据库装载完毕。
    数据库已经打开。

    4.2. 备库的配置

    4.2.1. 配置oracle net

    在备库上用netca或者netmgr创建listener.ora和tnsnames.ora。
    修改listener.ora

    # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
    # Generated by Oracle configuration tools.
    
    SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (GLOBAL_DBNAME = DGDB2)
          (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/dbhome_1)
          (SID_NAME = DGDB)
        )
      )
    
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = dgdb2.dhc.com)(PORT = 1521))
        )
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
        )
      )
    
    ADR_BASE_LISTENER = /u01/app/oracle

    修改tnsnames.ora

    DGDB2 =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 10.128.20.126)(PORT = 1521))
        )
        (CONNECT_DATA =
          (SERVICE_NAME = DGDB2)
        )
      )
    
    DGDB1 =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = 10.128.20.125)(PORT = 1521))
        )
        (CONNECT_DATA =
          (SERVICE_NAME = DGDB1)
        )
      )

    将主库/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs目录中的pfile和密码文件复制到备库上。

    [oracle@dgdb1 dbs]$ scp initDGDB.ora orapwDGDB 10.128.20.126:/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/
    The authenticity of host '10.128.20.126 (10.128.20.126)' can't be established.
    RSA key fingerprint is 0c:74:49:a9:2c:dd:ff:af:c9:1f:cb:6b:a6:44:4d:3b.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '10.128.20.126' (RSA) to the list of known hosts.
    oracle@10.128.20.126's password: 
    initDGDB.ora                                 100% 1386     1.4KB/s   00:00    
    orapwDGDB                                    100% 1536     1.5KB/s   00:00

    4.2.2. 配置参数文件

    修改pfile

    DB_UNIQUE_NAME='DGDB2'
    LOG_ARCHIVE_CONFIG='DG_CONFIG=(DGDB1,DGDB2)'
    LOG_ARCHIVE_DEST_1=
     'LOCATION=/arch
      VALID_FOR=(ALL_LOGFILES,ALL_ROLES) 
      DB_UNIQUE_NAME=DGDB2'
    LOG_ARCHIVE_DEST_2=
     'SERVICE=DGDB1 lgwr ASYNC
      VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) 
      DB_UNIQUE_NAME=DGDB1'
    log_archive_dest_state_1=enable
    log_archive_dest_state_2=enable
    fal_server='DGDB1'
    fal_client='DGDB2'
    standby_file_management=auto

    在备库上创建spfile

    [oracle@dgdb2 admin]$ sqlplus / as sysdba
    
    SQL*Plus: Release 11.2.0.4.0 Production on 星期四 109 06:56:55 2014
    
    Copyright (c) 1982, 2013, Oracle.  All rights reserved.
    
    已连接到空闲例程。
    
    SQL> create spfile from pfile;
    
    文件已创建。

    在备库上创建必需的目录

    mkdir /u01/app/oracle/fast_recovery_area
    mkdir -p /u01/app/oracle/admin/DGDB/adump

    启动备库到nomount

    SQL> startup nomount
    ORACLE 例程已经启动。
    
    Total System Global Area 1653518336 bytes
    Fixed Size          2253784 bytes
    Variable Size        1375734824 bytes
    Database Buffers      268435456 bytes
    Redo Buffers            7094272 bytes

    4.3. 使用RMAN生成物理备库

    使用下面的命令,登录rman

    rman target sys/oracle@DGDB1 auxiliary sys/oracle@DGDB2 nocatalog
    
    恢复管理器: Release 11.2.0.4.0 - Production on 星期四 109 07:44:07 2014
    
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    
    已连接到目标数据库: DGDB (DBID=2206457594)
    使用目标数据库控制文件替代恢复目录
    已连接到辅助数据库: DGDB (未装载)

    使用下面的命令,生成物理备库

    RMAN> duplicate target database for standby nofilenamecheck from active database;

    生成的备库没有redo和standby日志文件,需要把主库的文件复制过去。

    [oracle@dgdb1 DGDB]$ scp *.log 10.128.20.126:/u01/app/oracle/oradata/DGDB/oracle@10.128.20.126's password: 
    redo01.log                                   100%   50MB  50.0MB/s   00:01    
    redo02.log                                   100%   50MB  25.0MB/s   00:02    
    redo03.log                                   100%   50MB  50.0MB/s   00:01    
    std_redo04.log                               100%   50MB  50.0MB/s   00:01    
    std_redo05.log                               100%   50MB  50.0MB/s   00:01    
    std_redo06.log                               100%   50MB  50.0MB/s   00:01    
    std_redo07.log                               100%   50MB  50.0MB/s   00:01

    重启一下备库

    [oracle@dgdb2 DGDB]$ sqlplus / as sysdba
    
    SQL*Plus: Release 11.2.0.4.0 Production on 星期四 109 07:45:23 2014
    
    Copyright (c) 1982, 2013, Oracle.  All rights reserved.
    
    
    连接到: 
    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> archive log list
    数据库日志模式            存档模式
    自动存档             启用
    存档终点            /arch
    最早的联机日志序列     0
    下一个存档日志序列   0
    当前日志序列           0
    SQL> shutdown immediate
    ORA-01109: 数据库未打开
    
    
    已经卸载数据库。
    ORACLE 例程已经关闭。

    启动备库到mount

    SQL> startup mount
    ORACLE 例程已经启动。
    
    Total System Global Area 1653518336 bytes
    Fixed Size          2253784 bytes
    Variable Size        1375734824 bytes
    Database Buffers      268435456 bytes
    Redo Buffers            7094272 bytes
    数据库装载完毕。

    将备库切换到standby

    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
    
    数据库已更改。

    4.4. 验证DG是否搭建成功

    在备库上验证存在的归档日志。

    SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
    SEQUENCE# FIRST_TIME      NEXT_TIME
    ---------- -------------- --------------
           101 12-10月-14     13-10月-14
           102 13-10月-14     13-10月-14
           103 13-10月-14     14-10月-14
           104 14-10月-14     14-10月-14
           105 14-10月-14     15-10月-14
           106 15-10月-14     15-10月-14
           107 15-10月-14     15-10月-14
           108 15-10月-14     16-10月-14
           109 16-10月-14     16-10月-14

    在主库切换下日志

    SQL> alter system switch logfile;
    
    系统已更改。
    
    SQL> archive log list
    数据库日志模式            存档模式
    自动存档             启用
    存档终点            /arch
    最早的联机日志序列     109
    下一个存档日志序列   111
    当前日志序列           111

    在备库下看归档的状态

    SQL> archive log list
    数据库日志模式            存档模式
    自动存档             启用
    存档终点            /arch
    最早的联机日志序列     109
    下一个存档日志序列   0
    当前日志序列           111

    查看主库传过来的归档是否被应用

    SQL> SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
    SEQUENCE# APPLIED
    ---------- ---------
           101 YES
           102 YES
           103 YES
           104 YES
           105 YES
           106 YES
           107 YES
           108 YES
           109 YES
           110 IN-MEMORY

    到此DG的搭建已经完成。

    展开全文
  • Oracle 11g 透明网关

    万次阅读 2015-04-24 20:41:25
    Oracle11g通过透明网关访问SQLServer2008数据
  • Oracle之ADG与DG的区别?

    千次阅读 2019-07-20 20:07:05
    在上云后的Oracle数据灾备场景中,我们经常听到DBA迁移工程师讲到“在这个项目中用ADG进行数据实时备份,ADG比DG更好!”。究竟ADG作Oracle数据灾备的优势在什么地方? 一、ADG主要解决了DG时代读写不能并行的...
  • oracle创建dblink访问Sqlserver数据库

    千次阅读 2018-08-08 16:15:58
    需求:通过在oracle创建dblink的方式直接访问Sqlserver数据库 操作方式:利用Oracle组件,透明网关(Transparent Gateway),建立dblink ,访问SQL SERVER 1.首先在官网上先下载个透明网关。网址(11g): htt...
  • Oracle GateWay 工具连接SQLServer

    万次阅读 2018-12-11 16:28:28
    环境说明 ...Gateway安装机器地址为 10.238.98.190,已安装了Oracle11g Server 产品 GateWay 安装 下载好Oracle Gateway(版本为11.2)的安装包后,点击安装,首先出现以下界面   稍等片刻...
  • oracle DG 启动和关闭顺序

    千次阅读 2018-02-26 17:35:16
    启动顺序:先启动备库,后启动主库关闭顺序:先关闭主库,后关闭备库1、正确打开备库和主库备库:SQL> STARTUP MOUNT;SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;...
  • 配置Oracle Gateway 12连接到SQL server 2014

    千次阅读 2016-01-18 16:12:51
    最近的工作中需要基于Oracle连接到SQLserver2014,我们可以通过配置Gateway的方式来实现这个功能。这个Gateway的实质是透过dblink来实现的。即把SQLserver模拟成一个远端的Oracle实例,这个实例由Gateway来负责进行...
  • ORACLE DG概念及切换

    万次阅读 2019-01-15 16:02:46
    DG的原理: DG分为物理standy,逻辑standy 物理standy: 物理STANDBY提供与主数据库完全一样的拷贝(块到块),数据库SCHEMA,包括索引都是一样的。它是直接应用REDO实现同步的。 逻辑standy: 逻辑STANDBY则不是...
  • Oracle通过dblink直接访问Sqlserver

    千次阅读 2017-03-21 16:32:02
    需求:通过在oracle创建dblink的方式直接访问Sqlserver数据库 操作方式:利用Oracle组件,透明网关(Transparent Gateway),建立dblink ,访问SQL SERVER 1.首先在官网上先下载个透明网关。网址(11g): ...
  • 1 背景说明 正常情况下,我们在安装Oracle数据库的时候,都会创建一个oracle的用户。 其根目录就是/home/oracle.  并且根据Oracle 的OFA的架构,也是建议使用/u01 这样的目录来单独安装oracle的软件,包括存放数据...
  • oracle RAC如何正确地删除ASM磁盘组

    千次阅读 2018-01-20 18:00:04
    1.检查确认要删除的磁盘组是否在用 select * from dba_data_files; select * from dba_temp_files; select * from v$logfile; ...2.先在各节点上dismount磁盘组 ...alter diskgroup REDO01 dismount;...
  • ORACLE连接MYSQL-使用DG4ODBC.

    千次阅读 2014-05-23 10:48:37
    最近做了一次Oracle连接到MySQL的实验,主要是通过DG4ODBC来连接的.以下是实验环境和实验步骤. Oracle服务器: IP:192.168.0.193 Database Version:11.2.0.1 MySQL服务器 IP:192.168.0.100 MySQL Version:5.5.18...
  • oracle 11g建立DBLink访问sql server数据库

    万次阅读 2016-09-09 11:43:34
    1.安装oracle数据库(步骤省略)  (IP:172.29.29.36)安装路径:E:\oracle\product\11.2.0\dbhome_1 2.安装oracle gateways透明网关(安装步骤省略)  (IP:172.29.29.36)安装路径:E:\oracle\product\11.2.0\...
  • [Oracle, MySQL] Oracle通过dblink连接MySQL

    万次阅读 2013-08-29 12:05:48
    业务上有这么一个需求,需要把Oracle的一些数据同步到MySQL,如果每次都是手动同步的话,实在太麻烦,因此花了点时间研究了下Oracle直连MySQL的方式。 参考文档:Detailed Overview of Connecting Oracle to MySQL ...
  • Oracle DG环境如何正确地删除Archivelog

    万次阅读 2016-07-31 16:07:05
    清理归档日志最稳妥的原则: 主备库清理归档,都要配置。RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON STANDBY;  主库才用备份归档并清理。 备库应该是直接清理! Archivelog并不能直接得从OS层...
  • oracle dg打开备库为读写数据库,慎重!

    千次阅读 2014-08-01 20:05:14
    --确保standby数据库置于flashback on 状态 --设置闪回恢复区 alter system set db_recovery_dest_size=2g; ...alter system set db_recovery_file_dest='+DATA';...alter database recover managed standby d
  • DataGuard之DG Broker配置详解

    万次阅读 2017-02-17 09:57:01
    oracle dg datagurad failover swithover broker fsfo
1 2 3 4 5 ... 20
收藏数 17,039
精华内容 6,815
关键字:

dg 如何连接oracle