簡述一下local_listener與remote_listener這兩個參數的含義(針對rac
環境)
在安裝
完RAC以後,oracle
會自動修改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@devdb1
as 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@devdb2
as 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 succes
sfully
過程描述:
當客戶端發出連接請求給server
端
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> conn
sys/oracle@devdb2
as 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裏的。