Oracle配置多個監聽


本文參考了官方幫助文檔:
Oracle Database Net Services Administrator’s Guide-》9 Configuring and Administering Oracle Net Listener章節:

主要知識點有如下:

  1. 動態監聽


This dynamic registration feature is called service registration. The registration is performed by the PMON process, an instance background process of each database instance that is configured in the database initialization parameter file. Dynamic service registration does not require any manual configuration in the listener.ora file
A process monitor database process that performs process recovery when a user process fails. PMON is responsible for cleaning up the cache and freeing resources that the process was using. PMON also checks on dispatcher and server processes and restarts them if they have failed. As a part of service registration, PMON registers instance information with the listener。
Service registration offers the following benefits:
■Simplified configuration
Service registration reduces the need for the SID_LIST_listener_name parameter setting, which specifies information about the databases served by the listener, in the listener.ora file.
■Connect-time failover
Because the listener always monitors the state of the instances, service registration facilitates automatic failover of a client connect request to a different instance if one instance is down.
■Connection load balancing
Service registration enables the listener to forward client connect requests to the least-loaded instance and dispatcher or dedicated server. Service registration balances the load across the service handlers and nodes.
■High-availability for Oracle Real Application Clusters and Oracle Data Guard


動態注冊也叫作服務器注冊,該注冊是由PMON(PROCESS MONITOR)來完成的,它是實例的一個后台進程,在數據庫的初始化參數文件中配置的,動態注冊不需要再listener.ora文件進行任何手動配置,完全是自動的。
一個數據庫的進程監控器主要用於當用戶進程失敗后,進行進程的恢復操作,PMON用於清楚進行使用的緩沖以及釋放進程所使用的資源,PMON也檢查分發器和服務器進程,並且當它們失敗后,重啟上述進程,作為服務器注冊的一部分,PMON將實例注冊到監聽中。
服務端配置主要有以下幾個優點:
1、簡化配置
減少了在SID_LIST_listener的配置
2、連接故障轉移
由於listener監聽實例的狀態,動態注冊發現一個實例down掉后,會自動的進行故障轉移
3、連接時,均衡負載
服務器注冊可以使監聽將請求分發到壓力最小的實例、分發器、專用進程,服務器注冊器通過節點和服務處理器來實現均衡負載
4、RAC和Oracle DG的高可用性

  1. 靜態監聽

    為什么要配置靜態監聽:

Configuration of static service information is necessary if you require remote database startup from a tool other than Oracle Enterprise Manager, or you have Oracle Database releases earlier than Oracle8i.

如果你想通過工具遠程啟動數據庫,而不是通過OEM,或者你的數據庫版本在Oracle 8I之前,你必須要配置靜態監聽。

下面是配置靜態監聽的方法:

下圖是靜態監聽必須包含的參數 :

這里寫圖片描述

在listener中增加如下代碼:

    (SID_DESC = (SID_NAME = ORCL ) (ORACLE_HOME = C:\app\Dyj\product\11.2.0\dbhome_1) (GLOBAL_DBNAME = ORCL) )

如下圖所示:

這里寫圖片描述

重啟監聽后,靜態監聽注冊成功,下方出現unkown的標識(表示靜態監聽注冊成功):

這里寫圖片描述

這時候就可以使用如下的方式連接數據庫,數據庫連接成功,此時是使用靜態監聽連接數據庫的,因為如上圖所示,還不到60S,動態監聽尚未注冊警來:

C:\Users\Administrator>sqlplus sys/cape@orcl as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期日 2月 19 22:59:18 2017 Copyright (c) 1982, 2010, Oracle. All rights reserved. 連接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>

 

  1. local_listener參數的使用

    To have PMON register with a local listener that does not use TCP/IP, port 1521, configure the LOCAL_LISTENER parameter in the initialization parameter file to locate the local listener.
    如果要使用PMON注冊本地的監聽,並且不適用TCP/IP,不使用默認端口1521,使用參數LOCAL_LISTENER來確定本地監聽。
    For a shared server environment, you can use the LISTENER attribute of the DISPATCHERS parameter in the initialization parameter file to register the dispatchers with a nondefault local listener. Because the LOCAL_LISTENER parameter and the LISTENER attribute enable PMON to register dispatcher information with the listener, it is not necessary to specify both the parameter and the attribute if the listener values are the same.
    對於共享服務的環境下,你也可以使用初始化參數DISPATCHER參數的LISTENER參數屬性,來給分發器注冊一個非默認的端口,由於上述兩個參數目的都是使PMON進程完成動態注冊,當兩個參數的值一樣時,就不需要分別設置,只需要設置一個即可。
    LOCAL_LISTENER is a comma-delimited list parameter. If a comma appears in the string, then the entire string must be enclosed in double quotation marks. Set the LOCAL_LISTENER parameter as follows:
    ALTER SYSTEM SET LOCAL LISTENER=[“]listener_address[“][,…];
    For example, if the listener address “ab,cd” is entered, then it resolves to one listener address. If the address is entered as ab,cd, then it resolves to two listener addresses, ab and cd.
    For shared server connections, set the LISTENER attribute as follows:
    ALTER SYSTEM SET DISPATCHERS=”(PROTOCOL=tcp)(LISTENER=listener_address)”;
    In the preceding command, listener_address is resolved to the listener protocol addresses through a naming method, such as a tnsnames.ora file on the database server.

