典型的監聽配置模板:
創建監聽有多重方式:(1)netca (2)netmgr (3)手工編輯listener.ora文件等;
下面是一個監聽配置的標准模板:
配置文件中的關鍵之解析:
(1) PROTOCOL指的是監聽接收鏈接的協議;
(2) HOST是指的監聽運行的主機或者IP地址;
(3) PORT指的是監聽運行的端口。
(4) SID_NAME指的是監聽服務的實例名。
(5) GLOBAL_NAME指的是監聽服務的服務名;
(6) ORACLE_HOME指的是監聽服務的$ORACLE_HOME;
監聽支持的協議參數:
注意:為增加系統的可用性,在HA環境下,建議將listener.oora關鍵字HOST配置成主機名;
其中的SID_NAME等於數據庫參數INSTANCE_NAME的;
然後再看一下tnsnames的文件內容:
我們需要關注的是tns的service name是等於listener文件中的global_dbname的;
注意tnsping:tnsping只是發送鏈接包(NSPTCN)至服務端監聽上,所以即使tnsping監聽正常,客戶端也不一定能連接到數據庫庫服務器;tnsping主要檢查的是遠程監聽是否啟動在相應的ip地址和端口上,並不檢查監聽中的實力服務和句柄(handle);
靜態配置內容:
在靜態注冊環境下,在listener.ora文件中主要配置一下內容
(1) SID_NAME:數據庫實例名,其值需和數據庫參數INSTANCE_NAME保持一致。
(2) GLOBAL_DBNAME:數據庫服務名,可以省略,默認和SID_NAME保持一致。
(3) ORACLE_HOME:實力運行的ORACLE_HOME目錄,在unix和linux環境下,該參數可以省略,默認和環境變量¥ORACLE_HOME保持一致;
以下為實例名為felix和pyf靜態注冊配置:(注意:在監聽靜態注冊的情況下,即使數據庫實例已關閉,具有sysdba權限的業務用戶仍然可以通過監聽遠程連接到數據庫中進行維護);
[oracle@felix admin]$ vi listener.ora
# listener.ora Network Configuration File:/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION =
(ADDRESS= (PROTOCOL = TCP)(HOST = felix)(PORT = 1521))
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = develop)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = felix )
)
(SID_DESC =
(GLOBAL_DBNAME = pyfeng)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_2)
(SID_NAME = pyf )
)
)
ADR_BASE_LISTENER = /u01/app/oracle
11:36:53 SQL>show parameter service
NAME TYPE VALUE
---------------------------------------------------------- ------------------------------
service_names string felix
[oracle@felix admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File:/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
DEVELOP_p =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.17)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = develop)
)
)
[oracle@felix admin]$
特別注意:如果listener.ora設置了GLOBAL_DBNAME參數,呢麼在RAC環境下,TAF和connect-time failover特性將失效;
注意監聽狀態:
[oracle@felixadmin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Productionon 12-AUG-2014 14:01:58
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=felix)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 -Production
Start Date 12-AUG-2014 11:25:44
Uptime 0 days 2 hr. 36 min. 13 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/felix/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=felix)(PORT=1521)))
Services Summary...
Service "develop" has 1 instance(s).
Instance"felix", status UNKNOWN, has 1 handler(s) for this service...
Service "felix" has 1 instance(s).
Instance"felix", status BLOCKED, has 1 handler(s) for this service...
The command completed successfully
[oracle@felix admin]$