Oracle 监听器配置

Oracle数据库通过监听器与客户端建立连接,监听器程序由一个Oracle文件进行管理,文件名为listener.ora,Linux系统下存放于$ORACL_HOME/network/admin目录下。监听器必须运行在Oracle数据库服务器上,数据库服务通过动态注册或静态注册两种方式注册到监听器程序后,客户端即可通过监听器访问对应的数据库。

一、监听器配置

如下为一段监听文件的配置,有配置可以LISTENER采用TCP协议,数据库地址为192.168.0.9,默认端口为1521。如要新增监听器,可以直接修改该文件添加。

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.9)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

监听器常用命令

Oralce使用lsnrct命令完成监听器程序的日常管理,常用命令有
lsnrctl status   #查看监听器状态 
lsnrctl start     #启动监听器
lsnrctl stop      #停止监听程序

二、动态注册

查看监听器状态:

[oracle@centos6 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-SEP-2018 08:19:45

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.9)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                11-SEP-2018 08:19:39
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/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.9)(PORT=1521)))
The listener supports no services
The command completed successfully

由上述信息可知监听器没有任何服务注册过来,可以通过修改local_listener参数让数据库动态注册到监听器上,例子如下:

SQL> alter system set
  2  local_listener='(address_list=(address=(protocol=tcp)(host=192.168.0.9)(port=1521)))';

System altered.

改参数已经修改立即生效,此时查看系统中的local_listener指和监听器状态如下:

SQL> show parameter local_listener;

NAME				     TYPE
------------------------------------ ---------------------------------
VALUE
------------------------------
local_listener			     string
(address_list=(address=(protoc
ol=tcp)(host=192.168.0.9)(port
=1521)))
[oracle@centos6 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-SEP-2018 08:30:55

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.9)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                11-SEP-2018 08:19:39
Uptime                    0 days 0 hr. 11 min. 16 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/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.9)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully

由上述信息可知数据库服务已经注册过来了。

三、静态注册

先执行如下代码停止系统自动注册

SQL> alter system set 
  2  local_listener='';

System altered.

此时系统监听状态如下

[oracle@centos6 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-SEP-2018 08:35:26

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.9)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                11-SEP-2018 08:19:39
Uptime                    0 days 0 hr. 15 min. 47 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/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.9)(PORT=1521)))
The listener supports no services
The command completed successfully

静态注册是间数据库信息直接写到监听器配置文件中,当监听器启动时就会自动注册数据库服务,达道静态注册的效果。需要注意的是,采用静态注册方式,在修改监听器配置文件后,需要重启监听器配置才能生效。具体配置参考如下例子:

[oracle@centos6 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 = 192.168.0.9)(PORT = 1521))
    )
  )
SID_LIST_LISTENER=
  (SID_LIST=
            (SID_DESC=
                 (SID_NAME=orcl)
                 (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
                 (GLOBAL_DBNAME=orcl)
            )
  )
ADR_BASE_LISTENER = /u01/app/oracle

重启监听程序后,查看监听器状态:

[oracle@centos6 admin]$ lsnrctl stop

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-SEP-2018 08:39:34

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.9)(PORT=1521)))
The command completed successfully
[oracle@centos6 admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-SEP-2018 08:39:44

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.9)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.9)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                11-SEP-2018 08:39:44
Uptime                    0 days 0 hr. 0 min. 0 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/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.9)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

由上述信息可知,监听器已正常启动起来。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.