Oracle RAC中REMOTE_LISTENER和local_listener的作用是什么?

简介: Oracle RAC中REMOTE_LISTENER和local_listener的作用是什么?

简介

REMOTE_LISTENER参数主要用于RAC环境中监听器的远程注册,监听器的远程注册主要用于实现负载均衡。通常情况下,客户端发出的连接请求会首先被LOCAL_LISTENER接收,然后由Master Instance来决定当前的连接请求应该由哪个目标Instance发出Server Process响应这个连接请求。在启用了负载均衡的情形下,Master Instance会将请求转发到负载较小的实例。如果此时Remote_Listener中指定的实例负载较小,那么当前的请求会被重定向到负载较小的Instance中来建立连接,派生服务器进程进行相应连接。

在RAC环境下不管是使用了默认的TCP和1521还是其他协议都建议配置LOCAL_LISTENER。REMOTE_LISTENER参数在RAC环境下非常重要,是服务器实现负载均衡的一个工具。在服务器端的连接中,Oracle NET通过remote_listener确定当前RAC中的远程监听和实例,以便分发连接。

RAC环境中的监听器可以分为本地监听器和SCAN监听器,分别对应LOCAL_LISTENER和REMOTE_LISTENER参数:

LOCAL LISTENER:本地监听器只能监听到运行在本节点上的数据库。RAC的每个节点上都会有独立的本地监听器,它会监听该节点的Public IP和VIP,而每个节点的实例在启动的时候也会向本地监听器进行注册,当然它也会向SCAN监听器注册,当VIP或者Public IP有连接请求的时候,本地监听器就接受处理并和本地实例建立连接。如果某个节点故障,那么其上面的VIP会进行漂移,但本地监听器并不会产生漂移。

本地监听器对应的设置参数为LOCAL_LISTENER。这个参数控制着本地监听器的注册,因为本地监听器的工作机制关系,通过本地监听器的数据库连接请求只会连接到本地节点的实例上。

SCAN LISTENER:SCAN监听器可以监听到集群中运行的所有数据库,它是实现SCAN负载均衡的原理所在。如果RAC上有三个SCAN VIP,那么SCAN监听器也有三个,它们各自监听SCAN VIP的连接请求。SCAN监听器跟着SCAN VIP随机分配到节点服务器上,如果某个节点发生故障,那么运行在此节点上的SCAN VIP会进行漂移,这时候SCAN监听器也跟着漂移到正常的节点上,继续为SCAN VIP监听连接请求。当PMON进程下次动态更新实例信息到该SCAN监听器之后,它又重新接收客户端的连接。这和VIP产生漂移的时候是有所区别的。

SCAN监听器对应的设置参数为REMOTE_LISTENER。通过设置这个参数,任何数据库实例都会向SCAN监听器注册,主要用于注册远程数据库实例,所以SCAN监听器能够负载均衡地分发连接请求到节点本地监听器上,也就是连接到其本地节点上实例上。

修改远程监听参数REMOTE_LISTENER,值为“SCAN Name:port”:

alter system set remote_listener='raclhr-11gR2-scan:1521' sid='*';

修改远程监听端口scan端口:

srvctl modify scan_listener -p 1522

有关SCAN监听器的其它命令:

[root@raclhr-11gR2-N2 ~]# srvctl -h | grep scan_listener
Usage: srvctl add scan_listener [-l <lsnr_name_prefix>] [-s] [-p [TCP:]<port>[/IPC:<key>][/NMP:<pipe_name>][/TCPS:<s_port>] [/SDP:<port>]] 
Usage: srvctl config scan_listener [-i <ordinal_number>]
Usage: srvctl start scan_listener [-n <node_name>] [-i <ordinal_number>]
Usage: srvctl stop scan_listener [-i <ordinal_number>] [-f]
Usage: srvctl relocate scan_listener -i <ordinal_number> [-n <node_name>]
Usage: srvctl status scan_listener [-i <ordinal_number>] [-v]
Usage: srvctl enable scan_listener [-i <ordinal_number>]
Usage: srvctl disable scan_listener [-i <ordinal_number>]
Usage: srvctl modify scan_listener {-u|-p [TCP:]<port>[/IPC:<key>][/NMP:<pipe_name>][/TCPS:<s_port>] [/SDP:<port>]} 
Usage: srvctl remove scan_listener [-f] [-y]
[root@raclhr-11gR2-N2 ~]# 

查看现有的监听器:

[oracle@raclhr-11gR2-N2 ~]$ ps -ef|grep tns
root        15     2  0 09:55 ?        00:00:00 [netns]
grid     18138     1  0 10:38 ?        00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -inherit
grid     18168     1  0 10:38 ?        00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit
oracle   19184 18645  0 11:05 pts/2    00:00:00 grep tns
[oracle@raclhr-11gR2-N2 ~]$ 
[root@raclhr-11gR2-N2 ~]# lsnrctl status LISTENER_SCAN1

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 05-JUN-2018 10:48:12

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                05-JUN-2018 10:38:02
Uptime                    0 days 0 hr. 10 min. 10 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File         /u01/app/11.2.0/grid/log/diag/tnslsnr/raclhr-11gR2-N2/listener_scan1/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.59.174)(PORT=1521)))
Services Summary...
Service "+ASM" has 2 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "lhrrac1" has 2 instance(s).
  Instance "lhrrac11", status READY, has 1 handler(s) for this service...
  Instance "lhrrac12", status READY, has 1 handler(s) for this service...
