RAC_TNS故障转移负载均衡、SCANIP、VIP、PUBLICIP

不能通过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中的其他主机配置。

当前文章:RAC_TNS故障转移负载均衡、SCANIP、VIP、PUBLICIP
文章地址:http://myzitong.com/article/iejhji.html