在運作lsnrctl指令的status時,常會看到如下傳回值:
服務“test”包含1個例程。 例程"mydata",狀态 UNKOWN,包含此服務的一個處理程式。。。 服務"a"包含1個例程。 例程"mydata",狀态 READY,包含此服務的一個處理程式。。。
這裡的,狀态UNKOWN即表明為靜态注冊(手動填寫參數);
狀态為READY的記錄,表明為動态注冊(listener.ora參數由PMON程序自動從參數檔案擷取);
一、靜态注冊 監聽配置中,資料庫服務中的全局資料庫名,可以寫任意内容,與資料庫無關,隻要保證SID正确即可連上資料庫。
由于靜态注冊,參數是手動靜态添加,與資料庫無關。資料庫無法确認監聽是否正确配置。是以,lsnrctl中的status顯示狀态為unkown。即不保證能連通資料庫。
注意:靜态注冊監聽,用戶端在配置tnsnames.ora服務命名時,“(Oracle 8i或更高版本)服務名”裡填寫内容要與服務端靜态注冊監聽器時的全局資料庫名一緻。否則,無法連通。
lsnrctl中顯示如下
服務“test”包含1個例程。 例程“mydata”,狀态UNKOWN,包含此服務的一個處理程式。。。
test即從監聽配置過程,資料庫服務中的“全局資料庫名”讀到的值(即配置檔案中GLOBAL_DBNAME的值),“mydata”是從監聽配置中,資料庫服務中SID讀到的值(即SID_NAME的值)。
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = test ) (ORACLE_HOME = /orahome/oracle/product/10.2.0/db_1) (SID_NAME = mydata ) ) )
用戶端在配置tnsname時,服務名(SERVICE_NAME)即為test。否則,連接配接不到資料庫。
ABC = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.23)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME =
test ) ) )
這裡的ABC,為服務命名。可以為任意值,在用戶端連接配接伺服器時,填寫的主機字元串,即為此服務命名ABC。
二、動态注冊
1、預設的動态注冊
pmon在資料庫啟動到mount或open時,動态從參數檔案中讀取service_names值。service_names可以為多個值。
service_names預設為dbca建立資料庫時的全局資料庫名。
設定參數service_names為'a,b,c',指令如下:
alter system set service_names='a,b,c';
則:
lsnrctl狀态如下:
服務“test”包含1個例程。 例程"mydata",狀态 UNKOWN,包含此服務的一個處理程式。。。 服務"a"包含1個例程。 例程"mydata",狀态 READY,包含此服務的一個處理程式。。。 服務"b"包含1個例程。 例程"mydata",狀态 READY,包含此服務的一個處理程式。。。 服務"c"包含1個例程。 例程"mydata",狀态 READY,包含此服務的一個處理程式。。。 服務 "mydata.ccddt.cn" 包含一個例程。 例程"mydata",狀态 READY, 包含此服務的一個處理程式。。。
以上服務名a, b, c, mydata.ccddt.cn都為READY,為動态注冊。
這裡多了最後一條"mydata.ccddt.cn",是PMON預設動态注冊到監聽器内的。
注意:不管參數service_names為何值,pmon都會自動以全局資料庫名(這裡為mydata.ccddt.cn)為服務名,動态注冊一個監聽。
預設情況下,若啟用動态注冊監聽,端口号必須為1521。若啟用其他端口的動态監聽注冊,必須要做相關配置。
通過檢視v$session,狀态為SYS$USERS的連接配接為通過靜态注冊監聽連接配接到伺服器。
2、自定義端口的動态監聽注冊
若要啟用非預設端口1521的動态監聽注冊,預設狀态,Oracle不會進行動态注冊。要啟用動态注冊,必須設定local_listener參數。并在服務端配置tnsnames.ora指定監聽參數,或者直接通過修改local_listener指定監聽參數。步驟如下:
1)服務端
netmgr,配置監聽程式,監聽端口為1525(非預設端口)
儲存配置
2)、指定監聽參數 (1)法1:直接通過修改local_listener參數指定
SQL> alter system set LOCAL_LISTENER=' (ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.23)(PORT=1525))';
System altered
SQL> alter system register
System altered (2)法2: 在Oracle伺服器端建立$ORACLE_HOME/network/admin/tnsnames.ora。解析檔案,位置并填入如下内容
mytest = (DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS=(PROTOCOL=TCP)(HOST = 192.168.1.23)(PORT = 1525))
)
)
這裡的mytest也可以根據自己需要,修改為其他字元串。如a或b等。 設定參數,指定通過tnsnames.ora内的資訊指定監聽參數 SQL> alter system set local_listener=mytest;
System altered SQL> alter system register;
3、檢視監聽器狀态
LSNRCTL> status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.23)(PORT=1525)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 15-MAR-2011 10:43:47
Uptime 0 days 0 hr. 0 min. 56 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /orahome/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /orahome/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oraserver)(PORT=1525)))
Services Summary...
Service "a" has 1 instance(s).
Instance "mydata", status READY, has 1 handler(s) for this service...
Service "b" has 1 instance(s).
Instance "mydata", status READY, has 1 handler(s) for this service...
Service "c" has 1 instance(s).
Instance "mydata", status READY, has 1 handler(s) for this service...
Service "mydata" has 1 instance(s).
Instance "mydata", status READY, has 1 handler(s) for this service...
Service "mydataXDB" has 1 instance(s).
Instance "mydata", status READY, has 1 handler(s) for this service...
Service "mydata_XPT" has 1 instance(s).
Instance "mydata", status READY, has 1 handler(s) for this service...
The command completed successfully
1.jpg
靜态注冊:通過解析listene.ora檔案
動态注冊:由PMON程序動态注冊至監聽中
在沒有listener.ora配置檔案的情況下,如果啟動監聽,則監聽為動态注冊。用圖形化netca建立的監聽,預設也為動态注冊
1.靜态注冊
listener.ora檔案,監聽的配置檔案,靜态注冊讀取該檔案,動态注冊,不必要
可以通過netca工具建立,也可以手動編輯。典型的listener.ora檔案内容:
LISTENER_PHAMR = |
(DESCRIPTION = |
(ADDRESS = (PROTOCOL = TCP)(HOST = phamrdb1-vip)(PORT = 1521)) |
) SID_LIST_LISTENER_PHALR = |
(SID_LIST = |
(SID_DESC = |
(GLOBAL_DBNAME = phalr) |
(ORACLE_HOME = /oracle/product/11.2.0) |
(SID_NAME = phalr) |
) |
) |
listener.ora檔案兩大子產品:
LISTENER子產品:監聽名字、連接配接協定、監聽主機、監聽端口等基本配置資訊
SID_LIST_LISTENER子產品:配置監聽的靜态注冊特性,包含資料庫服務名、ORACLE_HOME、執行個體名等資訊。
注意:SID_NAME,就是資料庫執行個體名,在Linux環境大小寫敏感
GLOBAL_DBNAME就是資料庫服務名,可以省略,預設和SID_NAME保持一緻,也可以不一緻。
ORACLE_HOME,預設和$ORACLE_HOME環境變量保持一緻。Windows,該參數無效,取自系統資料庫。
靜态注冊,監聽不知道執行個體的具體狀态,是以監聽啟動之初檢視執行個體資訊,其狀态資訊顯示為UNKNOWN.例如:
[email protected]: /home/oracle> lsnrctl status LISTENER_PHAMR LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 17-NOV-2016 17:17:37 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=phamrdb1-vip)(PORT=1521))) |
STATUS of the LISTENER |
------------------------ |
Alias LISTENER_PHAMR |
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production |
Start Date 01-OCT-2016 14:12:51 |
Uptime 47 days 3 hr. 4 min. 45 sec |
Trace Level off |
Security ON: Local OS Authentication |
SNMP OFF |
Listener Parameter File /oracle/product/11.2.0/network/admin/listener.ora |
Listener Log File /oracle/diag/tnslsnr/phamrdb1/listener_phamr/alert/log.xml |
Listening Endpoints Summary... |
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.178.1.64)(PORT=1521))) |
Services Summary... |
Service "phamr" has 1 instance(s). 監聽狀态中的服務名 |
Instance "phamr", status UNKNOWN, has 1 handler(s) for this service... 監聽狀态中的執行個體名 |
The command completed successfully |
2,動态注冊
在動态注冊監聽的環境中,listener.ora檔案可以不包括目前資料庫的執行個體資訊,是以這個檔案不必要。
執行個體啟動時,會由Oracle PMON程序将資料庫執行個體資訊動态注冊至監聽上。
當Oracle執行個體關閉時,會再次由PMON程序自動從監聽裡面撤銷目前執行個體資訊。
是以,要實作動态注冊,資料庫的執行個體至少要處于nomount狀态
監聽動态注冊時的執行個體狀态:來自PMON程序動态注冊時的執行個體狀态,一般有3種狀态:READY、BLOCKED和RESTRICED
READY:表示資料庫執行個體已經處于mount或者open狀态,可以接受用戶端連接配接
BLOCKED:表示資料庫執行個體還處于nomount狀态或者該執行個體類型為ASM執行個體,不接受用戶端連接配接,如果這時候用戶端去連
接資料庫會報ora-12528錯誤
RESTRICED:表示資料庫處于RESTRICED模式,不接受普通權限的遠端用戶端連接配接,如果這時候用戶端去連接配接資料庫會報
ora-12526錯誤
oracle@fsdata: /oracle/product/11.2.0/network/admin> lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 17-NOV-2016 16:01:43 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) |
STATUS of the LISTENER |
------------------------ |
Alias LISTENER |
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production |
Start Date 17-NOV-2016 15:57:23 |
Uptime 0 days 0 hr. 4 min. 19 sec |
Trace Level off |
Security ON: Local OS Authentication |
SNMP OFF |
Listener Log File /oracle/diag/tnslsnr/fsdata/listener/alert/log.xml |
Listening Endpoints Summary... |
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=fsdata)(PORT=1521))) |
Services Summary... |
Service "FSDATA" has 1 instance(s). |
Instance "FSDATA", status READY, has 1 handler(s) for this service... |
Service "FSDATAXDB" has 1 instance(s). |
Instance "FSDATA", status READY, has 1 handler(s) for this service... |
The command completed successfully |
oracle@fsdata: /oracle/product/11.2.0/network/admin> lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 17-NOV-2016 15:58:47 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) |
STATUS of the LISTENER |
------------------------ |
Alias LISTENER |
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production |
Start Date 17-NOV-2016 15:57:23 |
Uptime 0 days 0 hr. 1 min. 23 sec |
Trace Level off |
Security ON: Local OS Authentication |
SNMP OFF |
Listener Log File /oracle/diag/tnslsnr/fsdata/listener/alert/log.xml |
Listening Endpoints Summary... |
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=fsdata)(PORT=1521))) |
Services Summary... |
Service "FSDATA" has 1 instance(s). |
Instance "FSDATA", status BLOCKED, has 1 handler(s) for this service... |
The command completed successfully |
執行個體既可以動态注冊,同時靜态注冊,狀态分别顯示為READY和UNKNOWN
oracle@fsdata: /oracle/product/11.2.0/network/admin> lsnrctl status LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 17-NOV-2016 17:50:14 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=fsdata)(PORT=1521))) |
STATUS of the LISTENER |
------------------------ |
Alias LISTENER |
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production |
Start Date 17-NOV-2016 15:57:23 |
Uptime 0 days 1 hr. 52 min. 50 sec |
Trace Level off |
Security ON: Local OS Authentication |
SNMP OFF |
Listener Parameter File /oracle/product/11.2.0/network/admin/listener.ora |
Listener Log File /oracle/diag/tnslsnr/fsdata/listener/alert/log.xml |
Listening Endpoints Summary... |
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=fsdata)(PORT=1521))) |
Services Summary... |
Service "FSDATA" has 2 instance(s). |
Instance "FSDATA", status UNKNOWN, has 1 handler(s) for this service... |
Instance "FSDATA", status READY, has 1 handler(s) for this service... |
Service "FSDATAXDB" has 1 instance(s). |
Instance "FSDATA", status READY, has 1 handler(s) for this service... |
The command completed successfully |
3.監聽的常用指令
lsnrctl start [listener_name]
lsnrctl stop [listener_name]
lsnrctl status [listener_name]
lsnrctl service [listener_name]
lsnrctl reload [listener_name]
4.監聽的别名
監聽預設名字是LISTENER,可以配置别名
[email protected]: /dump> ps -ef | grep tnslsnr | grep -v grep
oracle 29598 1 0 15:57 ? 00:00:00 /oracle/product/11.2.0/bin/tnslsnr LISTENER -inherit
oracle@phamrdb1: /home/oracle> ps -ef | grep tnslsnr| grep -v grep
oracle 38300 1 0 Oct01 ? 06:21:54 /oracle/product/11.2.0/bin/tnslsnr LISTENER_PHAMR –inherit