Service "lhrrac1XDB" has 2 instance(s).
  Instance "lhrrac11", status READY, has 1 handler(s) for this service...
  Instance "lhrrac12", status READY, has 1 handler(s) for this service...
The command completed successfully
[root@raclhr-11gR2-N2 ~]# lsnrctl status LISTENER 

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 05-JUN-2018 11:22:08

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                05-JUN-2018 10:38:07
Uptime                    0 days 0 hr. 44 min. 1 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/raclhr-11gR2-N2/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.59.171)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.59.173)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "lhrrac1" has 1 instance(s).
  Instance "lhrrac12", status READY, has 1 handler(s) for this service...
Service "lhrrac1XDB" has 1 instance(s).
  Instance "lhrrac12", status READY, has 1 handler(s) for this service...
The command completed successfully

当然,SCAN Listener也可以进行静态监听,如下所示:

[root@raclhr-11gR2-N2 .oracle]# cat /u01/app/11.2.0/grid/network/admin/listener.ora
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1))))                # line added by Agent
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER))))            # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON              # line added by Agent
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON                # line added by Agent

LISTENER_SCAN1 =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.174)(PORT = 1521))
    )
  )

SID_LIST_LISTENER_SCAN1 =
(SID_LIST =
    (SID_DESC =
     (GLOBAL_DBNAME = lhrrac1)
     (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
     (SID_NAME = lhrrac12)
    )
    (SID_DESC =
     (GLOBAL_DBNAME = lhrrac1)
     (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
     (SID_NAME = lhrrac11)
    )
 )
[root@raclhr-11gR2-N2 .oracle]# lsnrctl reload listener_scan1                      

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 05-JUN-2018 13:46:13

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.59.174)(PORT=1521)))
The command completed successfully
[root@raclhr-11gR2-N2 .oracle]# lsnrctl status listener_scan1                      

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 05-JUN-2018 13:46:19

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.59.174)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     listener_scan1
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                05-JUN-2018 13:41:04
Uptime                    0 days 0 hr. 5 min. 14 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File         /u01/app/11.2.0/grid/log/diag/tnslsnr/raclhr-11gR2-N2/listener_scan1/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.59.174)(PORT=1521)))
Services Summary...
Service "+ASM" has 2 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "lhrrac1" has 4 instance(s).
  Instance "lhrrac11", status UNKNOWN, has 1 handler(s) for this service...
  Instance "lhrrac11", status READY, has 1 handler(s) for this service...
  Instance "lhrrac12", status UNKNOWN, has 1 handler(s) for this service...
  Instance "lhrrac12", status READY, has 1 handler(s) for this service...
Service "lhrrac1XDB" has 2 instance(s).
  Instance "lhrrac11", status READY, has 1 handler(s) for this service...
  Instance "lhrrac12", status READY, has 1 handler(s) for this service...
Service "lhrxxt" has 2 instance(s).
  Instance "lhrrac11", status READY, has 1 handler(s) for this service...
  Instance "lhrrac12", status READY, has 1 handler(s) for this service...
The command completed successfully

配置

1、修改完rac的端口号后,一定记得要修改local_listener和remote_listener的值,且必须使用sid参数

alter system set local_listener='(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.20.7.83)(PORT=1522)))' sid='rac1';
alter system set local_listener='(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.20.7.84)(PORT=1522)))' sid='rac2';
alter system set remote_listener='rac-scan:1522' sid='*';
alter system register;
相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
目录
相关文章
|
1月前
|
存储 运维 Oracle
Oracle系列十八:Oracle RAC
Oracle系列十八:Oracle RAC
|
2月前
|
Oracle 关系型数据库
oracle Hanganalyze no RAC
oracle Hanganalyze no RAC
15 0
|
2月前
|
Oracle 关系型数据库
oracle rac 手工安装补丁,不适用auto
oracle rac 手工安装补丁,不适用auto
25 3
|
6月前
|
Oracle 关系型数据库 Java
分享一个 Oracle RAC 模式下客户端建立JDBC初始连接时因ONS造成应用启动时卡顿30秒问题的排查分析案例
分享一个 Oracle RAC 模式下客户端建立JDBC初始连接时因ONS造成应用启动时卡顿30秒问题的排查分析案例
|
11月前
|
存储 Oracle 关系型数据库
|
文字识别 Oracle 关系型数据库
Oracle rac重新执行root.sh脚本
Oracle rac重新执行root.sh脚本
692 0
|
网络协议 Oracle 关系型数据库
Oracle rac 修改SCAN IP
Oracle rac 修改SCAN IP
650 0
|
网络协议 Oracle 关系型数据库
Oracle rac不能监听public ip
Oracle rac不能监听public ip
231 0
|
缓存 负载均衡 Oracle
Oracle rac集群中的IP类型简介
Oracle rac集群中的IP类型简介
545 0