靈活實現RAC三節點的負載均衡及TAF配置(五)

yangtingkun發表於2010-02-06

這兩天配置了一個三節點的RAC環境,想起前一段時間Thomas Zhang給我出的一個題目,配置一個三節點RAC環境的複雜負載均衡以及Transparent Application Failover的服務名。現在有環境了,可以將給出驗證後的結果了。

設定不同節點的SERVICE_NAMES,解決最終問題。

靈活實現RAC三節點的負載均衡及TAF配置(一):http://yangtingkun.itpub.net/post/468/482683

靈活實現RAC三節點的負載均衡及TAF配置(二):http://yangtingkun.itpub.net/post/468/482724

靈活實現RAC三節點的負載均衡及TAF配置(三):http://yangtingkun.itpub.net/post/468/487416

靈活實現RAC三節點的負載均衡及TAF配置(四):http://yangtingkun.itpub.net/post/468/487825

 

 

前面嘗試了很多的配置,基本上可以滿足絕大部分的要求,但是由於沒有辦法在DESCRIPTION中解決單獨指向例項1和例項2問題,因此只能使用DESCRIPTION_LIST解決,但是這也帶來了新的問題,使得LOAD_BANLANCETAF的設定異常的複雜,而且容易導致ORA-3113等錯誤。

因此首先修改例項1和例項2SERVICE_NAMES,使這兩個功能相同的例項擁有相同的SERVICE_NAMES,且與例項3SERVICE_NAMES相區別:

SQL> SELECT INSTANCE_NUMBER, INSTANCE_NAME      
  2  FROM GV$INSTANCE;

INSTANCE_NUMBER INSTANCE_NAME
--------------- ----------------
              1 testrac1
              3 testrac3
              2 testrac2

SQL> COL NAME FORMAT A30       
SQL> COL VALUE FORMAT A30
SQL> SELECT INST_ID, NAME, VALUE
  2  FROM GV$SYSTEM_PARAMETER
  3  WHERE NAME = 'service_names';

   INST_ID NAME                           VALUE
---------- ------------------------------ ------------------------------
         1 service_names                  testrac,testrac1
         3 service_names                  testrac,testrac3
         2 service_names                  testrac,testrac2

SQL> ALTER SYSTEM SET SERVICE_NAMES = 'testrac,testrac12' SCOPE = BOTH SID = 'testrac1';

系統已更改。

SQL> ALTER SYSTEM SET SERVICE_NAMES = 'testrac,testrac12' SCOPE = BOTH SID = 'testrac2';

系統已更改。

SQL> ALTER SYSTEM SET SERVICE_NAMES = 'testrac,testrac3' SCOPE = BOTH SID = 'testrac3';

系統已更改。

SQL> SELECT INST_ID, NAME, VALUE
  2  FROM GV$SYSTEM_PARAMETER
  3  WHERE NAME = 'service_names';

   INST_ID NAME                           VALUE
---------- ------------------------------ ------------------------------
         3 service_names                  testrac,testrac3
         2 service_names                  testrac,testrac12
         1 service_names                  testrac,testrac12

下面重新配置服務名:

SERVICEA =
  (DESCRIPTION_LIST =
    (LOAD_BALANCE = no)  
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
      )
      (LOAD_BALANCE = yes)
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = TESTRAC12)
        (FAILOVER_MODE =
          (TYPE = SELECT)
          (METHOD = BASIC)
          (BACKUP = SERVICEA_BACKUP)
        )
      )
    )
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.227)(PORT = 1521))
      )
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = TESTRAC3)
        (FAILOVER_MODE =
          (TYPE = SELECT)
          (METHOD = BASIC)
          (BACKUP = SERVICEA_BACKUP)
        )
      )
    )
  )

SERVICEB =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.227)(PORT = 1521))
      )
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = TESTRAC3)
        (FAILOVER_MODE =
          (TYPE = SELECT)
          (METHOD = BASIC)
          (BACKUP = SERVICEA)
        )
      )
    )
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
      )
      (LOAD_BALANCE = yes)
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = TESTRAC12)
        (FAILOVER_MODE =
          (TYPE = SELECT)
          (METHOD = BASIC)
          (BACKUP = SERVICEA)
        )
      )
    )
    (LOAD_BALANCE = no)
  )


SERVICEA_BACKUP =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
      )
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = TESTRAC12)
        (FAILOVER_MODE =
          (TYPE = SELECT)
          (METHOD = BASIC)
          (BACKUP = SERVICEA_BACKUP)
        )
      )
    )
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.227)(PORT = 1521))
      )
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = TESTRAC3)
        (FAILOVER_MODE =
          (TYPE = SELECT)
          (METHOD = BASIC)
          (BACKUP = SERVICEA)
        )
      )
    )
    (LOAD_BALANCE = no)
  )

測試連線:

SQL> CONN TEST/TEST@SERVICEA
已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac2

SQL> CONN TEST/TEST@SERVICEA
已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac1

SQL> CONN TEST/TEST@SERVICEB
已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac3

SQL> CONN TEST/TEST@SERVICEB
已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac3

透過SERVICEA可以在節點1和節點2的例項上負載均衡的連線,而透過SERVICEB則連線節點3

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac3

透過命令列方式關閉節點3

bash-2.03$ srvctl stop inst -d testrac -i testrac3

檢查當前連線的例項:

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac2

啟動資料庫例項:

bash-2.03$ srvctl start inst -d testrac -i testrac3

重複一下同樣的操作:

SQL> CONN TEST/TEST@SERVICEB
已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac3

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac1

需要注意在兩次執行當前例項的查詢之間,透過命令列的方式關閉了例項3

可以看到,當透過SERVICEB連線到例項3後,如果例項3發生故障,TAF將會話負載均衡的切換到例項1和例項2上。

下面啟動一下例項2,檢查最後一種情況,透過SERVICEA連線資料庫,當節點1或節點2都失敗的情況:

SQL> CONN TEST/TEST@SERVICEA
已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac1

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac2

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac1

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac3

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac2

對應的後臺命令列啟動關閉例項的指令碼為:

bash-2.03$ srvctl stop inst -d testrac -i testrac1
bash-2.03$ srvctl start inst -d testrac -i testrac1
bash-2.03$ srvctl stop inst -d testrac -i testrac2
bash-2.03$ srvctl stop inst -d testrac -i testrac1
bash-2.03$ srvctl start inst -d testrac -i testrac1,testrac2
bash-2.03$ srvctl stop inst -d testrac -i testrac3

下面簡單描述一下上面的過程。

透過SERVICEA服務名登陸,檢查當前連線的例項,發現連線到例項1上,在後臺關閉例項1,檢查連線例項,發現TAF後連線到例項2上,後臺啟動例項1,然後關閉例項2,再次檢查連線,發現TAF操作後,連線又回到了例項1上。然後關閉例項1,檢查當前的連線,由於例項1和例項2都已經被關閉,因此連線到了例項3上。最後啟動例項1和例項2,關閉例項3,檢查連線,當前的連線又回到了例項2上。

終於透過SERVICEASERVICEBSERVICEA_BACKUP三個服務名的配合,以及設定RAC不同節點上的SERVICE_NAMES引數,終於完美的解決了這個問題。

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4227/viewspace-626982/,如需轉載,請註明出處,否則將追究法律責任。

相關文章