溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ORACLE RAC均衡負(fù)載

發(fā)布時間:2020-07-21 18:52:35 來源:網(wǎng)絡(luò) 閱讀:641 作者:學(xué)者之路 欄目:關(guān)系型數(shù)據(jù)庫

    oracle集群數(shù)據(jù)庫有些時候并沒有實(shí)現(xiàn)自動負(fù)載均衡,基本所有業(yè)務(wù)都在某一個節(jié)點(diǎn)上,所以容易造成某一個節(jié)點(diǎn)宕機(jī)的情況,針對這種情況我們就需要手動為期配置負(fù)載均衡。針對負(fù)載均衡配置有在服務(wù)器端和客戶端兩種入手方法(但是我發(fā)現(xiàn)主要還是服務(wù)器端配置效果更明顯)

    一、服務(wù)器端配置

      1、首先要在每個節(jié)點(diǎn)服務(wù)器上tnsnames.ora文件進(jìn)行如下,注意看紅色部分,而且我建議在HOST后面的值直接寫IP地址,如果寫hosts文件的主機(jī)名的話,有可能會出現(xiàn)TNS連接超時的情況。

RACDB =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.153)(PORT = 1521))/*一節(jié)點(diǎn)的IP*/

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.154)(PORT = 1521))/*二節(jié)點(diǎn)的IP*/

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.155)(PORT = 1521))/*如果是11G的話,需要把scan ip也寫上,不然你用scan ip連不上去*/

    (LOAD_BALANCE = yes)                                             /*這個參數(shù)必須添加,不然沒法實(shí)現(xiàn)均衡負(fù)載*/

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = RACDB)

    )

  )

 

LISTENERS_RACDB =

  (ADDRESS_LIST =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.153)(PORT = 1521))

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.154)(PORT = 1521))

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.155)(PORT = 1521))

  )


      2、任意一個節(jié)點(diǎn)執(zhí)行如下操作。在初始化參數(shù)中設(shè)置參數(shù)remote_listeners

   

SQL> conn system/admin@racdb 

已連接。

SQL> show parameter remote_listener

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

remote_listener                      string                                         /*可以看到當(dāng)前的值為空*/

SQL>

SQL> alter system set remote_listener='LISTENERS_RACDB' sid='*';                   /*這個值一定要和前面tnsnames.ora文件里的一樣*/

#(reset命令可以撤銷設(shè)置,恢復(fù)默認(rèn)值)                                          

系統(tǒng)已更改。

 show parameter remote_listener

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

remote_listener                      string      LISTENERS_RACDB                     /*可以看到剛才修改的已經(jīng)生效*/


    3、現(xiàn)在可以看下監(jiān)聽信息,正確配置參數(shù)后,通過lsnrctl status命令看到在監(jiān)聽啟動以后,可以看到監(jiān)聽器上有2個instance。

[grid@node01 bin]# lsnrctl status

 

LSNRCTL for Linux: Version 10.2.0.4.0 - Production on 18-DEC-2014 05:40:08

 

Copyright (c) 1991, 2005, Oracle.  All rights reserved.

 

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

STATUS of the LISTENER

------------------------

Alias                     LISTENER_NODE01

Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production

Start Date                18-DEC-2014 00:18:07

Uptime                    0 days 15 hr. 22 min. 1 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /orac/orahome/oracle/product/11.2.0/db_1/network/admin/listener.ora

Listener Log File         /orac/orahome/oracle/product/11.2.0/db_1/network/log/listener_node01.log

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.230.153)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.230.154)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.230.155)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))

Services Summary...

Service "+ASM" has 1 instance(s).

  Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service...

Service "+ASM_XPT" has 1 instance(s).

  Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service...

Service "RACDB" has 2 instance(s).

  Instance "RACDB1", status READY, has 2 handler(s) for this service...

  Instance "RACDB2", status READY, has 1 handler(s) for this service...

Service "RACDBXDB" has 2 instance(s).

  Instance "RACDB1", status READY, has 1 handler(s) for this service...

  Instance "RACDB2", status READY, has 1 handler(s) for this service...

Service "RACDB_XPT" has 2 instance(s).

  Instance "RACDB1", status READY, has 2 handler(s) for this service...

  Instance "RACDB2", status READY, has 1 handler(s) for this service...

The command completed successfully



二、客戶端配置   


 在每個客戶端或者JDBC的程序都用LOAD_BALANCE = yes的參數(shù)即可

                 客戶端的tnsnames.ora如下修改

                   

RAC_DB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.153)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.154)(PORT = 1521))
     (LOAD_BALANCE = yes)
      (FAILOVER = on)

    )
    (CONNECT_DATA =
      (SERVICE_NAME = RAC_DB)
     (FAILOVER_MODE = (TYPE = SELECT)
                       (METHOD = BASIC)
                       (RETRIES = 20)
                       (DELAY = 10)

      )
    )
  )

標(biāo)紅的這幾個參數(shù)代表意義:

LOAD_BALANCE=YES 表示的負(fù)載均衡,而且這個應(yīng)該是客戶端的負(fù)載均衡,就是隨機(jī)的進(jìn)行連接分配。


FAILOVER =ON 表示的是客戶端連接時的故障轉(zhuǎn)移。也就是說在建立會話的時候如果發(fā)現(xiàn)一個節(jié)點(diǎn)出現(xiàn)故障就去檢測另外的節(jié)點(diǎn)。默認(rèn)就是開啟的。但是現(xiàn)在ORACLE一般使用TAF,就是說即使在連接期間出現(xiàn)故障,也會轉(zhuǎn)移到其他節(jié)點(diǎn)繼續(xù)操作
failover_mode 有幾個參數(shù)TYPE MOTHOD RETRIES DELAY。
mothod 取值 basic preconnect(前者是在感知了錯誤才建立到其他節(jié)點(diǎn)的連接,后者是預(yù)先建立到其他節(jié)點(diǎn)的連接)
TYPE 取值 SELECT或 SESSION(前者在故障節(jié)點(diǎn)的查詢結(jié)果不會拋棄,在新節(jié)點(diǎn)繼續(xù)余下的操作,后者就是重新進(jìn)行操作,拋棄以前的操作)
retries就是重試次數(shù)
DELAY 重試間隔時間,也可以使用SERVICE來做服務(wù)端的 TAF。


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI