Oracle RAC failover 测试(连接时故障转移)

Oracle RAC failover 测试(连接时故障转移)

    Oracle RAC 集群最突出的表现就是高可用性,这些内容主要包括load balance以及failover,通过这些技术使得单点故障不影响客户端端应用程序对数据库的正常访问,以及通过创建service实现节点间负载均衡。本文主要描述Oracle 10g rac环境下的Oracle failover测试。   下面是一些关于这方面的基础参考或相关链接:   有关负监听配置,载均衡(load balance)以及Oracle service请参考

  • ORACLE RAC 监听配置 (listener.ora tnsnames.ora)
  • ORACLE RAC 下非缺省端口监听配置(listener.ora tnsnames.ora)
  • Oracle RAC 客户端连接负载均衡(Load Balance)
  • Oracle RAC 服务器端连接负载均衡(Load Balance)
  • Oracle RAC 负载均衡测试(结合服务器端与客户端)
  • Oracle RAC failover 测试(TAF方式)
  • Oracle RAC failover 测试(Server TAF方式)
1、Oracle failover的几种方式
  Oracle failover也叫故障转移,从Oracle 10g开始,分为3种方式:
  a. Client-Side Connect time Failover
    客户端连接failover模式,此方式较为简单,只要安装了rac集群,缺省情况下即被启用。
  b. TAF
    透明故障转移,此方式同样基于客户端完成,需要配置客户端tnsnames.ora,连接故障发生时,无须重新连接
  c. Service-Side TAF
    服务器端透明故障转移,通过配置service来实现,客户端无须任何配置。
  
  本文主要演示第一种情形,即客户端在发起连接请求时如何实现故障转移    
  注意事项: 不能在listener.ora 文件中设置GLOBAL_NAME
         该参数会禁用Connect-time Failover 和 Transparent Application Failover

2、Client-Side Connect time Failover
  下面关于Client-Side Connect time Failover来自Oracle 的官方描述 ID 453293.1
  The connect-time failover enables clients to connect to another listener if the initial connection to the first 
  listener fails. The number of listener protocol addresses determines how many listeners are tried. Without 
  connect-time failover, Oracle Net attempts a connection with only one listener. The default is on. 

  Tnsnames Parameter: FAILOVER 
  
  (failover=on) is default for ADDRESS_LISTs, DESCRIPTION_LISTs, and a set of 
  DESCRIPTIONs., therefore, you do not have to specify it explicitly. 

  基于客户端的failover比较好理解。对于在客户端tnsnames.ora有多个VIP的情形,客户端会首先请求定位到第一个VIP,如果第一个VIP不
  可达,则继续尝试使用下一个VIP,直到成功建立连接,如果所有的VIP无法连接将收到错误消息。
  通常情况下,我们使用vip作为tnsnames.ora中的连接地址

3、服务器端、客户端的环境
  #服务器端环境,host信息
  oracle@bo2dbp:~> cat /etc/hosts |grep vip
  192.168.7.61   bo2dbp-vip.2gotrade.com    bo2dbp-vip
  192.168.7.62   bo2dbs-vip.2gotrade.com    bo2dbs-vip
  
  #服务器端环境,集群信息
  oracle@bo2dbp:~> ./crs_stat.sh 
   Resource name                                Target     State             
  --------------                                ------     -----             
  ora.GOBO4.GOBO4A.inst                         ONLINE     ONLINE on bo2dbp  
  ora.GOBO4.GOBO4B.inst                         ONLINE     ONLINE on bo2dbs  
  ora.GOBO4.db                                  ONLINE     ONLINE on bo2dbp  
  ora.bo2dbp.ASM1.asm                           ONLINE     ONLINE on bo2dbp  
  ora.bo2dbp.LISTENER_BO2DBP.lsnr               ONLINE     ONLINE on bo2dbp  
  ora.bo2dbp.LISTENER_ORA10G_BO2DBP.lsnr        ONLINE     ONLINE on bo2dbp  
  ora.bo2dbp.gsd                                ONLINE     ONLINE on bo2dbp  
  ora.bo2dbp.ons                                ONLINE     ONLINE on bo2dbp  
  ora.bo2dbp.vip                                ONLINE     ONLINE on bo2dbp  
  ora.bo2dbs.ASM2.asm                           ONLINE     ONLINE on bo2dbs  
  ora.bo2dbs.LISTENER_BO2DBS.lsnr               ONLINE     ONLINE on bo2dbs  
  ora.bo2dbs.LISTENER_ORA10G_BO2DBS.lsnr        ONLINE     ONLINE on bo2dbs  
  ora.bo2dbs.gsd                                ONLINE     ONLINE on bo2dbs  
  ora.bo2dbs.ons                                ONLINE     ONLINE on bo2dbs  
  ora.bo2dbs.vip                                ONLINE     ONLINE on bo2dbs  
  ora.ora10g.db                                 ONLINE     ONLINE on bo2dbp 

  #客户端环境
  robin@SZDB:~> cat /etc/issue
  
  Welcome to SUSE Linux Enterprise Server 10 SP3 (x86_64) - Kernel \r (\l).
  
  robin@SZDB:~> sqlplus -v
  
  SQL*Plus: Release 10.2.0.3.0 - Production
  
  #客户端tnsnames配置
  GOBO4 =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.61)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.62)(PORT = 1521))
      (LOAD_BALANCE = yes)
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = GOBO4)
      )
    )

