RAC_TNS故障轉移負載均衡、SCAN IP、VIP、PUBLIC IP

lusklusklusk發表於2017-08-30
不能透過lsnrctl來看scan的監聽,透過如下命令檢視scan監聽
[grid@node1 admin]$ srvctl config scan_listener
SCAN Listener LISTENER_SCAN1 exists. Port: TCP:1521
[grid@node1 admin]$ srvctl config scan
SCAN name: node-scan, Network: 1/192.168.92.0/255.255.255.0/eth0
SCAN VIP name: scan1, IP: /node-scan/192.168.92.99

RAC的tnsname.ora連線建議使用如下RACSCAN模式,當然RACVIP也可以
RACSCAN =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =SCAN-NAME)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

RACVIP =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =NODE1 VIP)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST =NODE2 VIP)(PORT = 1521))
    (LOAD_BALANCE = ON)
    (FAILOVER = ON)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )



問題1:SCAN IP只在一個節點,如果透過SCAN IP連線,那不是每次都連到SCAN IP所在的節點上了嗎?
答案:SCAN IP可以自動根據RAC負載把會話分到對應的節點,因為PMON程式可以定時把每個節點上的負載註冊到scan listener監聽器上。

問題2:配置了prefer和available的service時,如果發生prefer主伺服器當機,透過tns連線每次都要錯了一次再去找available備用伺服器嗎?
答案:如果配置了SCAN IP或VIP就不需要
    如果配置了Public IP且LOAD_BALANCE為no,且第一個IP是prefer主伺服器,那麼每次都要錯了一次再去找available備用伺服器


現象1:TNS裡面配置了FAILOVER、LOAD_BALANCE,但HOST是兩個節點的PUBLIC IP,宕掉一個節點,客戶端透過這個TNS連線,連線多次,每次連上後退出再連線,發現有一半左右的連線要過好長時間才連上,另一半的連線很快。

現象2:TNS裡面配置了FAILOVER、LOAD_BALANCE,但HOST是兩個節點的VIP,宕掉一個節點,客戶端透過這個TNS連線,連線多次,每次連上後退出再連線,發現每次連線都很快。



TNSNAME配置SCAN IP、VIP、PUBLIC IP的區別
SCAN IP是浮動的會落在某個節點上,有點類似VIP,不過SCAN IP與整個叢集相關聯,不僅僅是某單個節點,所有節點的所有服務包括VIP、PUBLIC IP都會註冊到整個叢集的scan_listener上,scan listener是知道每個節點的負載,SCAN IP是scan_listener的虛擬IP,srvctl config scan_listener只顯示埠資訊,IP資訊即SCAN IP會對映到所有節點的VIP、PUBLIC IP。

VIP也是浮動的會落在某個節點上,但是VIP只會註冊到對應節點的listener上,當節點當機之後,VIP會自動的漂移到正常節點上,但不會再註冊到正常節點的listener(即lsnrctl status看不到該VIP,該VIP不會出現在正常節點的監聽資訊中,該VIP雖然存在也可以連線但是無法對外服務了。),當客戶端透過這個VIP連線的時候,叢集馬上通知客戶端,該VIP對應監聽的節點已經當機了,客戶端會馬上使用另一個節點的VIP進行連線。

PUBLIC IP是固定的,只會註冊到對應節點的listener上,當節點當機之後,如果使用這個PUBLIC IP連線時,是到達不了叢集的,這個時候客戶端是靠“TCP/IP協議棧超時”來判斷伺服器故障,直到報time out,這個過程是非常耗時的。

所以:TNSNAME中不要配置PUBLIC IP,而是配置VIP,節點當機後,這個節點PUBLIC IP連線不上,但VIP可以連線並返回節點當機資訊,這樣客戶端可以很快知道節點掛了,較低消耗資源。


FAILOVER
Purpose:To enable or disable connect-time failover for multiple protocol addresses.
When you set the parameter to on, yes, or true, Oracle Net, at connect time, fails over to a different address if the first protocol address fails. When you set the parameter to off, no, or false, Oracle Net tries one protocol address.
故障切換
目的:啟用或禁用多個協議地址的連線時故障轉移。
當您將引數設定為on,yes或true時,如果第一個協議地址失敗,則Oracle Net在連線時將失敗到另一個地址。 當您將引數設定為off,no或false時,Oracle Net會嘗試一個協議地址。
這個引數應該預設是on,實驗過,如下tns配置後,把節點1關機,節點1的公共ip NODE1 PUBLIC_IP就不存在了,使用sqlplus連線這個tns的名稱時,還是可以連線上節點2
PUBLIC_NO_LOADBALANCE_FAILOVER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST =NODE1 PUBLIC_IP)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST =NODE2 PUBLIC_IP)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )


LOAD_BALANCE
Purpose:To enable or disable client load balancing for multiple protocol addresses.
When you set the parameter to on, yes, or true, Oracle Net progresses the list of addresses in a random sequence, balancing the load on the various listener or Oracle Connection Manager protocol addresses. When you set the parameter to off, no, or false, Oracle Net tries the first address in the address list. If the connection fails and the failover parameter is enabled, then Oracle Net tries the addresses sequentially until one succeeds.
負載均衡
目的:啟用或禁用多個協議地址的客戶端負載平衡。
當您將引數設定為on,yes或true時,Oracle Net會以隨機順序進行地址列表,平衡各種偵聽器或Oracle Connection Manager協議地址的負載。 將引數設定為off,no或false時,Oracle Net會嘗試地址列表中的第一個地址。 如果連線失敗並啟用了故障切換引數,則Oracle Net會依次嘗試地址,直到成功。

負載均衡:連線的時候,在資料庫的哪個節點上產生session。
  a、tnsnames.ora使用LOAD_BALANCE其實是客戶端的負載均衡。
     哪個節點上產生session其本質是伺服器端的負載均衡,因為客戶端並不知道伺服器端的哪個節點最空閒。
     如下從tnsnames.ora裡隨機選擇一個節點來連線。
     ERP=(DESCRIPTION=
           (LOAD_BALANCE=on)
           (ADDRESS=(PROTOCOL=TCP)(HOST=node-1vip)(PORT=1521))
           (ADDRESS=(PROTOCOL=TCP)(HOST=node-2vip)(PORT=1521))
           (ADDRESS=(PROTOCOL=TCP)(HOST=node-3vip)(PORT=1521))
           (CONNECT_DATA=(SERVICE_NAME=ERP)))
  b、tnsnames.ora使用的是scan name進行連線,則不存在客戶端的連線時的負載均衡。因為連線字串裡只有一個連線地址。
     如果使用的是SCAN name,則scan listener是知道每個節點的負載,這是才是真正的負載均衡
     所以可以把客戶端的連線重定向到最空閒的節點上。
     ERP=(DESCRIPTION=  ## Using the SCAN ##
           (LOAD_BALANCE=on)
           (ADDRESS=(PROTOCOL=TCP)(HOST=cluster-scan)(PORT=1521))
           (CONNECT_DATA=(SERVICE_NAME=ERP)))
  c、如果使用vip地址但是又想要實現服務端的負載均衡,那首先需要修改remote_listener指向所有的監聽器。
     修改兩個節點的tnsnames.ora,新增類似如下的資訊:
     all_listener =
        (DESCRIPTION =
         (ADDRESS = (PROTOCOL = TCP)(HOST = node2-vip)(PORT = 1521))
         (ADDRESS = (PROTOCOL = TCP)(HOST = node1-vip)(PORT = 1521))
        )
     alter system set remote_listener='all_listener';
     這樣pmon程式可以定時把每個節點上的workload註冊到所有節點的監聽器上。




