dg oracle rac_oracle rac和 dg有啥区别? - CSDN
精华内容
参与话题
  • ORACLE RAC+DG(单实例)

    万次阅读 2019-07-02 14:55:43
    ORACLE RAC+DG(单实例) 前提条件: 1.主库RAC已经成功安装,数据库也已经创建。 2.DG备库已经安装完相同版本的oracle软件,无需创建数据库。 1、RAC开启归档。 任意节点: alter system set log_archive_format='%t_%s...

    ORACLE RAC+DG(单实例)
    前提条件:
    1.主库RAC已经成功安装,数据库也已经创建。
    2.DG备库已经安装完相同版本的oracle软件,无需创建数据库。

    1、RAC开启归档。
    任意节点:

    alter system set log_archive_format='%t_%s_%r.arc' scope=spfile sid='*';
    alter system set log_archive_dest_1='LOCATION=+DATA/arch' scope=spfile sid='*';
    srvctl stop database -d racdb -o immediate
    startup mount
    alter database archivelog;
    alter database open;
    srvctl start database -d racdb
    

    查看每个节点的归档

    alter system switch logfile;
    archive log list;
    

    每个节点的归档序号是不一样的。

    2、启用force logging功能

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

    3、查询主库日志文件

    select thread#,group#,members,bytes/1024/1024 from v$log;
    alter database add standby logfile thread 1 group 11 size 50m;
    alter database add standby logfile thread 1 group 12 size 50m;
    alter database add standby logfile thread 1 group 13 size 50m;
    alter database add standby logfile thread 2 group 14 size 50m;
    alter database add standby logfile thread 2 group 15 size 50m;
    alter database add standby logfile thread 2 group 16 size 50m;
    

    3、配置主库的初始化参数

    alter system set db_unique_name='racdb' scope=spfile;
    alter system set log_archive_config='DG_CONFIG=(racdb,racdg)' scope=both sid='*';
    alter system set log_archive_dest_1='LOCATION=+data/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=racdb' scope=both sid='*';
    alter system set log_archive_dest_2='SERVICE=racdg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=racdg' scope=both sid='*';
    alter system set log_archive_format='%t_%s_%r.arc' scope=spfile sid='*';
    alter system set log_archive_max_processes=8 scope=both sid='*';
    alter system set db_file_name_convert='/oradata/racdg/','+DATA/racdb/datafile' scope=spfile sid='*';
    alter system set log_file_name_convert='/oradata/racdg/','+DATA/racdb/onlinelog' scope=spfile sid='*';
    alter system set standby_file_management=AUTO scope=both sid='*';
    alter system set fal_server='rac_dg' scope=both sid='*';
    

    4、查询是否生效:

    set linesize 500 pages 0
    col value for a90
    col name for a50
    select name, value from v$parameter where name in ('db_name','db_unique_name','log_archive_config', 'log_archive_dest_1','log_archive_dest_2','log_archive_dest_state_1','log_archive_dest_state_2','remote_login_passwordfile','log_archive_format','log_archive_max_processes','fal_server','db_file_name_convert', 'log_file_name_convert', 'standby_file_management')
    

    5、配置本地服务名(两个节点保持一致)

    cd $ORACLE_HOME/network/admin
    vim tnsnames.ora
    
    RACDB =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = racdb)
        )
      )
    
    RACDB1 =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.203)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = racdb)
        )
      )
    
    RACDB2 =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.204)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = racdb)
        )
      )
    
    
    RACDG =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.206)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = racdg)
        )
      )
    

    6、复制密码到DG节点
    使用oracle用户

    cd $ORACLE_HOME/dbs
    scp orapwracdb1 192.168.100.206:/$ORACLE_HOME/dbs/orapwracdg
    

    7、创建初始化文件。
    登录dg节点,使用oracle用户

    cd $ORACLE_HOME/dbs
    vim initracdg.ora
    如下:
    *.audit_file_dest='/u01/app/oracle/admin/racdg/adump'
    *.audit_trail='db'
    *.compatible='11.2.0.4.0'
    *.control_files='/oradata/racdg/control01.ctl'
    *.db_block_size=8192
    *.db_create_file_dest='/oradata/racdg'
    *.db_domain=''
    *.db_name='racdb'
    *.db_unique_name='racdg'
    *.diagnostic_dest='/u01/app/oracle'
    *.dispatchers='(PROTOCOL=TCP) (SERVICE=racdgXDB)'
    *.fal_client='racdg'
    *.fal_server='racdb'
    *.log_archive_config='DG_CONFIG=(racdb,racdg)'
    *.log_archive_dest_1='LOCATION=/oradata/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=racdg'
    #*.log_archive_dest_2='SERVICE=racdb LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=racdb OPTIONAL PROPEN=15 MAX_FAILU
    RE=10 NET_TIMEOUT=30'
    *.log_archive_dest_2='SERVICE=racdb LGWR ASYNC VALID_FOR=(ALL_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=racdb'
    *.log_archive_dest_state_2='enable'
    *.log_file_name_convert='+DATA/racdb/onlinelog','/oradata/racdg'
    *.db_file_name_convert='+DATA/racdb/datafile','/oradata/racdg'
    *.log_archive_format='%t_%s_%r.dbf'
    *.log_archive_max_processes=8
    *.open_cursors=300
    *.pga_aggregate_target=536870912
    *.processes=150
    *.remote_login_passwordfile='exclusive'
    *.standby_file_management='AUTO'
    *.sga_target=2147483648
    *.undo_tablespace='UNDOTBS1'
    

    8、主库做备份。

    rman targer /
    

    执行:

    backup database format '/oradata/backup/racdb_%T_%s';
    cd /oradata/backup/
    scp racdb* 192.168.200.206:/oradata/backup/
    

    9、创建目录

    mkdir -p /u01/app/oracle/admin/racdg/adump
    mkdir -p /oradata/racdg/
    mkdir -p /oradata/arch/
    

    10、创建LISTENER

    LISTENER =
       (DESCRIPTION_LIST =
         (DESCRIPTION =
           (ADDRESS = (PROTOCOL = TCP)(HOST = racdg)(PORT = 1521)))
              (DESCRIPTION =
           (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
         )
        )
       ADR_BASE_LISTENER = /u01/app/oracle 
    

    11、启动mount

    startup mount;
    rman恢复数据库
    rman target /
    catalog start with '/oradata/backup';
    run {
    allocate channel ch00 type disk;
    allocate channel ch01 type disk;
    allocate channel ch02 type disk;
    allocate channel ch03 type disk;
    set newname for datafile 1 to '/oradata/racdg/system.dbf';
    set newname for datafile 2 to '/oradata/racdg/sysaux.dbf';
    set newname for datafile 3 to '/oradata/racdg/undotbs1.dbf';
    set newname for datafile 4 to '/oradata/racdg/users.dbf';
    set newname for datafile 5 to '/oradata/racdg/undotbs2.dbf';
    set newname for datafile 6 to '/oradata/racdg/test.dbf';
    set newname for datafile 7 to '/oradata/racdg/test01.dbf';
    restore database;
    switch datafile all;
    release channel ch00;
    release channel ch01;
    release channel ch02;
    release channel ch03;
     }
    

    12、standby开启实时同步

    alter database recover managed standby database using current logfile disconnect from session;
    停止同步:
    alter database recover managed standby database cancel;
    

    13、 主库查询进程状态(注意LNS进程)

    select process, client_process, sequence#,thread#,status from v$managed_standby;
    ![如下图](https://img-blog.csdnimg.cn/20190702144431875.jpg)
    

    14、备库查询进程状态(注意RFS进程和MRP0进程)

    select process, client_process, sequence#,thread#,status from v$managed_standby;
    ![如下图](https://img-blog.csdnimg.cn/20190702144626345.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjIzOTE4Nw==,size_16,color_FFFFFF,t_70)
    

    15、查询日志

    select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;
    

    16、主库手动切换日志

    alter system switch logfile;
    

    17、查询日志

    select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;
    

    18、打开datagaurd模式

     alter database recover managed standby database cancel;
     alter database open read only;
     alter database recover managed standby database using current logfile disconnect from session;
    

    19、查看数据库模式

        主库:
        SQL>  select open_mode,database_role,switchover_status from v$database;
        
        OPEN_MODE	     DATABASE_ROLE    SWITCHOVER_STATUS
        -------------------- ---------------- --------------------
        READ WRITE	     PRIMARY	      SESSIONS ACTIVE
        备库:
        SQL> select open_mode,database_role,switchover_status from v$database;
        
        OPEN_MODE	     DATABASE_ROLE    SWITCHOVER_STATUS
        -------------------- ---------------- --------------------
        READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED
    
    展开全文
  • Oracle 11g RAC+DG 非常牛逼的部署手册
  • 实验: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 11g RAC+DG项目实战(共15集)视频

    千次阅读 2019-09-04 10:25:23
    下载地址: ...在15集视频中详细阐述了Oracle RAC的安装,RAC如何配置Active Data Guard,DG如何切换!绝对重量级的视频。掌握这个技术,资深Oracle DBA的岗位你也轻松秒杀! 实验手册在最后一集视频...
    本人购买的视频,原文地址:
    http://www.boobooke.com/goods-78.html
    
    ****下载地址:**
    https://download.csdn.net/download/a934343824/11663610
    

    文件内容:
    在这里插入图片描述



    这是黄伟老师精心制作的Oracle最高端的技术实战!在15集视频中详细阐述了Oracle RAC的安装,RAC如何配置Active Data Guard,DG如何切换!绝对重量级的视频。掌握这个技术,资深Oracle DBA的岗位你也轻松秒杀!

    实验手册在最后一集视频中!

    概述:
    本系列视频是Oracle 11gR2 RAC+单实例Active Dataguard备库,属Oracle数据库技术中的高端应用场景,
     视频背景取自于之前给某电商客户实施的一套高可用+容灾方案。
    

    视频内容:

    本系列视频一共15讲。
    第1讲:搭建物理环境之:创建3台服务器,其中2个用作RAC节点,第3个用户Ddataguard物理机器。

    第2讲:RAC第一个节点准备工作之:配置网络、DNS服务器、建用户、配置系统内核等。

    第3讲:节点2准备工作之配置网络,建用户、配置系统内核等。RAC双节点停止NTP服务,配置grid、oracle用户对等性。

    第4讲:RAC双节点格式化共享存储,配置ASM磁盘,配置ASM。

    第5讲:准备安装介质,安装前预检查,RAC双节点安装Grid Infrastructure软件。

    第6讲:RAC双节点安装oracle软件,创建ASM磁盘组,创建RAC数据库。

    第7讲:测试RAC数据库的主要功能,以及管理和维护RAC。

    第8讲:物理备库机器安装GRID软件并且配置ASM磁盘组,以及安装oracle软件。

    第9讲:创建物理备库的准备工作之:主库置为归档、FORCE LOGGING、RMAN备份RAC主库,创建备库的控制文件,创建备库的初始化参数文件等。

    第10讲:创建物理备库的准备工作之:在物理备库上创建口令文件,初始化参数文件,tnsnames.ora文件。

    第11讲:给RAC主库配置ACTIVE PHYSICAL Dataguard之:NOMOUNT备库,恢复备库控制文件,MOUNT备库,RESTORE备库,备库创建STANDBY LOGFILE。

    第12讲:给RAC主库配置ACTIVE PHYSICAL Dataguard之:主库参数调整,日志传递到备库,备库接受日志,同主库同步,READ ONLY打开备库。

    第13讲:测试物理备库,ACTIVE Dataguard的功能,即物理备库既可以同RAC主库同步,也可以对外提供READ ONLY。

    第14讲:讲解RAC主库同物理备库的SWITCHOVER角色切换功能,即将RAC切换为备库,单实例库切换为主库。

    第15讲:讲解如何将RAC数据库(现为备库)切换成主库,单实例库(现为主库)切换成物理备库,即将整个环境切换到之前的状态,并且确保切换成功,数据不丢失!

    展开全文
  • Oracle 11g RAC 到 单实例 DG 环境搭建

    千次阅读 2019-05-22 09:20:25
    Primary Database 是一个两节点的RAC,存储采用ASM 方式,具体如下图: RAC Primary rac1 rac2 Public IP 192.168.1.60/24 192.168.1.62/24 Private IP 192.168.56.80/24 192.168.56.82/24 ...

    1 环境说明

    Primary Database 是一个两节点的RAC,存储采用ASM 方式,具体如下图:

     

    RAC Primary  rac1 rac2
    Public IP 192.168.1.60/24 192.168.1.62/24
    Private IP 192.168.56.80/24 192.168.56.82/24
    Vritual IP 192.168.1.61/24 192.168.1.63/24
     San IP                                         192.168.1.125 
     Instance  leo1  leo2
     DB_NAME                                               leo 
     Data、Control File、Redo File                                              ASM 

     

    Standby Database (Single Instance) 环境介绍

     

     

    Single instance Standby                            说明
    IP 192.168.1.65/24
    Oracle 单实例
    Instance orcl
    DB_NAME leo
     Data  /u01/app/oracle/oradata/orcl/data tempfile
     Control File  /u01/app/oracle/oradata/orcl/control01.ctl
     /u01/app/oracle/fast_recovery_area/orcl
     Redo FileRedo File  /u01/app/oracle/oradata/orcl/redo

     

     

    2  主库设置为 force logging 模式

    rac 节点1 执行
    
    SQL> alter database force logging;
    
    Database altered.
    
    SQL> select force_logging from v$database; 
    
    FOR
    ---
    YES

    3 修改主库为归档模式 

    SQL>  archive log list
    Database log mode	       No Archive Mode
    Automatic archival	       Disabled
    Archive destination	       USE_DB_RECOVERY_FILE_DEST
    Oldest online log sequence     30
    Current log sequence	       31
    
    
    切换归档,将所有节点都必须处于 mount 状态。 在其中一个节点修改模式,然后在其他节点正常启动即可。
    
    SQL> shutdown immediate
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
    
    SQL> startup mount
    ORACLE instance started.
    
    Total System Global Area 1269366784 bytes
    Fixed Size		    2252864 bytes
    Variable Size		  872419264 bytes
    Database Buffers	  385875968 bytes
    Redo Buffers		    8818688 bytes
    Database mounted.
    
    SQL> alter database archivelog;
    
    Database altered.
    
    SQL> archive log list;
    Database log mode	       Archive Mode
    Automatic archival	       Enabled
    Archive destination	       USE_DB_RECOVERY_FILE_DEST
    Oldest online log sequence     30
    Next log sequence to archive   31
    Current log sequence	       31
    
    SQL> select name , open_mode, log_mode,force_logging from gv$database;
    
    NAME	  OPEN_MODE	       LOG_MODE     FOR
    --------- -------------------- ------------ ---
    LEO	  READ WRITE	       ARCHIVELOG   YES
    LEO	  READ WRITE	       ARCHIVELOG   YES
    
    SQL>  show parameter db_recover 
    
    NAME				     TYPE	 VALUE
    ------------------------------------ ----------- ------------------------------
    db_recovery_file_dest		     string	 +DATA
    db_recovery_file_dest_size	     big integer 4407M
    
    
    我 2 个节点的归档都指向了+DATA 这个磁盘组。 也可以指向其他的磁盘组或者本地的位置,如: 
    SQL> alter system set log_archive_dest_1='location=/u01/leo1arch' sid='leo1'; 
    SQL> alter system set log_archive_dest_1='location=/u01/leo2arch' sid='leo2';

    4  主备库添加 standby Redo log 文件 

    RAC 每个 Redo Thread 都需要创建对应的 Standby Redo Log。 创建原则和单实例一样,包括日志 文件大小相等,日志组数量要多 1 组。
    主库
    SQL> set lines 120
    SQL> col member for a50
    SQL> select a.thread#,a.group#,a.bytes/1024/1024,b.member from v$log a,v$logfile b where a.group#=b.group#;
    
       THREAD#     GROUP# A.BYTES/1024/1024 MEMBER
    ---------- ---------- ----------------- --------------------------------------------------
    	 1	    2		     50 +DATA/leo/onlinelog/group_2.277.943664411
    	 1	    2		     50 +DATA/leo/onlinelog/group_2.278.943664413
    	 1	    1		     50 +DATA/leo/onlinelog/group_1.275.943664407
    	 1	    1		     50 +DATA/leo/onlinelog/group_1.276.943664409
    	 2	    3		     50 +DATA/leo/onlinelog/group_3.281.943668673
    	 2	    3		     50 +DATA/leo/onlinelog/group_3.282.943668675
    	 2	    4		     50 +DATA/leo/onlinelog/group_4.283.943668677
    	 2	    4		     50 +DATA/leo/onlinelog/group_4.284.943668679
    
    8 rows selected.
    --主库添加 standby redo log: 
    SQL> alter database add standby logfile thread 1 group 10 ('+DATA') size 50m; 
    
    Database altered.
    
    SQL> alter database add standby logfile thread 1 group 11 ('+DATA') size 50m; 
    
    Database altered.
    
    SQL> alter database add standby logfile thread 1 group 12 ('+DATA') size 50m; 
    
    Database altered.
    
    SQL> alter database add standby logfile thread 1 group 13 ('+DATA') size 50m; 
    
    Database altered.
    
    SQL> alter database add standby logfile thread 1 group 14 ('+DATA') size 50m; 
    
    Database altered.
    
    
    SQL> alter database add standby logfile thread 2 group 15 ('+DATA') size 50m; 
    
    Database altered.
    
    SQL> alter database add standby logfile thread 2 group 16 ('+DATA') size 50m;
    
    Database altered.
    
    SQL> alter database add standby logfile thread 2 group 17 ('+DATA') size 50m; 
    
    Database altered.
    
    SQL> alter database add standby logfile thread 2 group 18 ('+DATA') size 50m; 
    
    Database altered.
    
    SQL> alter database add standby logfile thread 2 group 19 ('+DATA') size 50m; 
    
    Database altered.
    
    
    
    --验证: 
    SQL> select group#,type,member from v$logfile order by 2;
    
        GROUP# TYPE    MEMBER
    ---------- ------- --------------------------------------------------
    	 2 ONLINE  +DATA/leo/onlinelog/group_2.277.943664411
    	 4 ONLINE  +DATA/leo/onlinelog/group_4.284.943668679
    	 4 ONLINE  +DATA/leo/onlinelog/group_4.283.943668677
    	 3 ONLINE  +DATA/leo/onlinelog/group_3.282.943668675
    	 3 ONLINE  +DATA/leo/onlinelog/group_3.281.943668673
    	 1 ONLINE  +DATA/leo/onlinelog/group_1.276.943664409
    	 1 ONLINE  +DATA/leo/onlinelog/group_1.275.943664407
    	 2 ONLINE  +DATA/leo/onlinelog/group_2.278.943664413
    	18 STANDBY +DATA/leo/onlinelog/group_18.330.945089519
    	17 STANDBY +DATA/leo/onlinelog/group_17.329.945089515
    	16 STANDBY +DATA/leo/onlinelog/group_16.328.945089509
    
        GROUP# TYPE    MEMBER
    ---------- ------- --------------------------------------------------
    	15 STANDBY +DATA/leo/onlinelog/group_15.327.945089505
    	14 STANDBY +DATA/leo/onlinelog/group_14.294.944422059
    	13 STANDBY +DATA/leo/onlinelog/group_13.293.944422047
    	12 STANDBY +DATA/leo/onlinelog/group_12.292.944422039
    	11 STANDBY +DATA/leo/onlinelog/group_11.291.944422031
    	19 STANDBY +DATA/leo/onlinelog/group_19.331.945089523
    	10 STANDBY +DATA/leo/onlinelog/group_10.290.944422017
    
    18 rows selected.

    5 配置主备库的监听:listener.ora 
    用 net manager 工具,在备库创建一个监听。 也可以手动的修改 listener.ora 文件。 
    --对于 RAC 环境: 

    在 grid 用户的 listener.ora 文件中加入如下内容:  
    [grid@rac1 admin]$ cat listener.ora
    # listener.ora Network Configuration File: /u01/app/11.2.0/grid/network/admin/listener.ora
    # Generated by Oracle configuration tools.
    
    ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1 = ON
    
    SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (GLOBAL_DBNAME = leo)
          (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
          (SID_NAME = leo1)
        )
      )
    
    LISTENER =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER))
      )
    
    ADR_BASE_LISTENER = /u01/app/grid
    
    ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER = ON
    
    LISTENER_SCAN1 =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER_SCAN1))
      )
    
    ADR_BASE_LISTENER_SCAN1 = /u01/app/grid
    
     节点 2,对应修改即可。
     [grid@rac2 admin]$ cat listener.ora
    # listener.ora Network Configuration File: /u01/app/11.2.0/grid/network/admin/listener.ora
    # Generated by Oracle configuration tools.
    
    ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1 = ON
    
    SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (GLOBAL_DBNAME = leo)
          (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
          (SID_NAME = leo2)
        )
      )
    
    LISTENER =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER))
      )
    
    ADR_BASE_LISTENER = /u01/app/grid
    
    ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER = ON
    
    LISTENER_SCAN1 =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER_SCAN1))
      )
    
    ADR_BASE_LISTENER_SCAN1 = /u01/app/grid
    
    
    --这里写的 Oracle 用户的 ORACLE_HOME,否则连接时会报错:
    ORA-01031: insufficient privileges 
     
    然后重启监听。  
     
    注意在 oracle 11gR2 的 RAC 环境下,监听是在 grid 用户下配置的。所以这里可以用 grid 用户连接,
    并修 改。 最后重启监听。 
     
    对于单实例,直接在 listener.ora 里添加: 
    
    [oracle@localhost admin]$ cat listener.ora 
    # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
    # Generated by Oracle configuration tools.
    
    SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (GLOBAL_DBNAME = orcl)
          (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
          (SID_NAME = orcl)
        )
      )
    
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
        )
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
        )
      )
    
    ADR_BASE_LISTENER = /u01/app/oracle

    6 配置主备库的 Net Server: tnsnames.ora 

    节点1,节点2,单实例 的 tnsnames.ora 文件是一致的,添加以下内容: 

    leo=
     (DESCRIPTION =
       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.61)(PORT = 1521))
       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.63)(PORT = 1521))
       (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME =leo)
        )
      )
    
    orcl_st=
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.65)(PORT = 1521))  
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = orcl)
        )
      )
    
    配置完成后,使用 tnsping 命令效验:
      
    [oracle@rac1 admin]$ tnsping orcl_st
    
    TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 29-MAY-2017 01:59:09
    
    Copyright (c) 1997, 2013, Oracle.  All rights reserved.
    
    Used parameter files:
    
    
    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.65)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
    OK (0 msec)
    
    [oracle@localhost dbs]$ tnsping leo
    
    TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 29-MAY-2017 01:59:38
    
    Copyright (c) 1997, 2013, Oracle.  All rights reserved.
    
    Used parameter files:
    
    
    Used TNSNAMES adapter to resolve the alias
    Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.61)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.63)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME =leo)))
    OK (0 msec)

    7 单实例创建相关目录 

    --FRA目录
    [oracle@rac2 ~]$ mkdir -p /u01/app/oracle/fast_recovery_area/orcl
    --DATAFILE
    [oracle@rac2 ~]$ mkdir -p /u01/app/oracle/oradata/orcl
    [oracle@rac2 ~]$ mkdir -p /u01/app/oracle/admin/orcl/adump
    [oracle@rac2 ~]$ mkdir -p /u01/app/oracle/admin/orcl/data
    [oracle@rac2 ~]$ mkdir -p /u01/app/oracle/admin/orcl/redo
    [oracle@rac2 ~]$ mkdir -p /u01/app/oracle/admin/orcl/tempfile

    8 创建备库口令文件 

    [oracle@localhost dbs]$ pwd
    /u01/app/oracle/product/11.2.0/db_1/dbs
    [oracle@localhost dbs]$ orapwd file=$ORACLE_HOME/dbs/orapwleo1 password=oracle
    [oracle@localhost dbs]$ orapwd file=$ORACLE_HOME/dbs/orapwleo2 password=oracle
    [oracle@localhost dbs]$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=oracle
    
    或者把节点的口令文件copy 到备库(在哪个节点执行操作就在把那个节点的口令文件copy过去)
    [oracle@rac1 dbs]$ scp orapwleo1 192.168.1.65:/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl 

    9 创建修改主备库的参数文件 

    --主库参数
    
    db_file_name_convert 和 log_file_name_convert 仅当数据库被 standby 时才会生效,
    这里配置,是 为切换做准备。 log_file_name_convert 指的是 online redo log。  
    在 Oracle 11g 已经废除了 fal_client 参数。   
    RAC 的 spfile 是放在共享设备上的,所以如果想创建,就需要先创建一份 pfile 到本地,在修改,
    如果不想这么折腾,就直接使用 SQL 语句修改:
    1)使用 ASM 作为存储时,datafile 和 tempfile 是分别放在两个目录下的,所以在Standby 
    上也单独创建一个tempdata 目录。并在db_file_name_convert 中作相应的设置。
    2)在使用ASM 的RAC中,注意不要改变db_unique_name 的参数值;因为ASM 存放文件的规则,是按照
    +diskgroup_name/data_unique_name/file/tag_name.file_member.incarnation 这样一个规则存放的,
    但是第二项database_unique_name 并不是db_name;如果改变了db_unique_name,则之后创建的数据文件
    会放在新的目录下,会导致db_file_name_convert 的失效,这一点需要特别注意。
    3)如果RAC中使用db_create_online_log_dest_n 系列参数,要相应调整stangby 上的log_file_name_convert 参数。
    
    alter system set db_unique_name='leo'  scope=spfile sid='*'; 
    alter system set log_archive_config='dg_config=(leo,orcl_st)'   scope=spfile sid='*';
    alter system set log_archive_dest_1='location=+FRA valid_for=(all_logfiles,all_roles) db_unique_name=leo'  scope=spfile sid='*';
    alter system set log_archive_dest_2='service=orcl_st valid_for=(online_logfiles,primary_role) db_unique_name=orcl_st'   scope=spfile sid='*';
    alter system set log_archive_dest_state_1=enable   scope=spfile sid='*';
    alter system set log_archive_dest_state_2=enable   scope=spfile sid='*';
    alter system set standby_file_management='auto'   scope=spfile sid='*';
    alter system set fal_server='orcl_st'   scope=spfile sid='*';
    alter system set db_file_name_convert='/u01/app/oracle/oradata/orcl/data','+DATA/leo/datafile','/u01/app/oracle/oradata/orcl/tempfile','+DATA/leo/tempfile' scope=spfile sid='*';
    alter system set log_file_name_convert='/u01/app/oracle/oradata/orcl/redo','+DATA/leo/onlinelog' scope=spfile sid='*';
    alter system set log_archive_format='%t_%s_%r.arch' scope=spfile sid='*';
    
    --备库参数
    
    --在主库创建pfile 文件并scp 到备库修改
    主要指定一些pfile的路径,不要直接create pfile from spfile 
    
    create pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/tmp.ora' from spfile;
    [oracle@rac1 dbs]$ scp tmp.ora 192.168.1.65:/u01/app/oracle/product/11.2.0/db_1/dbs/initorcl.ora
    
    [oracle@localhost dbs]$ pwd
    /u01/app/oracle/product/11.2.0/db_1/dbs
    [oracle@localhost dbs]$ cat initorcl.ora 
    orcl.__db_cache_size=436207616
    orcl.__java_pool_size=16777216
    orcl.__large_pool_size=33554432
    orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
    orcl.__pga_aggregate_target=520093696
    orcl.__sga_target=754974720
    orcl.__shared_io_pool_size=0
    orcl.__shared_pool_size=251658240
    orcl.__streams_pool_size=0
    *.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
    *.audit_trail='db'
    *.compatible='11.2.0.4.0'
    *.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'
    *.db_block_size=8192
    *.db_domain=''
    *.db_name='leo'
    *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
    *.db_recovery_file_dest_size=4621074432
    *.diagnostic_dest='/u01/app/oracle'
    *.dispatchers='(PROTOCOL=TCP) (SERVICE=leoXDB)'
    *.log_archive_dest_1='location=/u01/archive/'
    *.memory_target=1048576000
    *.open_cursors=300
    *.processes=150
    *.remote_login_passwordfile='exclusive'
    *.undo_tablespace='UNDOTBS1'
    --添加以下内容,对应修改上面的参数
    *.service_names='orcl_st'
    *.db_unique_name='orcl_st'
    *.log_archive_config='dg_config=(leo,orcl_st)' 
    *.log_archive_dest_1='location=/u01/archive valid_for=(all_logfiles,all_roles) db_unique_name=orcl_st' 
    *.log_archive_dest_2='service=leo valid_for=(online_logfiles,primary_role) db_unique_name=leo'
    *.log_archive_dest_state_1=enable 
    *.log_archive_dest_state_2=enable
    *.log_archive_format=%t_%s_%r.arc 
    *.standby_file_management='auto'
    *.fal_server='leo' 
    *.log_file_name_convert='+DATA/leo/onlinelog','/u01/app/oracle/oradata/orcl/redo'
    *.db_file_name_convert='+DATA/leo/datafile','/u01/app/oracle/oradata/orcl/data','+DATA/leo/tempfile','/u01/app/oracle/oradata/orcl/tempfile'

    10 使用 spfile 将备库启动 nomount 状态并启动监听 

    [oracle@localhost ~]$ lsnrctl start
    
    LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-MAY-2017 10:31:13
    
    Copyright (c) 1991, 2013, Oracle.  All rights reserved.
    
    Starting /u01/app/oracle/product/11.2.0/db_1/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_1/network/admin/listener.ora
    Log messages written to /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
    
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
    STATUS of the LISTENER
    ------------------------
    Alias                     LISTENER
    Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
    Start Date                28-MAY-2017 10:31:15
    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_1/network/admin/listener.ora
    Listener Log File         /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
    Listening Endpoints Summary...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
      (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
    Services Summary...
    Service "orcl" has 1 instance(s).
      Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
    The command completed successfully
    
    [oracle@localhost dbs]$ sqlplus /nolog
    
    SQL*Plus: Release 11.2.0.4.0 Production on Sun May 28 22:36:14 2017
    
    Copyright (c) 1982, 2013, Oracle.  All rights reserved.
    
    SQL> conn /as sysdba
    Connected.
    
    SQL> create spfile from pfile;
    
    File created.
    
    SQL> startup nomount
    ORACLE instance started.
    
    Total System Global Area 1043886080 bytes
    Fixed Size		    2259840 bytes
    Variable Size		  654312576 bytes
    Database Buffers	  381681664 bytes
    Redo Buffers		    5632000 bytes

    11 开始进行 duplicate 

    [oracle@rac1 ~]$ rman target sys/oracle@leo auxiliary sys/oracle@orcl_st
    
    Recovery Manager: Release 11.2.0.4.0 - Production on Sun May 28 22:42:26 2017
    
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    
    connected to target database: LEO (DBID=1717931218)
    connected to auxiliary database: LEO (not mounted)
    
    RMAN> duplicate target database for standby from active database dorecover;
    
    Starting Duplicate Db at 2017:05:28 22:42:36
    using target database control file instead of recovery catalog
    allocated channel: ORA_AUX_DISK_1
    channel ORA_AUX_DISK_1: SID=19 device type=DISK
    
    contents of Memory Script:
    {
       backup as copy reuse
       targetfile  '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwleo2' auxiliary format 
     '/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl'   ;
    }
    executing Memory Script
    
    Starting backup at 2017:05:28 22:42:37
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=53 instance=leo2 device type=DISK
    Finished backup at 2017:05:28 22:42:38
    
    contents of Memory Script:
    {
       backup as copy current controlfile for standby auxiliary format  '/u01/app/oracle/oradata/orcl/control01.ctl';
       restore clone controlfile to  '/u01/app/oracle/fast_recovery_area/orcl/control02.ctl' from 
     '/u01/app/oracle/oradata/orcl/control01.ctl';
    }
    executing Memory Script
    
    Starting backup at 2017:05:28 22:42:38
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting datafile copy
    copying standby control file
    output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_leo2.f tag=TAG20170528T224238 RECID=12 STAMP=945211363
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:04
    Finished backup at 2017:05:28 22:42:45
    
    Starting restore at 2017:05:28 22:42:45
    using channel ORA_AUX_DISK_1
    
    channel ORA_AUX_DISK_1: copied control file copy
    Finished restore at 2017:05:28 22:42:46
    
    contents of Memory Script:
    {
       sql clone 'alter database mount standby database';
    }
    executing Memory Script
    
    sql statement: alter database mount standby database
    
    contents of Memory Script:
    {
       set newname for tempfile  1 to 
     "/u01/app/oracle/oradata/orcl/tempfile/temp.279.943664427";
       switch clone tempfile all;
       set newname for datafile  1 to 
     "/u01/app/oracle/oradata/orcl/data/system.269.943664299";
       set newname for datafile  2 to 
     "/u01/app/oracle/oradata/orcl/data/sysaux.270.943664299";
       set newname for datafile  3 to 
     "/u01/app/oracle/oradata/orcl/data/undotbs1.271.943664301";
       set newname for datafile  4 to 
     "/u01/app/oracle/oradata/orcl/data/users.272.943664301";
       set newname for datafile  5 to 
     "/u01/app/oracle/oradata/orcl/data/undotbs2.280.943665551";
       backup as copy reuse
       datafile  1 auxiliary format 
     "/u01/app/oracle/oradata/orcl/data/system.269.943664299"   datafile 
     2 auxiliary format 
     "/u01/app/oracle/oradata/orcl/data/sysaux.270.943664299"   datafile 
     3 auxiliary format 
     "/u01/app/oracle/oradata/orcl/data/undotbs1.271.943664301"   datafile 
     4 auxiliary format 
     "/u01/app/oracle/oradata/orcl/data/users.272.943664301"   datafile 
     5 auxiliary format 
     "/u01/app/oracle/oradata/orcl/data/undotbs2.280.943665551"   ;
       sql 'alter system archive log current';
    }
    executing Memory Script
    
    executing command: SET NEWNAME
    
    renamed tempfile 1 to /u01/app/oracle/oradata/orcl/tempfile/temp.279.943664427 in control file
    
    executing command: SET NEWNAME
    
    executing command: SET NEWNAME
    
    executing command: SET NEWNAME
    
    executing command: SET NEWNAME
    
    executing command: SET NEWNAME
    
    Starting backup at 2017:05:28 22:42:53
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting datafile copy
    input datafile file number=00001 name=+DATA/leo/datafile/system.269.943664299
    output file name=/u01/app/oracle/oradata/orcl/data/system.269.943664299 tag=TAG20170528T224253
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:46
    channel ORA_DISK_1: starting datafile copy
    input datafile file number=00002 name=+DATA/leo/datafile/sysaux.270.943664299
    output file name=/u01/app/oracle/oradata/orcl/data/sysaux.270.943664299 tag=TAG20170528T224253
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
    channel ORA_DISK_1: starting datafile copy
    input datafile file number=00003 name=+DATA/leo/datafile/undotbs1.271.943664301
    output file name=/u01/app/oracle/oradata/orcl/data/undotbs1.271.943664301 tag=TAG20170528T224253
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:08
    channel ORA_DISK_1: starting datafile copy
    input datafile file number=00005 name=+DATA/leo/datafile/undotbs2.280.943665551
    output file name=/u01/app/oracle/oradata/orcl/data/undotbs2.280.943665551 tag=TAG20170528T224253
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
    channel ORA_DISK_1: starting datafile copy
    input datafile file number=00004 name=+DATA/leo/datafile/users.272.943664301
    output file name=/u01/app/oracle/oradata/orcl/data/users.272.943664301 tag=TAG20170528T224253
    channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
    Finished backup at 2017:05:28 22:44:36
    
    sql statement: alter system archive log current
    
    contents of Memory Script:
    {
       backup as copy reuse
       archivelog like  "+FRA/leo_pd/archivelog/2017_05_28/thread_2_seq_56.304.945211383" auxiliary format 
     "/u01/archive/2_56_943664406.arc"   archivelog like 
     "+FRA/leo_pd/archivelog/2017_05_28/thread_1_seq_72.302.945199597" auxiliary format 
     "/u01/archive/1_72_943664406.arc"   archivelog like 
     "+FRA/leo_pd/archivelog/2017_05_28/thread_2_seq_57.306.945211479" auxiliary format 
     "/u01/archive/2_57_943664406.arc"   archivelog like 
     "+FRA/leo_pd/archivelog/2017_05_28/thread_1_seq_73.303.945211381" auxiliary format 
     "/u01/archive/1_73_943664406.arc"   archivelog like 
     "+FRA/leo_pd/archivelog/2017_05_28/thread_1_seq_74.305.945211477" auxiliary format 
     "/u01/archive/1_74_943664406.arc"   ;
       catalog clone archivelog  "/u01/archive/2_56_943664406.arc";
       catalog clone archivelog  "/u01/archive/1_72_943664406.arc";
       catalog clone archivelog  "/u01/archive/2_57_943664406.arc";
       catalog clone archivelog  "/u01/archive/1_73_943664406.arc";
       catalog clone archivelog  "/u01/archive/1_74_943664406.arc";
       switch clone datafile all;
    }
    executing Memory Script
    
    Starting backup at 2017:05:28 22:44:39
    using channel ORA_DISK_1
    channel ORA_DISK_1: starting archived log copy
    input archived log thread=2 sequence=56 RECID=98 STAMP=945211394
    output file name=/u01/archive/2_56_943664406.arc RECID=0 STAMP=0
    channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:03
    channel ORA_DISK_1: starting archived log copy
    input archived log thread=1 sequence=72 RECID=96 STAMP=945199602
    output file name=/u01/archive/1_72_943664406.arc RECID=0 STAMP=0
    channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:03
    channel ORA_DISK_1: starting archived log copy
    input archived log thread=2 sequence=57 RECID=100 STAMP=945211479
    output file name=/u01/archive/2_57_943664406.arc RECID=0 STAMP=0
    channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
    channel ORA_DISK_1: starting archived log copy
    input archived log thread=1 sequence=73 RECID=97 STAMP=945211393
    output file name=/u01/archive/1_73_943664406.arc RECID=0 STAMP=0
    channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:03
    channel ORA_DISK_1: starting archived log copy
    input archived log thread=1 sequence=74 RECID=99 STAMP=945211477
    output file name=/u01/archive/1_74_943664406.arc RECID=0 STAMP=0
    channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:00
    Finished backup at 2017:05:28 22:44:51
    
    cataloged archived log
    archived log file name=/u01/archive/2_56_943664406.arc RECID=1 STAMP=945211492
    
    cataloged archived log
    archived log file name=/u01/archive/1_72_943664406.arc RECID=2 STAMP=945211492
    
    cataloged archived log
    archived log file name=/u01/archive/2_57_943664406.arc RECID=3 STAMP=945211493
    
    cataloged archived log
    archived log file name=/u01/archive/1_73_943664406.arc RECID=4 STAMP=945211493
    
    cataloged archived log
    archived log file name=/u01/archive/1_74_943664406.arc RECID=5 STAMP=945211493
    
    datafile 1 switched to datafile copy
    input datafile copy RECID=12 STAMP=945211493 file name=/u01/app/oracle/oradata/orcl/data/system.269.943664299
    datafile 2 switched to datafile copy
    input datafile copy RECID=13 STAMP=945211493 file name=/u01/app/oracle/oradata/orcl/data/sysaux.270.943664299
    datafile 3 switched to datafile copy
    input datafile copy RECID=14 STAMP=945211493 file name=/u01/app/oracle/oradata/orcl/data/undotbs1.271.943664301
    datafile 4 switched to datafile copy
    input datafile copy RECID=15 STAMP=945211493 file name=/u01/app/oracle/oradata/orcl/data/users.272.943664301
    datafile 5 switched to datafile copy
    input datafile copy RECID=16 STAMP=945211493 file name=/u01/app/oracle/oradata/orcl/data/undotbs2.280.943665551
    
    contents of Memory Script:
    {
       set until scn  2749620;
       recover
       standby
       clone database
        delete archivelog
       ;
    }
    executing Memory Script
    
    executing command: SET until clause
    
    Starting recover at 2017:05:28 22:44:53
    using channel ORA_AUX_DISK_1
    
    starting media recovery
    
    archived log for thread 1 with sequence 73 is already on disk as file /u01/archive/1_73_943664406.arc
    archived log for thread 1 with sequence 74 is already on disk as file /u01/archive/1_74_943664406.arc
    archived log for thread 2 with sequence 56 is already on disk as file /u01/archive/2_56_943664406.arc
    archived log for thread 2 with sequence 57 is already on disk as file /u01/archive/2_57_943664406.arc
    archived log file name=/u01/archive/1_73_943664406.arc thread=1 sequence=73
    archived log file name=/u01/archive/2_56_943664406.arc thread=2 sequence=56
    archived log file name=/u01/archive/2_57_943664406.arc thread=2 sequence=57
    archived log file name=/u01/archive/1_74_943664406.arc thread=1 sequence=74
    media recovery complete, elapsed time: 00:00:00
    Finished recover at 2017:05:28 22:44:56
    Finished Duplicate Db at 2017:05:28 22:45:14

    12 启动备库 
    --完成 duplicate 之后,备库就是 mount 状态: 

    SQL>  select NAME,open_mode from v$database; 
    
    NAME	  OPEN_MODE
    --------- --------------------
    LEO	  MOUNTED
    
    SQL> alter database open;
    
    Database altered.
    
    SQL> select open_mode from v$database;
    
    OPEN_MODE
    --------------------
    READ ONLY

    13 启动 MRP 进程 

    SQL>  alter database recover managed standby database disconnect from session;
    
    Database altered.
    
    SQL>  select open_mode from v$database; 
    
    OPEN_MODE
    --------------------
    READ ONLY WITH APPLY

    14 验证同步 

    节点1 执行
    
    SQL>  create table leo2 as select * from dba_users;
    
    Table created.
    
    SQL> alter system switch logfile;
    
    System altered.
    
    节点2 执行
    
    SQL> create table nancy as select * from dba_users;
    
    Table created.
    
    SQL> alter system switch logfile;
    
    System altered.
    
    --备库查询
    
    SQL> select count(*) from leo2;
    
      COUNT(*)
    ----------
    	31
    
    SQL> select count(*) from nancy; 
    
      COUNT(*)
    ----------
    	31
    
    SQL> select THREAD#,sequence#,applied from v$archived_log order by 1,2;
    
       THREAD#  SEQUENCE# APPLIED
    ---------- ---------- ---------
    	 1	   72 NO
    	 1	   73 YES
    	 1	   74 YES
    	 2	   56 YES
    	 2	   57 NO
    展开全文
  • HA/DG/RAC 三者的区别

    千次阅读 2010-08-14 16:04:00
    高可用性解决方案分为4种 (DG AR RAC HA): 一种是oracle提供的被用方法,Standby (=9i DataGuard) 一种是AR (高级复制Advanced Replication,在以前版本叫快照snapshot) 一种是oracle 并行...
  • Oracle 11g RAC+DG项目实战-视频分享

    千次阅读 2013-10-28 10:45:25
    在15集视频中详细阐述了Oracle RAC的安装,RAC如何配置Active Data Guard,DG如何切换!绝对重量级的视频。掌握这个技术,资深Oracle DBA的岗位你也轻松秒杀! 实验手册在最后一集视频中! 概述: 本系列视频是...
  • 如何Oracle_RAC恢复一个节点总结

    万次阅读 2016-07-05 22:48:14
    如何Oracle_RAC恢复一个节点总结 作者:51cto出处:博客2013-08-01 13:39  Rac1 已坏  Rac3 正常  先在rac3上把rac1的信息删干净,然后重新填加rac1  步骤如下:  1,在rac1上运行DBCA,...
  • Oracle】11gRAC添加静态监听

    千次阅读 2018-05-07 07:50:58
    11gRAC添加静态监听查看listener文件的内容[grid@rac1 admin]$ more listener.ora查看监听状态[grid@rac1 admin]$ lsnrctl status listener [grid@rac1 admin]$ srvctl config network添加监听[grid@rac1 admin]$ ...
  • RAC 11g + ASM 简单拓扑图

    千次阅读 2013-11-30 10:23:33
    抽象问题,图形化 简单问题,多维化 常见问题,文字化 RAC 11g,拓扑化 Oracle 11 G RAC + ASM 黄金搭档!
  • Oracle11g RAC集群启动关闭管理

    千次阅读 2015-11-05 09:42:57
    简单的Oracle11g RAC集群启动关闭管理1.切换到集群用户grid[root@rac1 ~]# su - grid2.查看集群资源状态(黄色标注11G不使用此资源 所以OFFLINE为正常状态)[grid@rac1 ~]$ crs_stat -t Name Type Target State Host...
  • oracle双机/RAC/Dataguard的区别

    千次阅读 2012-09-14 09:28:16
    高可用性解决方案分为4种 (DG、AR、RAC、HA): 一种是oracle提供的被用方法,Standby (=9i DataGuard) 一种是AR (高级复制Advanced Replication,在以前版本叫快照snapshot) 一种是oracle并行服务器8i的OPS (9i RAC...
  • 本人新手,资源有限,希望能得到大神指点。想利用虚拟机搭建一个Oracle 11grac集群,方便以后的学习!
  • 企业级RAC+DG架构部署

    千次阅读 2017-05-26 16:34:54
    Application Clusters,中文译为“实时应用集群”,是ORACLE甲骨文公司提供的在低成本服务器上构建高可用性数据库系统的解决方案,部署自由,无需购买额外部件,就可以实现多节点的负载均衡和故障转移功能,满足7*...
  • CentOS7.5搭建ORACLE RAC+DG

    千次阅读 2018-12-28 15:15:12
    RAC+DG RAM:4G ,OS:CENTOS7.5 HOSTNAME:RAC1: PUBLIC IP:162.168.145.244,PRIV IP:192.168.89.219,VIP:192.168.145.144,scanip:192.168.145.140 HOSTNAME:RAC2: PUBLIC IP:162.168.145.245,PRIV ...
  • 今天在做RAC-DG实验时,碰到了不少的问题,这个问题是在操作用pifle创建spifle时出现的 由于在配置RAC-DG主库参数时,大部分人喜欢直接用alter system set xxx='xxx.xxx' scope=spfile; 而我由于不想一条条敲命令,...
  • 今天在配置RAC-DG时,修改主库参数文件后无法用修改后的PFILE启动RAC主数据库,碰到了LRM-00101错误,这是一个语法错误,但是一开始始终没找到解决方法: SQL> create pfile='/rmanbackup/initora11rac.ora' from ...
  • Data Guard 是Oracle的远程复制技术,它有物理和逻辑之分,但是总的来说,它需要在异地有一套独立的系统,这是两套硬件配置可以不同的系统,但是这两套系统的软件结构保持一致,包括软件的版本,目录存储结构,以及...
  • $GRID_HOME/bin和$ORACLEHOME/bin目录下的oracle文件权限导致ORA-01078和Linux-x86_64 Error故障处理案例
  • oracle rac 11.2.0.3 升级到11.2.0.4

    千次阅读 2015-08-15 17:54:20
    下载解压oracle安装文件,第三个文件为grid p13390677_112040_Linux-x86-64_1of7.zip p13390677_112040_Linux-x86-64_2of7.zip p13390677_112040_Linux-x86-64_3of7.zip 解压完成之后,无需停止grid和db,...
1 2 3 4 5 ... 20
收藏数 6,682
精华内容 2,672
关键字:

dg oracle rac