♣
题目部分
在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”:
1alter system set remote_listener='raclhr-11gR2-scan:1521' sid='*';
修改远程监听端口scan端口:
1srvctl modify scan_listener -p 1522
有关SCAN监听器的其它命令:
1[root@raclhr-11gR2-N2 ~]# srvctl -h | grep scan_listener 2Usage: srvctl add scan_listener [-l <lsnr_name_prefix>] [-s] [-p [TCP:]<port>[/IPC:<key>][/NMP:<pipe_name>][/TCPS:<s_port>] [/SDP:<port>]] 3Usage: srvctl config scan_listener [-i <ordinal_number>] 4Usage: srvctl start scan_listener [-n <node_name>] [-i <ordinal_number>] 5Usage: srvctl stop scan_listener [-i <ordinal_number>] [-f] 6Usage: srvctl relocate scan_listener -i <ordinal_number> [-n <node_name>] 7Usage: srvctl status scan_listener [-i <ordinal_number>] [-v] 8Usage: srvctl enable scan_listener [-i <ordinal_number>] 9Usage: srvctl disable scan_listener [-i <ordinal_number>] 10Usage: srvctl modify scan_listener {-u|-p [TCP:]<port>[/IPC:<key>][/NMP:<pipe_name>][/TCPS:<s_port>] [/SDP:<port>]} 11Usage: srvctl remove scan_listener [-f] [-y] 12[root@raclhr-11gR2-N2 ~]#
查看现有的监听器:
1[oracle@raclhr-11gR2-N2 ~]$ ps -ef|grep tns 2root 15 2 0 09:55 ? 00:00:00 [netns] 3grid 18138 1 0 10:38 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -inherit 4grid 18168 1 0 10:38 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit 5oracle 19184 18645 0 11:05 pts/2 00:00:00 grep tns 6[oracle@raclhr-11gR2-N2 ~]$ 7[root@raclhr-11gR2-N2 ~]# lsnrctl status LISTENER_SCAN1 8 9LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 05-JUN-2018 10:48:12 10 11Copyright (c) 1991, 2011, Oracle. All rights reserved. 12 13Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1))) 14STATUS of the LISTENER 15------------------------ 16Alias LISTENER_SCAN1 17Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production 18Start Date 05-JUN-2018 10:38:02 19Uptime 0 days 0 hr. 10 min. 10 sec 20Trace Level off 21Security ON: Local OS Authentication 22SNMP OFF 23Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora 24Listener Log File /u01/app/11.2.0/grid/log/diag/tnslsnr/raclhr-11gR2-N2/listener_scan1/alert/log.xml 25Listening Endpoints Summary... 26 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN1))) 27 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.59.174)(PORT=1521))) 28Services Summary... 29Service "+ASM" has 2 instance(s). 30 Instance "+ASM1", status READY, has 1 handler(s) for this service... 31 Instance "+ASM2", status READY, has 1 handler(s) for this service... 32Service "lhrrac1" has 2 instance(s). 33 Instance "lhrrac11", status READY, has 1 handler(s) for this service... 34 Instance "lhrrac12", status READY, has 1 handler(s) for this service... 35Service "lhrrac1XDB" has 2 instance(s). 36 Instance "lhrrac11", status READY, has 1 handler(s) for this service... 37 Instance "lhrrac12", status READY, has 1 handler(s) for this service... 38The command completed successfully 39[root@raclhr-11gR2-N2 ~]# lsnrctl status LISTENER 40 41LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 05-JUN-2018 11:22:08 42 43Copyright (c) 1991, 2011, Oracle. All rights reserved. 44 45Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER))) 46STATUS of the LISTENER 47------------------------ 48Alias LISTENER 49Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production 50Start Date 05-JUN-2018 10:38:07 51Uptime 0 days 0 hr. 44 min. 1 sec 52Trace Level off 53Security ON: Local OS Authentication 54SNMP OFF 55Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora 56Listener Log File /u01/app/grid/diag/tnslsnr/raclhr-11gR2-N2/listener/alert/log.xml 57Listening Endpoints Summary... 58 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER))) 59 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.59.171)(PORT=1521))) 60 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.59.173)(PORT=1521))) 61Services Summary... 62Service "+ASM" has 1 instance(s). 63 Instance "+ASM2", status READY, has 1 handler(s) for this service... 64Service "lhrrac1" has 1 instance(s). 65 Instance "lhrrac12", status READY, has 1 handler(s) for this service... 66Service "lhrrac1XDB" has 1 instance(s). 67 Instance "lhrrac12", status READY, has 1 handler(s) for this service... 68The command completed successfully
当然,SCAN Listener也可以进行静态监听,如下所示:
1[root@raclhr-11gR2-N2 .oracle]# cat /u01/app/11.2.0/grid/network/admin/listener.ora 2LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent 3LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) # line added by Agent 4ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent 5ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1=ON # line added by Agent 6 7LISTENER_SCAN1 = 8 (DESCRIPTION_LIST = 9 (DESCRIPTION = 10 (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.174)(PORT = 1521)) 11 ) 12 ) 13 14SID_LIST_LISTENER_SCAN1 = 15(SID_LIST = 16 (SID_DESC = 17 (GLOBAL_DBNAME = lhrrac1) 18 (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) 19 (SID_NAME = lhrrac12) 20 ) 21 (SID_DESC = 22 (GLOBAL_DBNAME = lhrrac1) 23 (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) 24 (SID_NAME = lhrrac11) 25 ) 26 ) 27[root@raclhr-11gR2-N2 .oracle]# lsnrctl reload listener_scan1 28 29LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 05-JUN-2018 13:46:13 30 31Copyright (c) 1991, 2011, Oracle. All rights reserved. 32 33Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.59.174)(PORT=1521))) 34The command completed successfully 35[root@raclhr-11gR2-N2 .oracle]# lsnrctl status listener_scan1 36 37LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 05-JUN-2018 13:46:19 38 39Copyright (c) 1991, 2011, Oracle. All rights reserved. 40 41Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.59.174)(PORT=1521))) 42STATUS of the LISTENER 43------------------------ 44Alias listener_scan1 45Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production 46Start Date 05-JUN-2018 13:41:04 47Uptime 0 days 0 hr. 5 min. 14 sec 48Trace Level off 49Security ON: Local OS Authentication 50SNMP OFF 51Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora 52Listener Log File /u01/app/11.2.0/grid/log/diag/tnslsnr/raclhr-11gR2-N2/listener_scan1/alert/log.xml 53Listening Endpoints Summary... 54 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.59.174)(PORT=1521))) 55Services Summary... 56Service "+ASM" has 2 instance(s). 57 Instance "+ASM1", status READY, has 1 handler(s) for this service... 58 Instance "+ASM2", status READY, has 1 handler(s) for this service... 59Service "lhrrac1" has 4 instance(s). 60 Instance "lhrrac11", status UNKNOWN, has 1 handler(s) for this service... 61 Instance "lhrrac11", status READY, has 1 handler(s) for this service... 62 Instance "lhrrac12", status UNKNOWN, has 1 handler(s) for this service... 63 Instance "lhrrac12", status READY, has 1 handler(s) for this service... 64Service "lhrrac1XDB" has 2 instance(s). 65 Instance "lhrrac11", status READY, has 1 handler(s) for this service... 66 Instance "lhrrac12", status READY, has 1 handler(s) for this service... 67Service "lhrxxt" has 2 instance(s). 68 Instance "lhrrac11", status READY, has 1 handler(s) for this service... 69 Instance "lhrrac12", status READY, has 1 handler(s) for this service... 70The command completed successfully
本文选自《Oracle程序员面试笔试宝典》,作者:小麦苗
---------------优质麦课------------
详细内容可以添加麦老师微信或QQ私聊。
About Me:小麦苗
● 本文作者:小麦苗,只专注于数据库的技术,更注重技术的运用
● 作者博客地址:http://blog.itpub.net/26736162/abstract/1/
● 本系列题目来源于作者的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解
● 版权所有,欢迎分享本文,转载请保留出处
● QQ:646634621 QQ群:618766405
● 提供OCP、OCM和高可用部分最实用的技能培训
● 题目解答若有不当之处,还望各位朋友批评指正,共同进步
DBA宝典
长按下图识别二维码或微信扫描下图二维码来关注小麦苗的微信公众号:xiaomaimiaolhr,学习最实用的数据库技术。