About the SCAN
Oracle Database 11g release 2 clients connect to the database using SCANs. The SCAN and its associated IP addresses provide a stable name for clients to use for connections, independent of the nodes that make up the cluster. SCAN addresses, virtual IP addresses, and public IP addresses must all be on the same subnet.
The SCAN is a virtual IP name, similar to the names used for virtual IP addresses, such as node1-vip. However, unlike a virtual IP, the SCAN is associated with the entire cluster, rather than an individual node, and associated with multiple IP addresses, not just one address.
The SCAN works by being able to resolve to multiple IP addresses in the cluster handling public client connections. When a client submits a request, the SCAN listener listening on a SCAN IP address and the SCAN port is made available to a client. Because all services on the cluster are registered with the SCAN listener, the SCAN listener replies with the address of the local listener on the least-loaded node where the service is currently being offered. Finally, the client establishes connection to the service through the listener on the node where service is offered. All of these actions take place transparently to the client without any explicit configuration required in the client.
During installation listeners are created. They listen on the SCAN IP addresses provided on nodes for the SCAN IP addresses. Oracle Net Services routes application requests to the least loaded instance providing the service. Because the SCAN addresses resolve to the cluster, rather than to a node address in the cluster, nodes can be added to or removed from the cluster without affecting the SCAN address configuration.
The SCAN should be configured so that it is resolvable either by using Grid Naming Service (GNS) within the cluster, or by using Domain Name Service (DNS) resolution. For high availability and scalability, Oracle recommends that you configure the SCAN name so that it resolves to three IP addresses. At a minimum, the SCAN must resolve to at least one address.
If you specify a GNS domain, then the SCAN name defaults to clustername-scan.GNS_domain. Otherwise, it defaults to clustername-scan.current_domain. For example, if you start Oracle Grid Infrastructure installation from the server node1, the cluster name is mycluster, and the GNS domain is grid.example.com, then the SCAN Name is mycluster-scan.grid.example.com.
Clients configured to use IP addresses for Oracle Database releases prior to Oracle Database 11g release 2 can continue to use their existing connection addresses; using SCANs is not required. When you upgrade to Oracle Clusterware 11g Release 2 (11.2), the SCAN becomes available, and you should use the SCAN for connections to Oracle Database 11g release 2 or later databases. When an earlier version of Oracle Database is upgraded, it registers with the SCAN listeners, and clients can start using the SCAN to connect to that database. The database registers with the SCAN listener through the remote listener parameter in the init.ora file. The REMOTE_LISTENER parameter must be set to SCAN:PORT. Do not set it to a TNSNAMES alias with a single address with the SCAN as HOST=SCAN.
The SCAN is optional for most deployments. However, clients using Oracle Database 11g release 2 and later policy-managed databases using server pools should access the database using the SCAN. This is because policy-managed databases can run on different servers at different times, so connecting to a particular node virtual IP address for a policy-managed database is not possible.
關於SCAN
Oracle資料庫11g版本2客戶端使用SCAN連線到資料庫。 SCAN及其關聯的IP地址為客戶端提供了一個穩定的名稱,用於連線,獨立於構成叢集的節點。 SCAN地址,虛擬IP地址和公共IP地址都必須在同一個子網上。
SCAN是一個虛擬IP名稱,類似於虛擬IP地址的名稱,如node1-vip。 然而,與虛擬IP不同,SCAN與整個叢集相關聯,而不是單個節點,並且與多個IP地址相關聯,而不僅僅是一個地址。
SCAN透過能夠解決群集中處理公共客戶端連線的多個IP地址而起作用。 當客戶端提交請求時,偵聽SCAN IP地址和SCAN埠的SCAN偵聽器可用於客戶端。 因為群集上的所有服務都已向SCAN偵聽器註冊,所以SCAN偵聽器將回復當前提供服務的最小負載節點上的本地偵聽器的地址。 最後,客戶端透過在提供服務的節點上的監聽器建立與服務的連線。 所有這些操作都對客戶端透明地進行,而客戶端中不需要任何明確的配置。
在安裝期間建立監聽器。 他們監聽節點上提供的SCAN IP。 Oracle Net Services將應用程式請求路由到提供服務的最小負載例項。 由於SCAN地址解析到叢集,而不是群集中的節點地址,因此節點可以新增到叢集中或從群集中刪除,而不影響SCAN地址配置。
應該配置SCAN,以使其可以透過使用群集中的網格命名服務(GNS)或透過使用域名服務(DNS)解析來解析。 為了實現高可用性和可擴充套件性,Oracle建議您配置SCAN名稱,以便它解析為三個IP地址。 至少,SCAN必須至少解決一個地址。
如果指定了GNS域,則SCAN名稱預設為clustername-scan.GNS_domain。 否則,它預設為clustername-scan.current_domain。 例如,如果從伺服器node1啟動Oracle Grid Infrastructure安裝,則叢集名稱為mycluster,並且GNS域為grid.example.com,則SCAN名稱為mycluster-scan.grid.example.com。
配置為在Oracle Database 11g版本2之前使用Oracle資料庫版本的IP地址的客戶端可以繼續使用其現有的連線地址; 不需要使用SCAN。 升級到Oracle Clusterware 11g第2版(11.2)時,SCAN變為可用,您應該使用SCAN連線到Oracle Database 11g第2版或更高版本的資料庫。 當Oracle資料庫的早期版本升級時,它會向SCAN監聽器註冊,客戶端可以開始使用SCAN連線到該資料庫。 資料庫透過init.ora檔案中的遠端偵聽器引數與SCAN偵聽器註冊。
REMOTE_LISTENER引數必須設定為SCAN:PORT。 不要將其設定為具有SCAN的單個地址的TNSNAMES別名作為HOST = SCAN。
對於大多數部署,SCAN是可選的。 但是,使用Oracle Database 11g版本2及更高版本的策略管理的資料庫使用伺服器池的客戶端應使用SCAN訪問資料庫。 這是因為策略管理的資料庫可以在不同的時間在不同的伺服器上執行,因此連線到策略管理資料庫的特定節點虛擬IP地址是不可能的。




