local_listener與remote_listener詳述

zhanglei_itput發表於2009-04-28

簡述一下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> conn sys/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> conn sys/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裡的。

參考文獻:原創
listener的靜態註冊與動態註冊詳述 http://space.itpub.net/9252210/viewspace-580699

itpub oracle 10g dba培訓課程筆記(三)  http://space.itpub.net/9252210/viewspace-578120

安裝完RAC以後dba需要2點手工操作 http://space.itpub.net/9252210/viewspace-573149






來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9252210/viewspace-592111/,如需轉載,請註明出處,否則將追究法律責任。

相關文章