ORACLE動態監聽與靜態監聽

wzq609發表於2016-01-01

【前言】連線ORACLE其實是挺簡單的一件事,只要會啟動監聽、配置tnsnames檔案就可以了,但是相信大部分的人對於更深一點的動態監聽和靜態監聽會知道一些,但也僅限於表面而已,在後面的工作中,因為一些配置的緣故需要對這個更深一步瞭解,所以就有了今天這個文件;

 

【1】資料庫和監聽註冊的過程:

1.1 如果知道資料庫的資訊,可以先在監聽檔案裡面配置好要監聽的資料庫的例項名,並配置server名稱,這種就是靜態監聽,因為這個監聽伺服器是由監聽程式發起的,所以狀態一直是UNKNOWN,且資料庫關閉後這個監聽還會存在;

1.2 監聽檔案沒有配置監聽資料庫的資訊,但是當資料庫啟動的時候,會自動將instance_name,service_names兩個引數將例項和服務動態註冊到listener中,這種監聽就是動態監聽因為這個監聽是從資料庫發起的,這個時候監聽肯定是由對應的資料庫的,所以顯示的狀態是READ,當資料庫關閉後這個監聽也就消失了。

[grid@db01 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 03-DEC-2015 04:21:14

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                03-DEC-2015 02:37:06
Uptime                    0 days 1 hr. 44 min. 8 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/grid/product/11.2.0/grid/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/db01/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db01)(PORT=1521)))
Services Summary...
Service "JOEONEXDB" has 1 instance(s).
  Instance "JOEONE", status READY, has 1 handler(s) for this service...
Service "XIAMEN" has 2 instance(s).
  Instance "JOEONE", status UNKNOWN, has 1 handler(s) for this service...
  Instance "JOEONE", status READY, has 1 handler(s) for this service...
Service "XIAMEN01" has 1 instance(s).
  Instance "JOEONE", status UNKNOWN, has 1 handler(s) for this service...
Service "XIAMEN_DGB" has 1 instance(s).
  Instance "JOEONE", status READY, has 1 handler(s) for this service...
The command completed successfully

以上亮紅色的字型有三個監聽,分別是:

  • 資料庫有透過動態註冊一個Service為XIAMEN,INSTANCE_NAME為JOEONE的監聽;
  • 配置了一個Service為XIAMEN,INSTANCE_NAME為JOEONE的靜態監聽,因為兩個的SERVICE名稱一樣,所以合併在一起了;
  • 配置了一個Service為XIAMEN01,INSTANCE_NAME為JOEONE的靜態監聽;

 

相應的監聽配置檔案如下:

SID_LIST_LISTENER = 
  (SID_LIST = 
    (SID_DESC = 
      (GLOBAL_DBNAME =XIAMEN01
      (ORACLE_HOME =/u01/app/oracle/product/11.2.0/dbhome_1) 
      (SID_NAME =JOEONE
    ) 
  (SID_DESC =
      (GLOBAL_DBNAME =XIAMEN)
      (ORACLE_HOME =/u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME =JOEONE)
    )
  ) 

 

【2】動態監聽的原理

  pmon在資料庫啟動到mount或open時,動態從引數檔案中讀取service_names值。service_names可以為多值(可以有64個,其中包括兩個系統的)。
  service_names預設為建立資料庫時的全域性資料庫名,預設以1521的埠進行註冊;

 

建立非預設的名稱,指令碼:

SQL>  alter system set service_names=JOHN;

Services Summary...
Service "JOEONEXDB" has 1 instance(s).
  Instance "JOEONE", status READY, has 1 handler(s) for this service...
Service "JOHN" has 1 instance(s).    #上面註冊的名稱
  Instance "JOEONE", status READY, has 1 handler(s) for this service...
Service "XIAMEN" has 2 instance(s).
  Instance "JOEONE", status UNKNOWN, has 1 handler(s) for this service...
  Instance "JOEONE", status READY, has 1 handler(s) for this service...
Service "XIAMEN01" has 1 instance(s).
  Instance "JOEONE", status UNKNOWN, has 1 handler(s) for this service...
Service "XIAMEN_DGB" has 1 instance(s).
  Instance "JOEONE", status READY, has 1 handler(s) for this service...
The command completed successfully

 

預設情況下監聽的埠是1521,有時候出自於安全或區別的考慮監聽的埠就會用非預設的埠,SAP資料庫使用的埠就是用1527的,所以為了保證資料庫和監聽能夠建立連線,就需要配置靜態監聽或讓資料庫進行動態註冊;

  • 靜態監聽:這裡的步驟不再說明,在$ORACLE_HOME/NETWORK/ADMIN/listener.ora新增上面增加1.2的配置
  • 動態監聽:在ORACLE裡面新增SQL語句進行註冊,可以透過以下指令碼進行管理:
  •  

2.1 動態監聽的註冊:alter system set LOCAL_LISTENER='(ADDRESS=(PROTOCOL=TCP)(HOST=HOSTNAME)(PORT=1527))';

 

2.2  檢視當前本地監聽註冊的資訊: show parameter local_listener;

SQL> show parameter listener

NAME                           TYPE                                 VALUE
----------------------  --------------     ----------------------------------------------------------------
local_listener                 string                (ADDRESS=(PROTOCOL=TCP)(HOST=db01)(PORT=1527))

 

2.3 刪除當前監聽的註冊資訊:alter system set LOCAL_LISTENER='';

SQL> show parameter  local_listener 

NAME                                 TYPE                             VALUE
-----------------------  -------------    --------------------------------------------------------------------
local_listener                 string               (ADDRESS=(PROTOCOL=TCP)(HOST=db01)(PORT=1527))

SQL> alter system set LOCAL_LISTENER='';

System altered.

SQL> show parameter local_listener;

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
local_listener                 string

 

【總結】認證整理完監聽的這個文件,發現其實監聽也是很簡單的一件事就像男生和女生談戀愛一樣,要麼男生主動找女生這是動態監聽,要麼女生就在那邊靜靜等待男生的到來這是靜態監聽;但是動態不管是動態監聽還是靜態監聽女生都要告訴男神聯絡的暗號,這樣才能在同一個頻道上面。。

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

如果你對ORACLE的資料庫管理有獨特的見解或者有濃厚的興趣,請加入群367875324,暗號ORACLE管理

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

相關文章