动态监听配置示例

一.listener.ora的配置:

这里使用默认的即可

[oracle@bys001 ~]$ cd $ORACLE_HOME/network/admin
[oracle@bys001 admin]$ pwd
/u01/app/oracle/product/11.2.0/dbhome_1/network/admin
[oracle@bys001 admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = bys001.oel.com)(PORT = 1521))
    )
  )
ADR_BASE_LISTENER = /u01
动态监听中服务名和实例名:验证监听中实例和服务名依赖的参数:
监听中实例名:实例如果没有设定instance_name,将使用db_name初始化参数值。
监听中服务名:如果没有设定service_names,将拼接db_name和db_domain参数值来注册监听。

三.查看监听状态:

[oracle@bys001 admin]$ lsnrctl start

1.数据库未启动时监听状态:

[oracle@bys001 admin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-SEP-2013 16:01:57
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bys001.oel.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                05-SEP-2013 16:01:52
Uptime                    0 days 0 hr. 0 min. 5 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/diag/tnslsnr/bys001/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bys001.oel.com)(PORT=1521)))
The listener supports no services

The command completed successfully

2.数据库启动后监听状态:

[oracle@bys001 admin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Sep 5 16:03:21 2013
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to an idle instance.
SYS@bys1>startup;
ORACLE instance started.

Total System Global Area  631914496 bytes
Fixed Size                  1338364 bytes
Variable Size             264242180 bytes
Database Buffers          360710144 bytes
Redo Buffers                5623808 bytes
Database mounted.
Database opened.
SYS@bys1>exit
[oracle@bys001 admin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-SEP-2013 16:04:16
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bys001.oel.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                05-SEP-2013 16:01:52
Uptime                    0 days 0 hr. 2 min. 24 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/diag/tnslsnr/bys001/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bys001.oel.com)(PORT=1521)))
Services Summary...
Service "bys1" has 1 instance(s).
  Instance "bys1", status READY, has 1 handler(s) for this service...
Service "bys1XDB" has 1 instance(s).
  Instance "bys1", status READY, has 1 handler(s) for this service...
The command completed successfully

验证监听中实例和服务名依赖的参数:

监听中实例名:实例如果没有设定instance_name,将使用db_name初始化参数值。
监听中服务名:如果没有设定service_names,将拼接db_unique_name和db_domain参数值来注册监听,(service_names优先级高),验证如下:
  ----(很多文档里写的是db_name和db_domain这是不准确的)
详见: 验证service_names、db_name、db_unique_name在注册动态监听服务名时的作用

##################################################

SYS@bys1>show parameter instance_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
instance_name                        string      bys1
SYS@bys1>show parameter service_names

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      bys1
SYS@bys1>alter system set service_names=bystest;

System altered.
SYS@bys1>exit

[oracle@bys001 admin]$ lsnrctl status  --不需要重启监听直接查看状态就能看到修改后的service_names已经动态注册到监听。
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-SEP-2013 16:11:33
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bys001.oel.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                05-SEP-2013 16:01:52
Uptime                    0 days 0 hr. 9 min. 42 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/diag/tnslsnr/bys001/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bys001.oel.com)(PORT=1521)))
Services Summary...
Service "BYSTEST" has 1 instance(s).
  Instance "bys1", status READY, has 1 handler(s) for this service...
Service "bys1" has 1 instance(s).
  Instance "bys1", status READY, has 1 handler(s) for this service...
Service "bys1XDB" has 1 instance(s).
  Instance "bys1", status READY, has 1 handler(s) for this service...
The command completed successfully

3.如果选择设置service_names值,可以使用指定的名称(比如 orcl.oracle.com)或缩写的名称(比如orcl)。

如果选择缩写的名称并设置了db_domain参数,注册到监听器中的服务将是 service_name值和db_domain值的拼接。
BYS@bys1>alter system set  db_domain='bysa.com' scope=spfile;
System altered.
BYS@bys1>show parameter db_domain
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_domain                            string
BYS@bys1>conn / as sysdba
Connected.
SYS@bys1>shutdown immediate;
SYS@bys1>startup
ORACLE instance started.
Total System Global Area  631914496 bytes
Fixed Size                  1338364 bytes
Variable Size             264242180 bytes
Database Buffers          360710144 bytes
Redo Buffers                5623808 bytes
Database mounted.
Database opened.
此时查看监听状态:

[oracle@bys001 oradiag_oracle]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-SEP-2013 22:30:51
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bys001.oel.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                05-SEP-2013 16:37:05
Uptime                    0 days 5 hr. 53 min. 45 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/diag/tnslsnr/bys001/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bys001.oel.com)(PORT=1521)))
Services Summary...
Service "bys1.bysa.com" has 1 instance(s).
  Instance "bys1", status READY, has 1 handler(s) for this service...
Service "bys1XDB.bysa.com" has 1 instance(s).
  Instance "bys1", status READY, has 1 handler(s) for this service...
The command completed successfully

3.TNS文件的配置

[oracle@bys001 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

bys1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)( HOST = 192.168.1.211)( PORT =1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      ( SERVICE_NAME = bys1)
    )
  )

4.SQLPLUS登陆测试

[oracle@bys001 admin]$ sqlplus bys/bys@bys1
SQL*Plus: Release 11.2.0.1.0 Production on Thu Sep 5 21:27:01 2013
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
BYS@bys1>select name from v$database;
NAME
---------
BYS1

你可能感兴趣的:(动态监听配置示例)