Understanding SCAN Addresses and Client Service Connections
Public network addresses are used to provide services to clients. If your clients are connecting to the Single Client Access Name (SCAN) addresses, then you may need to change public and virtual IP addresses as you add or remove nodes from the cluster, but you do not need to update clients with new cluster addresses.
SCANs function like a cluster alias. However, SCANs are resolved on any node in the cluster, so unlike a VIP address for a node, clients connecting to the SCAN no longer require updated VIP addresses as nodes are added to or removed from the cluster. Because the SCAN addresses resolve to the cluster, rather than to a node address in the cluster, nodes can be added to or removed from the cluster without affecting the SCAN address configuration.
The SCAN is a fully qualified name (host name+domain) that is configured to resolve to all the addresses allocated for the SCAN. The addresses resolve using Round Robin DNS either on the DNS server, or within the cluster in a GNS configuration. SCAN listeners can run on any node in the cluster. SCANs provide location independence for the databases, so that client configuration does not have to depend on which nodes run a particular database.
Oracle Database 11g release 2 (11.2) and later instances only register with SCAN listeners as remote listeners. Upgraded databases register with SCAN listeners as remote listeners, and also continue to register with all node listeners.
Because of the Oracle Clusterware installation requirement that you provide a SCAN name during installation, if you resolved at least one IP address using the server /etc/hosts file to bypass the installation requirement but you do not have the infrastructure required for SCAN, then, after the installation, you can ignore the SCAN and connect to the databases in the cluster using VIPs.
Oracle does not support removing the SCAN address.
瞭解SCAN地址和客戶端服務連線
公共網路地址用於向客戶端提供服務。 如果您的客戶端連線到單個客戶端訪問名稱(SCAN)地址,則可能需要在從群集新增或刪除節點時更改公共和虛擬IP地址,但不需要使用新的群集地址更新客戶端。
SCANs功能像叢集別名一樣。 但是,在叢集中的任何節點上都會解析SCAN,因此與節點的VIP地址不同,連線到SCAN的客戶端不再需要更新的VIP地址,因為節點被新增到叢集或從叢集中刪除。 由於SCAN地址解析到叢集,而不是群集中的節點地址,因此節點可以新增到叢集中或從群集中刪除,而不影響SCAN地址配置。
SCAN是一個完全限定名稱(主機名+域),配置為解析為SCAN分配的所有地址。 這些地址使用DNS或GNS解析。 SCAN偵聽器可以在群集中的任何節點上執行。 SCAN為資料庫提供位置獨立性,因此客戶機配置不必依賴於執行特定資料庫的節點。
Oracle Database 11g第2版(11.2)和更高版本的例項只將SCAN偵聽器註冊為遠端偵聽器。 升級資料庫將SCAN偵聽器註冊為遠端監聽器,並繼續向所有節點偵聽器註冊。
由於Oracle Clusterware安裝要求,您在安裝期間提供SCAN名稱,如果您使用伺服器/etc/hosts檔案解決了至少一個IP地址以繞過安裝要求,但是沒有SCAN需要的基礎架構,那麼,安裝後,您可以忽略SCAN並使用VIP連線到群集中的資料庫。Oracle不支援刪除SCAN地址。



About the Virtual IP Address
The virtual IP (VIP) address is registered in the GNS, or the DNS. Select an address for your VIP that meets the following requirements:
The IP address and host name are currently unused (it can be registered in a DNS, but should not be accessible by a ping command)
The VIP is on the same subnet as your public interface
D.1.3.4 About the Grid Naming Service (GNS) Virtual IP Address
The GNS virtual IP address is a static IP address configured in the DNS. The DNS delegates queries to the GNS virtual IP address, and the GNS daemon responds to incoming name resolution requests at that address.
Within the subdomain, the GNS uses multicast Domain Name Service (mDNS), included with Oracle Clusterware, to enable the cluster to map host names and IP addresses dynamically as nodes are added and removed from the cluster, without requiring additional host configuration in the DNS.
關於虛擬IP地址
虛擬IP(VIP)地址註冊在GNS或DNS中。 選擇符合以下要求的VIP地址:
IP地址和主機名當前未使用(可以在DNS中註冊,但不能透過ping命令訪問)
VIP與您的PUBLIC IP介面在同一個子網上
D.1.3.4關於網格命名服務(GNS)虛擬IP地址
GNS虛擬IP地址是DNS中配置的靜態IP地址。 DNS將對GNS虛擬IP地址的查詢委託給GNS,並且GNS守護程式響應該地址處的傳入名稱解析請求。
在子域內,GNS使用Oracle Clusterware附帶的多播域名服務(mDNS),使群集能夠動態地對映主機名和IP地址,而不需要在群集中新增和刪除節點,而不需要DNS中的其他主機配置。

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

相關文章