修改配置文件listener.ora文件

增加配置文件,此處一定要去掉上方拷貝的IPC協議

SID_LIST_LISTENER1 =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = C:\app\Dyj\product\11.2.0\dbhome_1) (PROGRAM = extproc) (ENVS = "EXTPROC_DLLS=ONLY:C:\app\Dyj\product\11.2.0\dbhome_1\bin\oraclr11.dll") ) ) LISTENER1 = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = dongyj)(PORT = 1522)) ) )

 

這里寫圖片描述

修改配置文件tnsnames.ora

LISTENER_ORCL1 = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522))

 

這里寫圖片描述

配置數據庫參數值:local_listener

SQL> alter system set local_listener=LISTENER_ORCL,LISTENER_ORCL1; 系統已更改。 SQL> show parameters local_listener; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ local_listener string LISTENER_ORCL, LISTENER_ORCL1

 

啟動監聽,並完成動態注冊

啟動監聽:listener

這里寫圖片描述

啟動監聽:listener1

這里寫圖片描述

執行動態注冊命令:alter system register

listener動態監聽成功

這里寫圖片描述

listener1動態監聽成功

這里寫圖片描述

連接測試

在tnsnames.ora中加入一段代碼,測試1522端口號:

ORCL1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )

測試結果:1521端口

C:\Users\Administrator>sqlplus sys/cape@orcl as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期一 2月 20 22:07:36 2017 Copyright (c) 1982, 2010, Oracle. All rights reserved. 連接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>

 

1522端口

C:\Users\Administrator>sqlplus sys/cape@orcl1 as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期一 2月 20 22:08:13 2017 Copyright (c) 1982, 2010, Oracle. All rights reserved. 連接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>

 

也可以使用如下方式,直接指定端口號方式,而不用服務名連接:

C:\Users\Administrator>sqlplus sys/cape@localhost:1521/orcl as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期一 2月 20 22:08:59 2017 Copyright (c) 1982, 2010, Oracle. All rights reserved. 連接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> quit 從 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options 斷開 C:\Users\Administrator>sqlplus sys/cape@localhost:1522/orcl as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期一 2月 20 22:09:21 2017 Copyright (c) 1982, 2010, Oracle. All rights reserved. 連接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>

 

總結

  1. alter system set local_listener=LISTENER_ORCL,LISTENER_ORCL1, 其中LISTENER_ORCL,LISTENER_ORCL1的值必須在tnsnames.ora聲明

聲明如下:

LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) LISTENER_ORCL1 = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1522)) 

 

否則會出現如下的錯誤;

SQL> alter system set local_listener=a; alter system set local_listener=a * 第 1 行出現錯誤: ORA-02097: 無法修改參數, 因為指定的值無效 ORA-00119: 系統參數 LOCAL_LISTENER 的說明無效 ORA-00132: 語法錯誤或無法解析的網絡名稱 'A'

 

但是經過測試,發現一個BUG,校驗過程中,只檢測第一個參數的值,例如

alter system set local_listener=listener,a;

 

如果listener的值存在,而a的值,不存在。

  1. 在listener.ora中只能存在一個IPC協議,否則啟動的監聽都指向同一個監聽,測試如下:

    先保留IPC協議

SID_LIST_LISTENER1 =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = C:\app\Dyj\product\11.2.0\dbhome_1) (PROGRAM = extproc) (ENVS = "EXTPROC_DLLS=ONLY:C:\app\Dyj\product\11.2.0\dbhome_1\bin\oraclr11.dll") ) ) LISTENER1 = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = dongyj)(PORT = 1522)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) )

 

啟動監聽過程中,會發現,單獨啟動,都指向了同一個監聽

這里寫圖片描述

關於只能啟動一個IPC協議的問題,請參考網址:
http://www.xifenfei.com/2012/06/%E5%9B%A0ipc%E5%AF%BC%E8%87%B4%E5%A4%9A%E4%B8%AA%E7%9B%91%E5%90%AC%E4%B8%8D%E8%83%BD%E6%AD%A3%E5%B8%B8%E5%90%AF%E5%8A%A8.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM