正德厚生,臻于至善

SCAN,VIP,Local Listener,Remote Listener之间的关系

11gRAC中有3种IP类型,分别为public IP,private IP和Virtual VIP。HAIP属于Private IP,SCAN IP属于Virtual IP.

Public IP

The public IP address is for the server.It’s the same as any server IP address,a unique address with exists in /etc/hosts

这个是真实的IP地址,称为公共网络(Public IP)。配置TNS时一般不用Public IP,选择用VIP。因为用Public IP是,如果当一个节点有故障时,向她请求的客户端都会有等待,需要等到TCP超时,最长可达10分钟才会提示错误。这不是高可用性最佳实践。

Private IP

Oracle RCA requires “private IP” addresses to manage the CRS, the clusterware heartbeat process and the cache fusion layer.

这个也是真实的IP地址,称为私有网络(Private Ip),主要用于心跳同步和Cache Fusion。私有网络之间通信故障时,会出现脑裂现象(brain split)。在11.2.0.2引入了HAIP,即私有网络的高可用性。类似于Linux上网卡Bonding技术和AIX上etherchannel技术。使用多个私有网络连接来一方面满足网卡间的负载均衡,另一方面还能提高Cache Fusion资源传送能力。

HAIP

Highly Available IP.It’s was introduced on Oracle Grid Infrastructure 11.2.0.2,HAIP allows for redundant cluster interconnect NICs on cluster nodes without requiring any OS level bonding, teaming or aggregating of the NICs.

Use the OS command “ifconfig -a”. Look in the ASM and RDBMS instance alert logs. During instance startup the interfaces and associated HAIP will be shown.
HAIP属于Private IP,在11.2.0.2引入了HAIP概念,是私有网络的冗余。可以用ifconfig -a来查看,从ASM和RDBMS的alet日志中也可以看到

alert_pgold.log
Private Interface ‘eth1:1′ configured from GPnP for use as a private interconnect.
[name=’eth1:1’, type=1, ip=169.254.67.247, mac=00-0c-28-36-c3-60, net=169.254.0.0/17, mask=255.255.128.0, use=haip:cluster_interconnect/62]
Private Interface ‘eth2:1′ configured from GPnP for use as a private interconnect.
[name=’eth2:1’, type=1, ip=169.254.178.243, mac=00-0c-28-36-c3-6a, net=169.254.128.0/17, mask=255.255.128.0, use=haip:cluster_interconnect/62]

ifconfig -a
eth1      Link encap:Ethernet  HWaddr 00:0C:28:36:C3:60
inet addr:192.168.0.101  Bcast:192.168.0.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe36:c380/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:102093 errors:0 dropped:0 overruns:0 frame:0
TX packets:103575 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:48494112 (46.2 MiB)  TX bytes:63337730 (60.4 MiB)
Interrupt:75 Base address:0x24a4

eth1:1    Link encap:Ethernet  HWaddr00:0C:28:36:C3:60
inet addr:169.254.67.247  Bcast:169.254.127.255  Mask:255.255.128.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
Interrupt:75 Base address:0x24a4

eth2      Link encap:Ethernet  HWaddr 00:0C:28:36:C3:6A
inet addr:192.168.0.103  Bcast:192.168.0.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe36:c38a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:77472 errors:0 dropped:0 overruns:0 frame:0
TX packets:75498 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:39169420 (37.3 MiB)  TX bytes:43387409 (41.3 MiB)
Interrupt:51 Base address:0x2824

eth2:1    Link encap:Ethernet  HWaddr 00:0C:28:36:C3:6A
inet addr:169.254.178.243  Bcast:169.254.255.255  Mask:255.255.128.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
Interrupt:51 Base address:0x2824

Virtual IP

Oracle uses a Virtual IP (VIP) for database access.The VIP must be on the same subnet as the public IP address.The VIP is used for RAC failover (TAF).

每个Public IP对应一个VIP,她和PUBLIC IP属于同一个子网段,由CRS来管理。VIP所在节点服务器发生故障的时,会自动漂移到其它正常的节点服务器,当RAC节点大于2个,Failover到哪个节点有CRS决定。FailOver之后LOCAL LISTENER是不能也不在处理客户端的请求,当有客户端向这个VIP发送请求时,CRS会让其连接其它VIP。待故障解决后,节点恢复正常工作,VIP会重新回到此节点上,继续为大家提供服务。

