程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> oracleRACclient-sideTAF&&server-sideTAF

oracleRACclient-sideTAF&&server-sideTAF

編輯:Oracle教程

今天是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+++++++++++++++++++++++++++


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved