今天是2014-03-19,对oracle TAF技术整理一下学习笔记,记录如下:
####################################################################################
failover_mode 参数 描述
####################################################################################
backup 指定用于创建备份连接的本地服务名,当使用preconnect预创建连接
的时候应该指明这个参数值
method TAF的配置包含如下两种failover切换方式
preconnect:创建到切换实例的预连接,提供快速failover的能力
basic:在发生failover的时候创建连接
retries failover发生后尝试连接的次数,如果指明了delay参数,那么retries默认为5
type Taf的配置包含如下三种failover的类型:
session:如果用户连接丢失,新的会话将自动被创建。这种类型的failover不能
尝试恢复select操作
select:如果用户连接丢失,新创建的会话将继续之前失败之后的select操作
none 这是默认值,不具备failover能力。这个能被明确的指明用于防止failover
的发生。
注意:这些参数只能手动设置,不能在listener.ora文件中SID_LIST_<LISTENER_NAME>条目中设置global_dbname参数,静态配置的全局数据
库名称不能使用TAF功能。另外jdbc thin驱动方式无法使用TAF技术。
实现TAF有两种方式一种为client-side TAF 另一种为server-side TAF ,下面先介绍第一种client-side TAF:
RAC = (DESCRIPTION = (FAILOVER=ON) (LOAD_BALANCE=ON) (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = rac-one)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = rac-two)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = Rac2) (FAILOVER_MODE= (TYPE=SELECT) (METHOD=BASIC)) ) )
该方式使用了连接时failover、client-side TAF 和客户端负载均衡,当该客户端尝试连接数据库的时候会在address中随即挑选一个用于连接数据库,假如选择rac-one如果连接失败,那么就会使用rac-two进行连接,如果都失败那么将提出连接错误。当客户端已经连接到数据库的时候,突然rac-one实例关闭,那么该客户端随即创建与rac-two的会话连接这个过程报错select的操作。例外我们可以使用retries和delay参数来指定重新连接次数和延迟重新连接的秒数。如下是重试连接rac-one5次每次120秒。
eg:
RAC = (DESCRIPTION = (FAILOVER=ON) (LOAD_BALANCE=OFF) (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = rac-one-vip)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = rac-two-vip)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = Rac2) (FAILOVER_MODE= (TYPE=SELECT) (METHOD=BASIC) (RETRIES=5) (DELAY=120) ) ) )
另外在failover_mode中的method中有preconnect(预连接),该说明在client-side TAF中分配一个主连接的同时预先分配备用连接。
eg:
RAC1 = (DESCRIPTION = (FAILOVER=ON) (LOAD_BALANCE=OFF) (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = rac-one)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = Rac2) (FAILOVER_MODE= (METHOD=PRECONNECT) (BACKUP=RAC2) (TYPE=SELECT) (RETRIES=5) (DELAY=30) ) ) ) RAC2 = (DESCRIPTION = (FAILOVER=ON) (LOAD_BALANCE=OFF) (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = rac-two)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = Rac2) (FAILOVER_MODE= (METHOD=PRECONNECT) (BACKUP=RAC1) (TYPE=SELECT) (RETRIES=5) (DELAY=30) ) ) )
验证client-side TAF:
首先确认/etc/hosts文件如下:
[root@rac-one ~]# more /etc/hosts 127.0.0.1 localhost localhost.localdomain 192.168.2.11 openfiler1 192.168.1.112 rac-two-priv 192.168.1.111 rac-one-priv 192.168.4.111 rac-one rac-one.localdomain 192.168.4.112 rac-two rac-two.localdomain 192.168.4.113 rac-one-vip 192.168.4.114 rac-two-vip [root@rac-one ~]#
查看客户端tnsname.ora配置:
RAC = (DESCRIPTION = (FAILOVER=ON) (LOAD_BALANCE=ON) (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = rac-two-vip)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = rac-one-vip)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = Rac) (FAILEOVER_MODE= (METHOD=BASIC) (TYPE=SELECT) (RETRIES=5) (DELAY=60)) ) )
用户连接数据库,然后查看数据库会话信息,(注意还需要修改windows的hosts名称否则无法识别rac-two-vip或是rac-one-vip):
rac-one节点:
SQL> r 1 select inst_id,username,failover_type,failover_method,failed_over from gv$session where username in (‘SYSTEM‘,‘SYS‘) 2* INST_ID USERNAME FAILOVER_TYPE FAILOVER_M FAI ---------- ------------------------------ ------------- ---------- --- 2 SYS NONE NONE NO 2 SYS NONE NONE NO 2 SYS NONE NONE NO 2 SYS NONE NONE NO 2 SYS NONE NONE NO 2 SYS NONE NONE NO 1 SYS NONE NONE NO 1 SYS NONE NONE NO 1 SYS NONE NONE NO 1 SYSTEM SELECT BASIC NO 10 rows selected. SQL>
可知目前system用户已经具备failover功能。
注意:在配置client-side TAF的时候尤其注意参数的设置位置,否则无法实现failover。
其实在11G中scan功能也实现了负载均衡的作用,它是从dns解析中的三个地址轮询负载的分配给scan listener进而采去和本地listener进行通信。
另外实现TAF的方式为server-side TAF。说白了,就是通过服务端设置service来实现,先比client-side TAF有很多简便的方式。
eg:
增加服务名rac1和rac2:
oracle@rac-two ~]$ srvctl add service -d Rac -s rac1 -r Rac1 -a Rac2 -P basic -y automatic -e select -m basic -z 5 -w 120 [oracle@rac-two ~]$ srvctl add service -d Rac -s rac2 -r Rac2 -a Rac1 -P basic -y automatic -e select -m basic -z 5 -w 120
查看服务名状态
[oracle@rac-two ~]$ srvctl status service -d RAc Service rac1 is not running. Service rac2 is not running.
启动服务资源:
[oracle@rac-two ~]$ srvctl start service -d Rac [oracle@rac-two ~]$ srvctl status service -d Rac Service rac1 is running on instance(s) Rac1 Service rac2 is running on instance(s) Rac2
查看配置信息:
[oracle@rac-two ~]$ srvctl config service -d Rac Service name: rac1 Service is enabled Server pool: Rac_rac1 Cardinality: 1 Disconnect: false Service role: PRIMARY Management policy: AUTOMATIC DTP transaction: false AQ HA notifications: false Failover type: SELECT Failover method: BASIC TAF failover retries: 5 TAF failover delay: 120 Connection Load Balancing Goal: LONG Runtime Load Balancing Goal: NONE TAF policy specification: BASIC Edition: Preferred instances: Rac1 Available instances: Rac2 Service name: rac2 Service is enabled Server pool: Rac_rac2 Cardinality: 1 Disconnect: false Service role: PRIMARY Management policy: AUTOMATIC DTP transaction: false AQ HA notifications: false Failover type: SELECT Failover method: BASIC TAF failover retries: 5 TAF failover delay: 120 Connection Load Balancing Goal: LONG Runtime Load Balancing Goal: NONE TAF policy specification: BASIC Edition: Preferred instances: Rac2 Available instances: Rac1 [oracle@rac-two ~]$
注意这个时候,实例Rac1已经注册了rac1服务,且主要实例为Rac1备用实例为Rac2,实例Rac2注册了rac2服务,且主要实例为Rac2备用实例为Rac1;
本地监听只会注册本地服务名,scan监听将注册所有的监听服务名。
验证:
首先明确客户端配置:
RAC = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = rac-two-cluster-scan.grid.example.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = Rac2) ) )
登录数据库查看会话信息如下:
会话一使用system用户登录数据库:
用户没有登录之前状态:
[oracle@rac-one ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Wed Mar 19 20:59:56 2014 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> col username for a20 SQL> set linesize 200 SQL> select inst_id,username,failover_type,failover_method,failed_over from gv$session where username=‘SYSTEM‘; no rows selected
登录之后状态:
SQL> r 1* select inst_id,username,failover_type,failover_method,failed_over from gv$session where username=‘SYSTEM‘ INST_ID USERNAME FAILOVER_TYPE FAILOVER_M FAI ---------- -------------------- ------------- ---------- --- 2 SYSTEM SELECT BASIC NO 2 SYSTEM SELECT BASIC NO SQL>
这个时候关闭该节点,且在客户端执行select * from dba_objects;语句,
查看节点二 用户会话状态。
SQL> r 1* select inst_id,username,failover_type,failover_method,failed_over from gv$session where username=‘SYSTEM‘ INST_ID USERNAME FAILOVER_TYPE FAILOVER_M FAI ---------- -------------------- ------------- ---------- --- 1 SYSTEM SELECT BASIC YES SQL>
可以看到用户只在几秒中停顿后继续完成了select操作,且failed_over状态为yes,证明failover已经生效。
查看状态信息如下:
c[grid@rac-two ~]$ crsctl status res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.DATADG.dg ONLINE ONLINE rac-two ora.GIDG.dg ONLINE ONLINE rac-two ora.LISTENER.lsnr ONLINE ONLINE rac-two ora.asm ONLINE ONLINE rac-two Started ora.gsd OFFLINE OFFLINE rac-two ora.net1.network ONLINE ONLINE rac-two ora.ons ONLINE ONLINE rac-two ora.registry.acfs ONLINE ONLINE rac-two -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE rac-two ora.LISTENER_SCAN2.lsnr 1 ONLINE ONLINE rac-two ora.LISTENER_SCAN3.lsnr 1 ONLINE ONLINE rac-two ora.cvu 1 ONLINE ONLINE rac-two ora.oc4j 1 ONLINE ONLINE rac-two ora.rac-one.vip 1 ONLINE INTERMEDIATE rac-two FAILED OVER ora.rac-two.vip 1 ONLINE ONLINE rac-two ora.rac.db 1 ONLINE ONLINE rac-two Open 2 ONLINE OFFLINE Instance Shutdown ora.rac.rac1.svc 1 ONLINE ONLINE rac-two ora.rac.rac2.svc 1 ONLINE ONLINE rac-two ora.scan1.vip 1 ONLINE ONLINE rac-two ora.scan2.vip 1 ONLINE ONLINE rac-two ora.scan3.vip 1 ONLINE ONLINE rac-two [grid@rac-two ~]$
可知目前ora.ora-one.vip已经failed over,且ora.rac.rac1.svc运行到了rac-two中。
重启节点后查看资源如下:
[grid@rac-one ~]$ crsctl status res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.DATADG.dg ONLINE ONLINE rac-one ONLINE ONLINE rac-two ora.GIDG.dg ONLINE ONLINE rac-one ONLINE ONLINE rac-two ora.LISTENER.lsnr ONLINE OFFLINE rac-one ONLINE ONLINE rac-two ora.asm ONLINE ONLINE rac-one Started ONLINE ONLINE rac-two Started ora.gsd OFFLINE OFFLINE rac-one OFFLINE OFFLINE rac-two ora.net1.network ONLINE ONLINE rac-one ONLINE ONLINE rac-two ora.ons ONLINE OFFLINE rac-one STARTING ONLINE ONLINE rac-two ora.registry.acfs ONLINE ONLINE rac-one ONLINE ONLINE rac-two -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE rac-two STOPPING ora.LISTENER_SCAN2.lsnr 1 ONLINE ONLINE rac-two ora.LISTENER_SCAN3.lsnr 1 ONLINE ONLINE rac-two ora.cvu 1 ONLINE ONLINE rac-two ora.oc4j 1 ONLINE ONLINE rac-two ora.rac-one.vip 1 ONLINE INTERMEDIATE rac-two FAILED OVER,STOPPING ora.rac-two.vip 1 ONLINE ONLINE rac-two ora.rac.db 1 ONLINE ONLINE rac-two Open 2 ONLINE OFFLINE Instance Shutdown ora.rac.rac1.svc 1 ONLINE ONLINE rac-two ora.rac.rac2.svc 1 ONLINE ONLINE rac-two ora.scan1.vip 1 ONLINE ONLINE rac-two ora.scan2.vip 1 ONLINE ONLINE rac-two ora.scan3.vip 1 ONLINE ONLINE rac-two [grid@rac-one ~]$ [grid@rac-one ~]$ crsctl status res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.DATADG.dg ONLINE ONLINE rac-one ONLINE ONLINE rac-two ora.GIDG.dg ONLINE ONLINE rac-one ONLINE ONLINE rac-two ora.LISTENER.lsnr ONLINE ONLINE rac-one ONLINE ONLINE rac-two ora.asm ONLINE ONLINE rac-one Started ONLINE ONLINE rac-two Started ora.gsd OFFLINE OFFLINE rac-one OFFLINE OFFLINE rac-two ora.net1.network ONLINE ONLINE rac-one ONLINE ONLINE rac-two ora.ons ONLINE ONLINE rac-one ONLINE ONLINE rac-two ora.registry.acfs ONLINE ONLINE rac-one ONLINE ONLINE rac-two -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE rac-one ora.LISTENER_SCAN2.lsnr 1 ONLINE ONLINE rac-two ora.LISTENER_SCAN3.lsnr 1 ONLINE ONLINE rac-two ora.cvu 1 ONLINE ONLINE rac-two ora.oc4j 1 ONLINE ONLINE rac-two ora.rac-one.vip 1 ONLINE ONLINE rac-one ora.rac-two.vip 1 ONLINE ONLINE rac-two ora.rac.db 1 ONLINE ONLINE rac-two Open 2 ONLINE ONLINE rac-one Open ora.rac.rac1.svc 1 ONLINE ONLINE rac-two ora.rac.rac2.svc 1 ONLINE ONLINE rac-two ora.scan1.vip 1 ONLINE ONLINE rac-one ora.scan2.vip 1 ONLINE ONLINE rac-two ora.scan3.vip 1 ONLINE ONLINE rac-two [grid@rac-one ~]$
如果当Rac1失效(节点关闭),那么select将再次移动到Rac2上来
SQL> r 1* select inst_id,username,failover_type,failover_method,failed_over from gv$session where username=‘SYSTEM‘ INST_ID USERNAME FAILOVER_TYPE FAILOVER_M FAI ---------- ------------------------------ ------------- ---------- --- 2 SYSTEM SELECT BASIC YES
到了11G R2 使用scan和server-side TAF是最佳选择。
That’s all!!!!!
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Rhys↖(^ω^)↗Amy+++++++++++++++++++++++++++
oracle RAC client-side TAF && server-side TAF,布布扣,bubuko.com