分类: Oracle
2010-03-12 16:15:38
简述一下local_listener与remote_listener这两个参数的含义(针对环境)
在完RAC以后,会自动修改local_listener和remote_listener这两个参数,同时把两个节点的3要素添加到$ORACLE_HOME/network/admin下的tnsnames.ora文件中:
1.查看listeners_devdb服务名配置
[oracle@rac21admin]$ more tnsnames.ora
LISTENERS_DEVDB =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
)
2.show parameter local_listener and remote_listener
[oracle@rac1 admin]$ sqlplus /nolog
SQL> connsys/oracle@devdb1as sysdba
Connected.
SQL> show parameter listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.68)(PORT = 1521))
remote_listener string LISTENERS_DEVDB
SQL> connsys/oracle@devdb2as sysdba
Connected.
SQL> show parameter listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.230.69)(PORT = 1521))
remote_listener string LISTENERS_DEVDB
3.查看listener状态
节点1
[oracle@rac1 admin]$lsnrctl status
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER_RAC1
Version TNSLSNR for Linux: Version 10.2.0.4.0 - Production
Start Date 28-APR-2009 10:36:56
Uptime 0 days 8 hr. 1 min. 20 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener_rac1.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.230.68)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
Services Summary...
Service "devdb" has 2 instance(s).
Instance "devdb1", status READY, has 2 handler(s) for this service...
Instance "devdb2", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@rac1 admin]$lsnrctl service
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "devdb" has 2 instance(s).
Instance "devdb1", status READY, has 2 handler(s) for this service...
Handler(s):
"DEDICATED" established:1 refused:0 state:ready
LOCAL SERVER --local_listener参数
"DEDICATED" established:0 refused:0 state:ready
REMOTE SERVER --remote_listener参数
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.230.68)(PORT=1521))
Instance "devdb2", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
REMOTE SERVER --remote_listener参数
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.230.69)(PORT=1521))
The command completed successfully
节点2
[oracle@rac2 admin]$lsnrctl status
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER_RAC2
Version TNSLSNR for Linux: Version 10.2.0.4.0 - Production
Start Date 28-APR-2009 15:25:45
Uptime 0 days 3 hr. 18 min. 21 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener_rac2.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.230.69)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.230.67)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
Services Summary...
Service "devdb" has 2 instance(s).
Instance "devdb1", status READY, has 1 handler(s) for this service...
Instance "devdb2", status READY, has 2 handler(s) for this service...
The command completed successfully
[oracle@rac2 admin]$lsnrctl service
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "devdb" has 2 instance(s).
Instance "devdb1", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
REMOTE SERVER --remote_listener参数
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.230.68)(PORT=1521))
Instance "devdb2", status READY, has 2 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
REMOTE SERVER --remote_listener参数
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.230.69)(PORT=1521))
"DEDICATED" established:1 refused:0 state:ready
LOCAL SERVER --local_listener参数
The command completed successfully
过程描述:
当客户端发出连接请求给端listener的时候,通过local_listener注册的服务接收这个连接请求,然后由master instance来决定这个连接请求应该由哪个目标instance发出server process响应这个连接请求。如果启用负载均衡,那么主节点会选择cpu负载最小的那个instance,此时
如果master分配的目标instance是local listener machine,那么直接通过local server listener,开启后台的server process,处理发出conn的客户端,建立连接,处理会话;
如果master分配的目标instance不是local listener machine,那么会通过remote_listener这个参数,把连接请求转移到remote machine上的listener, 然后由remote service listener发出一个server process返回客户端,建立连接,处理会话.
当conn建立连接以后,listener就没有用了,不会再用到了,如果这个时候,已经连接的那个instance down了,会重新由新分配的master instance通过remote_listener切换到可用instance,此时客户不会发现连接中断。conn 和 select操作是不会中断的。
备注:shut down instance2,重启listener,监听服务状态
[oracle@rac2 admin]$ sqlplus /nolog
SQL> connsys/oracle@devdb2as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
[oracle@rac2 admin]$lsnrctl status
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER_RAC2
Version TNSLSNR for Linux: Version 10.2.0.4.0 - Production
Start Date 28-APR-2009 15:25:45
Uptime 0 days 3 hr. 43 min. 44 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener_rac2.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.230.69)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.230.67)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
Services Summary...
Service "devdb" has 1 instance(s).
Instance "devdb1", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@rac2 admin]$lsnrctl service
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "devdb" has 1 instance(s).
Instance "devdb1", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
REMOTE SERVER
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.230.68)(PORT=1521))
The command completed successfully
[oracle@rac2 admin]$lsnrctl stop
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
The command completed successfully
[oracle@rac2 admin]$lsnrctl start
Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.4.0 - Production
System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac2.domain.com)(PORT=1521)))
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.4.0 - Production
Start Date 28-APR-2009 19:11:08
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac2.domain.com)(PORT=1521)))
The listener supports no services
The command completed successfully
[oracle@rac2 admin]$lsnrctl status
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.4.0 - Production
Start Date 28-APR-2009 19:11:08
Uptime 0 days 0 hr. 3 min. 28 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=rac2.domain.com)(PORT=1521)))
Services Summary...
Service "devdb" has 1 instance(s).
Instance "devdb1", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@rac2 admin]$lsnrctl service
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "devdb" has 1 instance(s).
Instance "devdb1", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
REMOTE SERVER
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.230.68)(PORT=1521))
The command completed successfully
此时可以看出,即使关闭实例2了,重启listener,但是实例2的service devdb 仍然可用,所以由此可以看出:
当实例1注册监听的时候,即使节点2的instance没有启动,也会通过remote_listener在节点2server上注册相应的listener1.它是在启动的时候,添加到相应的listener service里的。
参考文献:原创
listener的静态注册与动态注册详述http://space.itpub.net/9252210/viewspace-580699
itpub oracle dba培训课程笔记(三) http://space.itpub.net/9252210/viewspace-578120
安装完RAC以后dba需要2点手工操作http://space.itpub.net/9252210/viewspace-573149