When configuring the listener to listen on TCP/IP, you should enter the default port of 1521. If you do not, you must configure the LOCAL_LISTENER parameter in theinitialization parameter file and resolve the listener name through a naming method.
参见官方的说明:
http://docs.oracle.com/cd/E11882_01/server.112/e25513/initparams118.htm#REFRN10082
LOCAL_LISTENER
specifies a network name that resolves to an address or address list of Oracle Net local listeners (that is, listeners that are running on the same machine as this instance). The address or address list is specified in the TNSNAMES.ORA
file or other address repository as configured for your system.
例子1
创建2个监听服务,Listener1,Listener2,默认状态下,只有Listener1可以监听到现有的数据库服务,Listener2不能监听到数据库服务。
listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0.3.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora11gr2.sannet.net)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = ora11gr2.sannet.net)(PORT = 1530))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
LISTENER2 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora11gr2.sannet.net)(PORT = 1540))
)
)
ADR_BASE_LISTENER2 = /u01/app/oracle
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER = ON
tnsname.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0.3.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORA11G =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora11gr2.sannet.net)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = ora11gr2.sannet.net)(PORT = 1530))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORA11G)
)
)
ORA11G2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora11gr2.sannet.net)(PORT = 1540))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORA11G)
)
)
默认状态下,这里只能看见Listener1在起监听,而Listener2没有生效。
ora11gr2.sannet.net | ORA11G | /u01/app/oracle/product/11.2.0.3.0/db_1/network/admin > lsnrctl status LISTENER
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 13-NOV-2012 15:08:38
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ora11gr2.sannet.net)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 13-NOV-2012 15:07:52
Uptime 0 days 0 hr. 0 min. 46 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0.3.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/ora11gr2/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11gr2.sannet.net)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11gr2.sannet.net)(PORT=1530)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "ORA11G" has 1 instance(s).
Instance "ORA11G", status READY, has 1 handler(s) for this service...
Service "ORA11GXDB" has 1 instance(s).
Instance "ORA11G", status READY, has 1 handler(s) for this service...
The command completed successfully
ora11gr2.sannet.net | ORA11G | /u01/app/oracle/product/11.2.0.3.0/db_1/network/admin > lsnrctl status LISTENER2
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 13-NOV-2012 15:08:42
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ora11gr2.sannet.net)(PORT=1540)))
STATUS of the LISTENER
------------------------
Alias LISTENER2
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 13-NOV-2012 15:08:02
Uptime 0 days 0 hr. 0 min. 40 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0.3.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/ora11gr2/listener2/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11gr2.sannet.net)(PORT=1540)))
The listener supports no services
The command completed successfully
local_listener,必须是两个网络名称必须与tnsname.ora中的一致,否则另外一个监听服务无法生效。
SQL> alter system set local_listener='ORA11G','ORA11G2';
System altered.
ora11gr2.sannet.net | ORA11G | /u01/app/oracle/product/11.2.0.3.0/db_1/network/admin > lsnrctl status LISTENER
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 13-NOV-2012 15:09:10
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ora11gr2.sannet.net)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 13-NOV-2012 15:07:52
Uptime 0 days 0 hr. 1 min. 17 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0.3.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/ora11gr2/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11gr2.sannet.net)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11gr2.sannet.net)(PORT=1530)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "ORA11G" has 1 instance(s).
Instance "ORA11G", status READY, has 1 handler(s) for this service...
Service "ORA11GXDB" has 1 instance(s).
Instance "ORA11G", status READY, has 1 handler(s) for this service...
The command completed successfully
ora11gr2.sannet.net | ORA11G | /u01/app/oracle/product/11.2.0.3.0/db_1/network/admin > lsnrctl status LISTENER2
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 13-NOV-2012 15:09:11
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ora11gr2.sannet.net)(PORT=1540)))
STATUS of the LISTENER
------------------------
Alias LISTENER2
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 13-NOV-2012 15:08:02
Uptime 0 days 0 hr. 1 min. 9 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0.3.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/ora11gr2/listener2/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11gr2.sannet.net)(PORT=1540)))
Services Summary...
Service "ORA11G" has 1 instance(s).
Instance "ORA11G", status READY, has 1 handler(s) for this service...
Service "ORA11GXDB" has 1 instance(s).
Instance "ORA11G", status READY, has 1 handler(s) for this service...
The command completed successfully
这里2个监听都已经生效。
多个监听服务的应用案例
当外网用户通过目标地址映射NAT的方式访问内网中的Oracle数据库,需要通过将Oracle内网地址端口映射成外网地址端口,但这时外网客户端往往无法直接通过1521进行连接,即使将1521映射成其他端口也不行。必须在当前监听添加额外端口,或再次建立一个监听服务,总之只要将监听端口地址改变为1521外的地址,然后使用修改后的监听端口(即1521外),即可通过外网连接数据库。
具体情形如下
LISTENER 1521 -> 1521 失败
LISTENER 1521 -> 1530 失败
LISTENER 1530 -> 1530 成功
LISTENER2 1540 -> 1540 成功