VIP作为Nodeapps类型的CRS Resource注册到OCR中,并由CRS维护
VIP(包括scan ip)会绑定到节点的Public网卡上
当某个节点发生故障时,CRS会把故障节点的VIP转移到其他节点上
每个节点的Listener会同时监听public网卡上的Public IP和VIP
配置客户端的tnsnames.Ora一般指向节点的VIP

SCAN VIP

也是我们常说的SCAN IP,也是虚拟的IP地址,和Public IP属于同一个网段。可以通过也DNS、GNS、hosts文件三种方式来实现。使用hosts文件解析时最多有且只有一个SCAN VIP,采用DNS/GNS时,SCAN VIP最多能有三个。SCAN VIP数量和节点数是没有直接的关系,所以当只有2个节点时,1个节点上会有2个SCAN VIP,另外一个节点有一个。当节点数为4个时,其中3个节点上各有一个,如果有一个SCAN VIP的节点出故障时,会切换到另一节点,还有一点SCAN VIP会落到哪个节点上都是随机的。

SCAN IP其实是Oracle在客户端与数据库之间,新加的一个连接层,当有客户端访问时连接到SCAN IP Listener。而SCAN IP Listener接收到连接请求时,会根据 LBA(Load Balancing Advisory) 算法(所谓LBA算法,就是Least Loaded Instance),将该客户端的连接请求,转发给对应的Instance上的VIP Listener,从而完成了整个客户端与服务器的连接过程。简化如下:

Client -> Scan listener -> Local listener -> Local instance

SCAN的概念

A. Single client access name (SCAN) is the virtual hostname to provide for all clients connecting to the cluster (as opposed to the vip hostnames in 10g and 11gR1).

SCAN是虚拟的主机名字,用于客户端连接数据库时使用

B. SCAN is a domain name registered to at least one and up to three IP addresses, either in the domain name service (DNS) or the Grid Naming Service (GNS).

SCAN可以注册最少一个,最多3个IP地址如果采用DNS或者GNS服务

C. By default, the name used as the SCAN is also the name of the cluster and must be globally unique throughout your enterprise. The default value for the SCAN is based on the local node name. SCAN name must be at least one character long and no more than 15 characters in length, must be alphanumeric – cannot begin with a numeral and may contain hyphens (-). If you require a SCAN that is longer than 15 characters, then select an Advanced installation.

默认情况下SCAN的名字会使用集群的名字,最少一个字符最多15个字符,开始的字符不能为数字,可以包含-。如果SCAN名字长度大于15,安装是请选择高级安装。

D. For installation to succeed, the SCAN must resolve to at least one address.

为了能够安装成功,SCAN至少能解析一个地址,就是采用hosts文件的方式解析

E. SCAN VIP addresses must be on the same subnet as virtual IP addresses and public IP addresses.

SCAN VIP的地址必须和VIP,PUBLIC IP属于同一网段。

F. Oracle strongly recommends that you do not configure SCAN VIP addresses in the hosts file. But if you use the hosts file to resolve SCAN name, you can have only one SCAN IP address.

Oracle强烈建议不用使用hosts文件配置SCAN VIP。因为如果使用hosts文件,只能有一个SCAN IP地址

G. If hosts file is used to resolve SCAN hostname, you will receive Cluster Verification Utility failure at end of installation (see Note: 887471.1 for more details)

如果使用hosts文件解析SCAN主机名,在安装最后会收到验证是会失败,详情请见887471.1

H. For high availability and scalability, Oracle recommends that you configure the SCAN to use DNS Round Robin resolution to three addresses.

为了高可用性和稳定性,Orace建议对3个IP地址使用round-robin方式

I. Because the SCAN is associated with the cluster as a whole, rather than to a particular node, the SCAN makes it possible to add or remove nodes from the cluster

SCAN是针对整个集群而言的,不是特定的某个节点。所以当添加或移除节点时不会收到影响。

J. without needing to reconfigure clients. It also adds location independence for the databases, so that client configuration does not have to depend on which nodes are running a particular database.

客户端不需要重新配置

K. Clients can continue to access the cluster in the same way as with previous releases, but Oracle recommends that clients accessing the cluster use the SCAN. Clients using the SCAN can also access the cluster using EZCONNECT.

客户端可以继续使用之前版本的连接方式连接数据库,Oracle建议使用SCAN,也可以使用EZCONNECT

L. Grid Infrastructure will start local listener LISTENER on all nodes to listen on local VIP, and SCAN listener LISTENER_SCAN1 (up to three cluster wide) to listen on SCAN VIP(s); 11gR2 database by default will set local_listener to local LISTENER, and remote_listener to SCAN listener.

GI会启动每个节点的Local listener去监听Local VIP和SCAN Listener去监听SCAN VIP。11gR2默认会设置local_listener为本地监听,remote_listener为SCAN监听

M. SCAN listener will be running off GRID_HOME, and by default, in 11gR2 local listener will be running off GRID_HOME as well.

Local listenerSCAN listener从GRID_HOME启动。

Local Listener
即单节点/RAC的本地监听器。如果是RAC节点,她会监听该节点的PUBLIC IP和VIP,实例在启动的时候会向本地监听器进行注册,也会向SCAN监听器注册(限于11gR2以上版本)。如果RAC中某个节点发生故障,该节点的VIP会漂移到其它节点。安装后默认的本地监听端口为1521。注意本地监听器不会发生漂移。

[orgrid@ohs1 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 07-MAY-2016 19:44:15
Copyright (c) 1991, 2011, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                07-MAY-2016 19:40:22
Uptime                    0 days 0 hr. 3 min. 54 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /orgrid/oracle/product/112/network/admin/listener.ora
Listener Log File         /orgrid/grid_base/diag/tnslsnr/ohs1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.101)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.103)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "pgold" has 1 instance(s).
  Instance "pgold1", status READY, has 1 handler(s) for this service...
Service "pgoldXDB" has 1 instance(s).
  Instance "pgold1", status READY, has 1 handler(s) for this service...
The command completed successfully
[orgrid@ohs1 ~]$

SCAN Listener
SCAN监听器和本地监听器的个数依赖于SCAN VIP的个数,用hosts文件解析,SCAN监听器有一个,用DNS/GNSN监听器最多有三个。
SCAN监听器和本地监听器基本上一样,都是从GI_HOME启动,安装时可以指定SCAN的端口(本次测试中指定的端口为10010,当然也可以使用端口1521)。
SCAN监听器通过remote_listener(本文后面会做说明)将不同节点的实例信息注册过来。当用SCAN IP连接时,就可根据实例负载的信息,连接不同的节点。
[orgrid@ohs1 ~]$ srvctl config scan

SCAN name: cluster01-scan, Network: 1/172.0.2.0/255.255.255.0/eth0
SCAN VIP name: scan1, IP: /cluster01-scan/172.0.2.111
SCAN VIP name: scan2, IP: /cluster01-scan/172.0.2.112
SCAN VIP name: scan3, IP: /cluster01-scan/172.0.2.113

[orgrid@ohs1 ~]$ srvctl config scan_listener

SCAN Listener LISTENER_SCAN1 exists. Port: TCP:10010
SCAN Listener LISTENER_SCAN2 exists. Port: TCP:10010
SCAN Listener LISTENER_SCAN3 exists. Port: TCP:10010

[orgrid@ohs1 ~]$ srvctl config listener

Name: LISTENER
Network: 1, Owner: oracle
Home: <CRS home>
End points: TCP:1521
[orgrid@ohs1 ~]$

[orgrid@ohs1 ~]$ ps -ef|grep tns

orgrid    6451     1  0 19:40 ?        00:00:00 /orgrid/oracle/product/112/bin/tnslsnr LISTENER_SCAN2 -inherit
orgrid    6455     1  0 19:40 ?        00:00:00 /orgrid/oracle/product/112/bin/tnslsnr LISTENER_SCAN3 -inherit
orgrid    6457     1  0 19:40 ?        00:00:00 /orgrid/oracle/product/112/bin/tnslsnr LISTENER -inherit
orgrid    9566  7642  0 20:14 pts/1    00:00:00 grep tns

[orgrid@ohs1 ~]$

[orgrid@ohs2 ~]$ ps -ef|grep tns

orgrid    6543     1  0 19:48 ?        00:00:00 /orgrid/oracle/product/112/bin/tnslsnr LISTENER -inherit
orgrid    6569     1  0 19:48 ?        00:00:00 /orgrid/oracle/product/112/bin/tnslsnr LISTENER_SCAN1 -inherit
orgrid    8449  6752  0 20:15 pts/1    00:00:00 grep tns

[orgrid@ohs2 ~]$

[orgrid@ohs1 ~]$ lsnrctl status listener_scan2

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 07-MAY-2016 20:33:07
Copyright (c) 1991, 2011, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN2)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER_SCAN2
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                07-MAY-2016 19:40:22
Uptime                    0 days 0 hr. 52 min. 45 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /orgrid/oracle/product/112/network/admin/listener.ora
Listener Log File         /orgrid/oracle/product/112/log/diag/tnslsnr/ohs1/listener_scan2/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN2)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.112)(PORT=10010)))
Services Summary...
Service "pgold" has 2 instance(s).
  Instance "pgold1", status READY, has 1 handler(s) for this service...
  Instance "pgold2", status READY, has 1 handler(s) for this service...
Service "pgoldXDB" has 2 instance(s).
  Instance "pgold1", status READY, has 1 handler(s) for this service...
  Instance "pgold2", status READY, has 1 handler(s) for this service...
The command completed successfully

[orgrid@ohs1 ~]$ lsnrctl status listener_scan3

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 07-MAY-2016 20:33:08
Copyright (c) 1991, 2011, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN3)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER_SCAN3
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                07-MAY-2016 19:40:22
Uptime                    0 days 0 hr. 52 min. 47 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /orgrid/oracle/product/112/network/admin/listener.ora
Listener Log File         /orgrid/oracle/product/112/log/diag/tnslsnr/ohs1/listener_scan3/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN3)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.113)(PORT=10010)))
Services Summary...
Service "pgold" has 2 instance(s).
  Instance "pgold1", status READY, has 1 handler(s) for this service...
  Instance "pgold2", status READY, has 1 handler(s) for this service...
Service "pgoldXDB" has 2 instance(s).
  Instance "pgold1", status READY, has 1 handler(s) for this service...
  Instance "pgold2", status READY, has 1 handler(s) for this service...
The command completed successfully

[orgrid@ohs2 ~]$ lsnrctl status listener_scan1

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 07-MAY-2016 20:31:24
Copyright (c) 1991, 2011, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER_SCAN1
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                07-MAY-2016 19:48:48
Uptime                    0 days 0 hr. 42 min. 35 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /orgrid/oracle/product/112/network/admin/listener.ora
Listener Log File         /orgrid/oracle/product/112/log/diag/tnslsnr/ohs2/listener_scan1/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.111)(PORT=10010)))
Services Summary...
Service "pgold" has 2 instance(s).
  Instance "pgold1", status READY, has 1 handler(s) for this service...
  Instance "pgold2", status READY, has 1 handler(s) for this service...
Service "pgoldXDB" has 2 instance(s).
  Instance "pgold1", status READY, has 1 handler(s) for this service...
  Instance "pgold2", status READY, has 1 handler(s) for this service...
The command completed successfully
[orgrid@ohs2 ~]$

SCAN监听器和SCAN VIP随机分配到不同的节点服务器,她们2个就像好朋友一样,形影不离。如果某一节点发生故障,运行在此节点上的SCAN VIP和SCAN监听器会漂移到正常的节点上(本地监听器不会漂移),继续为SCAN VIP监听连接请求服务,PMON进程会更新实例信息到SCAN监听器。以下为测试,关闭节点一,在节点二上查看SCAN,VIP信息

关闭节点一

[root@ohs1 ~]# /orgrid/oracle/product/112/bin/crsctl stop crs

CRS-2677: Stop of 'ora.LISTENER.lsnr' on 'ohs1' succeeded
CRS-2673: Attempting to stop 'ora.ohs1.vip' on 'ohs1'
CRS-2677: Stop of 'ora.LISTENER_SCAN2.lsnr' on 'ohs1' succeeded
CRS-2673: Attempting to stop 'ora.scan2.vip' on 'ohs1'
CRS-2677: Stop of 'ora.LISTENER_SCAN3.lsnr' on 'ohs1' succeeded
CRS-2673: Attempting to stop 'ora.scan3.vip' on 'ohs1'
CRS-2677: Stop of 'ora.ohs1.vip' on 'ohs1' succeeded
CRS-2672: Attempting to start 'ora.ohs1.vip' on 'ohs2'
CRS-2677: Stop of 'ora.scan2.vip' on 'ohs1' succeeded
CRS-2672: Attempting to start 'ora.scan2.vip' on 'ohs2'
CRS-2677: Stop of 'ora.scan3.vip' on 'ohs1' succeeded
CRS-2672: Attempting to start 'ora.scan3.vip' on 'ohs2'
CRS-2676: Start of 'ora.ohs1.vip' on 'ohs2' succeeded
CRS-2676: Start of 'ora.scan2.vip' on 'ohs2' succeeded
CRS-2676: Start of 'ora.scan3.vip' on 'ohs2' succeeded
CRS-2672: Attempting to start 'ora.LISTENER_SCAN2.lsnr' on 'ohs2'
CRS-2672: Attempting to start 'ora.LISTENER_SCAN3.lsnr' on 'ohs2'
CRS-2677: Stop of 'ora.registry.acfs' on 'ohs1' succeeded
CRS-2676: Start of 'ora.LISTENER_SCAN3.lsnr' on 'ohs2' succeeded
CRS-2676: Start of 'ora.LISTENER_SCAN2.lsnr' on 'ohs2' succeeded

节点二上查看VIP和SCAN信息

[orgird@ohs2 ~]$ crsctl stat res -t

--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA_PGOLD.dg
               ONLINE  ONLINE       ohs2                                         
ora.LISTENER.lsnr
               ONLINE  ONLINE       ohs2                                         
ora.SYSTEMDG.dg
               ONLINE  ONLINE       ohs2                                         
ora.asm
               ONLINE  ONLINE       ohs2                     Started             
ora.gsd
               OFFLINE OFFLINE      ohs2                                         
ora.net1.network
               ONLINE  ONLINE       ohs2                                         
ora.ons
               ONLINE  ONLINE       ohs2                                         
ora.registry.acfs
               ONLINE  ONLINE       ohs2                                         
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       ohs2                                         
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       ohs2                                         
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       ohs2                                         
ora.cvu
      1        ONLINE  ONLINE       ohs2                                         
ora.oc4j
      1        ONLINE  ONLINE       ohs2                                         
ora.ohs1.vip
      1        ONLINE  INTERMEDIATE ohs2                     FAILED OVER         
ora.ohs2.vip
      1        ONLINE  ONLINE       ohs2                                         
ora.pgold.db
      1        ONLINE  OFFLINE                                                   
      2        ONLINE  ONLINE       ohs2                     Open                
ora.scan1.vip
      1        ONLINE  ONLINE       ohs2                                         
ora.scan2.vip
      1        ONLINE  ONLINE       ohs2                                         
ora.scan3.vip
      1        ONLINE  ONLINE       ohs2                                         
[orgird@ohs2 ~]$

[orgrid@ohs2 ~]$ lsnrctl status listener_scan1

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 07-MAY-2016 21:01:41

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER_SCAN1
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                07-MAY-2016 19:48:48
Uptime                    0 days 1 hr. 12 min. 52 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /orgrid/oracle/product/112/network/admin/listener.ora
Listener Log File         /orgrid/oracle/product/112/log/diag/tnslsnr/ohs2/listener_scan1/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.111)(PORT=10010)))
Services Summary...
Service "pgold" has 1 instance(s).
  Instance "pgold2", status READY, has 1 handler(s) for this service...
Service "pgoldXDB" has 1 instance(s).
  Instance "pgold2", status READY, has 1 handler(s) for this service...
The command completed successfully

[orgrid@ohs2 ~]$ lsnrctl status listener_scan2

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 07-MAY-2016 21:01:47

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN2)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER_SCAN2
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                07-MAY-2016 20:50:13
Uptime                    0 days 0 hr. 11 min. 34 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /orgrid/oracle/product/112/network/admin/listener.ora
Listener Log File         /orgrid/oracle/product/112/log/diag/tnslsnr/ohs2/listener_scan2/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN2)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.112)(PORT=10010)))
Services Summary...
Service "pgold" has 1 instance(s).
  Instance "pgold2", status READY, has 1 handler(s) for this service...
Service "pgoldXDB" has 1 instance(s).
  Instance "pgold2", status READY, has 1 handler(s) for this service...
The command completed successfully

[orgrid@ohs2 ~]$ lsnrctl status listener_scan3

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 07-MAY-2016 21:01:48

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN3)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER_SCAN3
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                07-MAY-2016 20:50:13
Uptime                    0 days 0 hr. 11 min. 35 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /orgrid/oracle/product/112/network/admin/listener.ora
Listener Log File         /orgrid/oracle/product/112/log/diag/tnslsnr/ohs2/listener_scan3/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN3)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.0.2.113)(PORT=10010)))
Services Summary...
Service "pgold" has 1 instance(s).
  Instance "pgold2", status READY, has 1 handler(s) for this service...
Service "pgoldXDB" has 1 instance(s).
  Instance "pgold2", status READY, has 1 handler(s) for this service...
The command completed successfully
[orgrid@ohs2 ~]$

[orgrid@ohs2 ~]$ ps -ef|grep tns

orgrid    6543     1  0 19:48 ?        00:00:00 /orgrid/oracle/product/112/bin/tnslsnr LISTENER -inherit
orgrid    6569     1  0 19:48 ?        00:00:00 /orgrid/oracle/product/112/bin/tnslsnr LISTENER_SCAN1 -inherit
orgrid   10752     1  0 20:50 ?        00:00:00 /orgrid/oracle/product/112/bin/tnslsnr LISTENER_SCAN2 -inherit
orgrid   10754     1  0 20:50 ?        00:00:00 /orgrid/oracle/product/112/bin/tnslsnr LISTENER_SCAN3 -inherit
orgrid   12448  6752  0 21:03 pts/1    00:00:00 grep tns

[orgrid@ohs2 ~]$

监听器工作流程

The basic steps by which a client establishes a connection through a listener are:
1. A client process or another database requests a connection.
2. The listener selects an appropriate service handler to service the client request and forwards the request to the handler.
3. The client process connects directly to the service handler. The listener is no longer involved in the communication.

SQL> show parameter listener

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
listener_networks                    string
local_listener                       string      (DESCRIPTION=(ADDRESS_LIST=(AD
                                                 DRESS=(PROTOCOL=TCP)(HOST=172.
                                                 0.2.104)(PORT=1521))))
remote_listener                      string      cluster01-scan:10010
SQL>

初始化参数LOCAL_LISTENER
LOCAL_LISTENER specifies a network name that resolves to an address or address list of Oracle Net local listeners (that is, listeners that are running on the same machine as this instance). The address or address list is specified in the TNSNAMES.ORA file or other address repository as configured for your system.

By default, the PMON process registers service information with its local listener on the default local address of TCP/IP, port 1521. If the listener configuration is synchronized with the database configuration, then PMON can register service information with a nondefault local listener or a remote listener on another node. Synchronization occurs when the protocol address of the listener is specified in the listener.ora file and the location of the listener is specified in the initialization parameter file.

To have PMON register with a local listener that does not use TCP/IP, port 1521, configure the LOCAL_LISTENER parameter in the initialization parameter file to locate the local listener.

初始化参数REMOTE_LISTENER
REMOTE_LISTENER specifies a network name that resolves to an address or address list of Oracle Net remote listeners (that is, listeners that are not running on the same machine as this instance). The address or address list is specified in the TNSNAMES.ORA file or other address repository as configured for your system.

A remote listener is a listener residing on one computer that redirects connections to a database instance on another computer. Remote listeners are typically used in an Oracle Real Application Clusters (Oracle RAC) environment. You can configure registration to remote listeners, such as with Oracle RAC, for dedicated or shared server environments.

详情参考

http://docs.oracle.com/cd/E11882_01/network.112/e41945/listenercfg.htm#NETAG302

remote_listener实际上起到一个重定向的功能,她必须和本地监听一起才能正常工作。为了更好的说明,做了一下测试。有2台服务器,第一台服务器机器名db1(数据库upgr运行在这台服务器上),另外一台服务器机器名ora10(只启动了监听)。在db1上配置remote_listener,通过remote_listener连接到db1上数据库。

db1上数据库listener信息

[oracle@db1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sat May 7 22:01:07 2016
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, Data Mining and Real Application Testing options

SQL> show parameter listener

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
listener_networks             string
local_listener                string     (ADDRESS=(PROTOCOL=TCP)(HOST=db1)(PORT=1521))
remote_listener              string     upgr
SQL>

db1上tnsnames.ora内容

[oracle@db1 admin]$ cat tnsnames.ora
upgr =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ora10)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME=upgr)
    )
  )
[oracle@db1 admin]$
[oracle@db1 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-MAY-2016 22:04:04

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

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused
[oracle@db1 admin]$

启动ora10上监听

[oracle@ora10 ~]$ ps -ef|grep pmon
oracle    4479  4191  0 07:05 pts/1    00:00:00 grep pmon
[oracle@ora10 ~]$ lsnrctl status

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 07-MAY-2016 07:05:09

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

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-12541: TNS:no listener
 TNS-12560: TNS:protocol adapter error
  TNS-00511: No listener
   Linux Error: 111: Connection refused
[oracle@ora10 ~]$ lsnrctl start

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 07-MAY-2016 07:05:14

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

Starting /u01/oracle/product/102/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Log messages written to /u01/oracle/product/102/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora10)(PORT=1521)))

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date                07-MAY-2016 07:05:14
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         /u01/oracle/product/102/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora10)(PORT=1521)))
The listener supports no services
The command completed successfully
[oracle@ora10 ~]$
[oracle@ora10 ~]$ lsnrctl

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 07-MAY-2016 07:06:03

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

Welcome to LSNRCTL, type "help" for information.

LSNRCTL> status  
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date                07-MAY-2016 07:05:14
Uptime                    0 days 0 hr. 0 min. 53 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         /u01/oracle/product/102/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora10)(PORT=1521)))
Services Summary...
Service "upgr" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
Service "upgrXDB" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
The command completed successfully
LSNRCTL> service
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "upgr" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:blocked
         REMOTE SERVER
         (ADDRESS=(PROTOCOL=TCP)(HOST=db1)(PORT=1521))
Service "upgrXDB" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER <machine: db1, pid: 3238>
         (ADDRESS=(PROTOCOL=tcp)(HOST=db1)(PORT=25407))
The command completed successfully
LSNRCTL>

在ora10上做测试

[oracle@ora10 ~]$ sqlplus system/oracle@ora10:1521/upgr
SQL*Plus: Release 10.2.0.1.0 - Production on Sat May 7 07:07:21 2016

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

ERROR:
ORA-12516: TNS:listener could not find available handler with matching protocol
stack Enter user-name:
ERROR:
ORA-01017: invalid username/password; logon denied

Enter user-name:
ERROR:
ORA-01017: invalid username/password; logon denied
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
[oracle@ora10 ~]$

启动db1上监听

[oracle@db1 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-MAY-2016 22:10:12

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

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                07-MAY-2016 22:08:50
Uptime                    0 days 0 hr. 1 min. 21 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         /u01/oracle/diag/tnslsnr/db1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db1)(PORT=1521)))
Services Summary...
Service "upgr" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
Service "upgrXDB" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@db1 admin]$
[oracle@db1 admin]$ lsnrctl

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-MAY-2016 22:10:45

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

Welcome to LSNRCTL, type "help" for information.

LSNRCTL> services
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "upgr" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "upgrXDB" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER <machine: db1, pid: 3238>
         (ADDRESS=(PROTOCOL=tcp)(HOST=db1)(PORT=25407))
The command completed successfully
LSNRCTL>

在ora10上再次连接upgr

[oracle@ora10 ~]$ lsnrctl

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 07-MAY-2016 07:09:19

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

Welcome to LSNRCTL, type "help" for information.

LSNRCTL> services
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "upgr" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:blocked
         REMOTE SERVER
         (ADDRESS=(PROTOCOL=TCP)(HOST=db1)(PORT=1521))
Service "upgrXDB" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER <machine: db1, pid: 3238>
         (ADDRESS=(PROTOCOL=tcp)(HOST=db1)(PORT=25407))
The command completed successfully
LSNRCTL> exit
[oracle@ora10 ~]$ sqlplus system/oracle@ora10:1521/upgr

SQL*Plus: Release 10.2.0.1.0 - Production on Sat May 7 07:11:40 2016

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options

SQL> select name from v$database;

NAME
---------
UPGR

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options
[oracle@ora10 ~]$ lsnrctl service

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 07-MAY-2016 07:11:59

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

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "upgr" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:1 refused:0 state:ready
         REMOTE SERVER
         (ADDRESS=(PROTOCOL=TCP)(HOST=db1)(PORT=1521))
Service "upgrXDB" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER <machine: db1, pid: 3238>
         (ADDRESS=(PROTOCOL=tcp)(HOST=db1)(PORT=25407))
The command completed successfully
[oracle@ora10 ~]$

在db1上查看监听信息

LSNRCTL> service
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "upgr" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "upgrXDB" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER <machine: db1, pid: 3238>
         (ADDRESS=(PROTOCOL=tcp)(HOST=db1)(PORT=25407))
The command completed successfully
LSNRCTL> service
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "upgr" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:1 refused:0 state:ready
         LOCAL SERVER
Service "upgrXDB" has 1 instance(s).
  Instance "upgr", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER <machine: db1, pid: 3238>
         (ADDRESS=(PROTOCOL=tcp)(HOST=db1)(PORT=25407))
The command completed successfully
LSNRCTL>

测试用相关连接字符串

PGOLD =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = cluster01-scan)(PORT = 10010))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pgold)
    )
  )
 
PGOLD =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (LOAD_BALANCE=YES)
      (FAILOVER=YES)
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.0.2.111)(PORT = 10010))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.0.2.112)(PORT = 10010))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.0.2.113)(PORT = 10010))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = pgold)
    )
  )

11gR2 JDBC Connect String
jdbc:oracle:thin@cluster01-scan:10010/pgold
注意:之前jdbc连接串中:换成了/

SCAN相关命令

srvctl config scan
Shows the current SCAN configuration

srvctl config scan_listener
Shows the existence and port numbers for the SCAN listeners

srvctl add scan -n cluster01-scan
Adds new SCAN information for a cluster

srvctl remove scan -f
Removes SCAN information

srvctl add scan_listener
Adds a new SCAN listener for a cluster on the default port of 1521

srvctl add scan_listener -p 10010 ## non default port number ##
Adds a new SCAN listener on a different port

srvctl remove scan_listener
Removes the SCAN listener

srvctl modify scan -n cluster_scan
Modifies SCAN information (used when changing SCAN to DNS after initially using /etc/hosts)

srvctl modify scan_listener -u
Modifies the SCAN listener information to match the new SCAN VIP information from the modify scan command

如何修改SCAN监听端口

To modify SCAN listener port,login as grid user and do below steps

1. Modify SCAN listener port:
$GRID_HOME/bin/srvctl modify scan_listener -p <new-SCAN-port>
2. Restart SCAN listener so the new port will be effective:
$GRID_HOME/bin/srvctl stop scan_listener
$GRID_HOME/bin/srvctl start scan_listener
3. Confirm the change:
$GRID_HOME/bin/srvctl config scan_listener

SCAN相关名词
single client access name (SCAN)
Oracle Database 11g database clients use SCAN to connect to the database. SCAN can resolve to multiple IP addresses, reflecting multiple listeners in the cluster handling public client connections.

FAN: Fast Application Notification
Applications can use FAN to enable rapid failure detection, balancing of connection pools after failures, and re-balancing of connection pools when failed components are repaired. The FAN notification process uses system events that Oracle Database publishes when cluster servers become unreachable or if network interfaces fail.

Fast Connection Failover
Fast Connection Failover provides high availability to FAN integrated clients, such as clients that use JDBC, OCI, or ODP.NET. If you configure the client to use fast connection failover, then the client automatically subscribes to FAN events and can react to database UP and DOWN events. In response, Oracle Database gives the client a connection to an active instance that provides the requested database service.

TAF: Transparent Application Failover
A runtime failover for high-availability environments, such as Oracle RAC and Oracle RAC Guard, TAF refers to the failover and re-establishment of application-to-service connections. It enables client applications to automatically reconnect to the database if the connection fails, and optionally resume a SELECT statement that was in progress. This reconnect happens automatically from within the Oracle Call Interface library.

Oracle Notification Service
A publish and subscribe service for communicating information about all FAN events.

policy-managed database
A database that you define as a cluster resource. Management of the database is defined by how you configure the resource, including on which servers the database can run and how many instances of the database are necessary to support the expected workload.

Reference

Grid Infrastructure Single Client Access Name (SCAN) Explained (Note ID 887522.1)

http://docs.oracle.com/cd/E11882_01/server.112/e40540/dist_pro.htm#CNCPT1272
http://docs.oracle.com/cd/E11882_01/network.112/e41945/listenercfg.htm
http://docs.oracle.com/cd/E11882_01/rac.112/e41960/rac_glossary.htm

http://www.oracle.com/technetwork/products/clustering/overview/scan-129069.pdf

赞(0) 打赏
未经允许不得转载:徐万新之路 » SCAN,VIP,Local Listener,Remote Listener之间的关系
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