♣
题目部分
在Oracle中,RAC中REMOTE_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”:
代码语言:javascript复制alter system set remote_listener='raclhr-11gR2-scan:1521' sid='*';
修改远程监听端口scan端口:
代码语言:javascript复制srvctl modify scan_listener -p 1522
有关SCAN监听器的其它命令:
代码语言:javascript复制[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 ~]#
查看现有的监听器:
代码语言:javascript复制[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也可以进行静态监听,如下所示:
代码语言:javascript复制[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
本文选自《Oracle程序员面试笔试宝典》,作者:小麦苗
---------------优质麦课------------
详细内容可以添加麦老师微信或QQ私聊。
About Me:小麦苗
● 本文作者:小麦苗,只专注于数据库的技术,更注重技术的运用
● 作者博客地址:http://blog.itpub.net/26736162/abstract/1/
● 本系列题目来源于作者的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解
● 版权所有,欢迎分享本文,转载请保留出处
● QQ:646634621 QQ群:618766405
● 提供OCP、OCM和高可用部分最实用的技能培训
● 题目解答若有不当之处,还望各位朋友批评指正,共同进步