4、连接测试  
  #首次建立连接,此时客户端从tnsnames配置的第一个IP建立连接,即192.168.7.61
  #VIP 192.168.7.61对应的hostname以及instance_name分别为bo2dbp,GOBO4A,所以我们获得如下返回结果
  robin@SZDB:~> sqlplus fail_over/fail@gobo4

  fail_over@GOBO4> get verify.sql
    1  REM the following query is for TAF connection verification
    2  col sid format 99999
    3  col serial# format 9999999
    4  col failover_type format a13
    5  col failover_method format a15
    6  col failed_over format a11
    7  Prompt
    8  Prompt Failover status for current user
    9  Prompt ============================================
   10  SELECT   sid,
   11   serial#,
   12   failover_type,
   13   failover_method,
   14   failed_over
   15   FROM   v$session
   16   WHERE   username = 'FAIL_OVER';
   17  REM the following query is for load balancing verification
   18  col host_name format a20
   19  Prompt
   20  Prompt Current instance name and host name
   21  Prompt ========================================
   22* SELECT   instance_name,host_name FROM v$instance;
   23  
   
  fail_over@GOBO4> @verify.sql
  
  Failover status for current user
  ============================================
     SID  SERIAL# FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER
  ------ -------- ------------- --------------- -----------
    1071      249 NONE          NONE            NO
  
  
  Current instance name and host name
  ========================================
  INSTANCE_NAME    HOST_NAME
  ---------------- --------------------
  GOBO4A           bo2dbp

  #停止集群数据库的第一个instance,即GOBO4A
  oracle@bo2dbp:~> srvctl stop instance -d GOBO4 -i GOBO4A
  #校验结果
  oracle@bo2dbp:~> ./crs_stat.sh | grep inst
  ora.GOBO4.GOBO4A.inst                         OFFLINE    OFFLINE           
  ora.GOBO4.GOBO4B.inst                         ONLINE     ONLINE on bo2dbs 
  
  #回到客户端原来的session,此时出现ORA-03114
  fail_over@GOBO4> /
  SELECT   instance_name,host_name FROM v$instance
  *
  ERROR at line 1:
  ORA-03113: end-of-file on communication channel
  
  fail_over@GOBO4> /
  ERROR:
  ORA-03114: not connected to ORACLE
  
  ERROR:
  ORA-03114: not connected to ORACLE

  #下面尝试重新建立连接
  fail_over@GOBO4> conn fail_over/fail@gobo4
  Connected.
  fail_over@GOBO4> @verify
  
  Failover status for current user
  ============================================
     SID  SERIAL# FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER
  ------ -------- ------------- --------------- -----------
    1062       94 NONE          NONE            NO
  
  
  Current instance name and host name
  ========================================
  INSTANCE_NAME    HOST_NAME
  ---------------- --------------------
  GOBO4B           bo2dbs
  
  #Author : Robinson
  #Blog   : http://blog.csdn.net/robinson_0612
  
  #从上面的查询可知,当前的session已经连接到第二个实例。且FAILOVER_TYPE,FAILOVER_METHOD,FAILED_OVER几个至没有发生任何变化
  #因为这几个参数主要是针对TAF。

5、小结
  a、客户端连接时的故障转移,服务器端和客户端无需任何配置,缺省情况下即被开启,即failover=on
  b、只要集群环境存在(非单节点RAC),客户端的连接请求会逐个尝试列出的VIP,直到连接成功为止,如果所有不可连接,返回错误
  c、客户端已经建立后,服务器端实例或节点故障,都将导致客户端必须重新发起新的连接请求
posted @ 2021-04-20 15:31  耀阳居士  阅读(342)  评论(0编辑  收藏  举报