ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 再说Oracle Listener动静态注册

再说Oracle Listener动静态注册

原创 Linux操作系统 作者:realkid4 时间:2012-09-23 21:24:46 0 删除 编辑

 

监听器ListenerOracle Client Process和实例远程建立连接关系的必经之路。借助ListenerClient Process可以实现和一个特定的Server Process建立连接关系,开启Session会话,操作Oracle Instance

 

Oracle体系中,Listener是一个独立的进程。Listener的运行是独立于Oracle实例的。在Windows或者Unix/Linux架构中,监听器都是被实现为一个独立的系统进程Process。监听器在工作中,是侍候在特定的端口Port上,接受Client Process通过Oracle Net协议访问。同时,监听器需要知道所在服务器上的Oracle实例提供的Service Name和对应目录,这个过程,我们称之为“Register”(注册)。

 

对于注册过程,Oracle监听器提供动静态两种注册方法。不同的注册方法有不同的配置方式和特点,也有各自独特的使用场景。本篇就着重介绍一些动静态注册问题。

 

1Listener默认动态监听配置

 

我们的实验从笔者虚拟机的实际配置开始,选择Oracle版本为11gR2

 

 

SQL> select * from v$version;

 

BANNER

------------------------------------------------------

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

PL/SQL Release 11.2.0.1.0 - Production

CORE        11.2.0.1.0         Production

 

 

使用lsnrctl命令查看监听器状态。

 

 

[oracle@bsplinux ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-SEP-2012 15:49:00

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

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bsplinux)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                17-JUL-2012 19:52:13

Uptime                    65 days 19 hr. 56 min. 47 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/network/admin/listener.ora

Listener Log File         /u01/app/diag/tnslsnr/bsplinux/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bsplinux)(PORT=1521)))

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

 

 

status命令参数结果输出中,我们可以看到监听器的工作状态。此时,Listener使用Oracle NET参数文件listener.ora,同时监听器注册两个服务项目,名称为ora11gora11gXDB。从两个服务的READY状态,可以知道使用动态注册方法。

 

我们在操作系统层面查看listener.ora文件。

 

 

[oracle@bsplinux admin]$ pwd

/u01/app/oracle/network/admin

[oracle@bsplinux admin]$ ls -l

total 40

-rw-r--r-- 1 oracle oinstall  288 May 22 21:21 listener1205229PM2122.bak

-rw-r--r-- 1 oracle oinstall  288 May 22 19:57 listener.ora

drwxr-xr-x 2 oracle oinstall 4096 May 22 15:54 samples

-rw-r--r-- 1 oracle oinstall  187 May  9  2007 shrept.lst

-rw-r--r-- 1 oracle oinstall  310 May 22 21:22 tnsnames.ora

 

 

[oracle@bsplinux admin]$ cat listener.ora

# listener.ora Network Configuration File: /u01/app/oracle/network/admin/listener.ora

# Generated by Oracle configuration tools.

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = bsplinux)(PORT = 1521))

    )

  )

 

ADR_BASE_LISTENER = /u01/app

 

 

Oracle Net Service三大配置文件为:listener.orasqlnet.oratnsnames.ora。其中listener.ora定义了监听器信息。在上面的监听器配置信息中,定义了监听器监听端口1521(默认端口)。注意,文件中没有定义与ora11g实例有关的内容。这个就是使用了动态注册机制。

 

2、动态监听

 

所谓动态监听,就是在listener.ora文件中,不需要定义实例Instance具体名称和位置。Oracle实例会在运行之后,由后台进程pmon会周期性的(1-3分钟)到指定端口1521进行状态信息通知。Listener就会自动的进行更新Service情况。

 

在上一个部分,我们已经看到了存在listener.ora文件情况下的动态注册情况。事实上,如果没有listener.ora文件,我们也是可以实现默认的动态注册监听器的功能。

 

首先,我们删除listener.ora文件。

 

 

[oracle@bsplinux admin]$ mv listener.ora listener_bak.ora

[oracle@bsplinux admin]$ ls -l | grep listener.ora

[oracle@bsplinux admin]$

 

 

启动监听器。

 

 

[oracle@bsplinux admin]$ lsnrctl start

 

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-SEP-2012 15:51:50

 

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

 

Starting /u01/app/oracle/bin/tnslsnr: please wait...

 

TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Log messages written to /u01/app/diag/tnslsnr/bsplinux/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bsplinux)(PORT=1521)))

 

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                21-SEP-2012 15:51:51

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Log File         /u01/app/diag/tnslsnr/bsplinux/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bsplinux)(PORT=1521)))

The listener supports no services

The command completed successfully

 

注意,上面的内容中没有Listener Parameter的内容。监听器在1521端口等待。过一分钟左右,注册内容显示。

 

--Pmon存在

[oracle@bsplinux admin]$ ps -ef | grep pmon

oracle   10442 10359  0 15:52 pts/0    00:00:00 grep pmon

oracle   24187     1  0 Sep11 ?        00:02:33 ora_pmon_ora11g

 

[oracle@bsplinux admin]$ lsnrctl status

 

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-SEP-2012 15:52:58

Copyright (c) 1991, 2009, 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.1.0 - Production

Start Date                21-SEP-2012 15:51:51

Uptime                    0 days 0 hr. 1 min. 7 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Log File         /u01/app/diag/tnslsnr/bsplinux/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bsplinux)(PORT=1521)))

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

 

 

动态注册在实际中是非常有用的。pmon后台进程是Oracle实例生死的重要指标,周期性的pmon注册到Listener中,实际上也是实现了一个功能:实例生存状态汇集。

 

当我们的实例崩溃,但是监听器存活的时候,监听器不能受到pmon的周期性注册信息。监听器也就可以实现某种类型的failover

 

但是,动态注册也不是万能的。其中一个问题就是,动态注册只能进行1521的端口注册。如果我们变化端口,就不能实现动态注册方式了。

 

我们修改listener.ora文件中的端口信息,如果使用非1521端口,就必须使用listener.ora配置。

 

 

 

[oracle@bsplinux admin]$ ls -l

total 44

-rw-r--r-- 1 oracle oinstall  288 May 22 21:21 listener1205229PM2122.bak

-rw-r--r-- 1 oracle oinstall  288 May 22 19:57 listener_bak.ora

-rw-r--r-- 1 oracle oinstall  288 Sep 21 15:56 listener.ora

drwxr-xr-x 2 oracle oinstall 4096 May 22 15:54 samples

-rw-r--r-- 1 oracle oinstall  187 May  9  2007 shrept.lst

-rw-r--r-- 1 oracle oinstall  310 May 22 21:22 tnsnames.ora

 

 

--修改参数端口为1522

[oracle@bsplinux admin]$ cat listener.ora

# listener.ora Network Configuration File: /u01/app/oracle/network/admin/listener.ora

# Generated by Oracle configuration tools.

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = bsplinux)(PORT = 1522))

    )

  )

 

ADR_BASE_LISTENER = /u01/app

 

 

启动监听器,使用1522端口。

 

 

[oracle@bsplinux admin]$ lsnrctl start

 

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-SEP-2012 15:58:05

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

 

Starting /u01/app/oracle/bin/tnslsnr: please wait...

 

TNSLSNR for Linux: Version 11.2.0.1.0 - Production

System parameter file is /u01/app/oracle/network/admin/listener.ora

Log messages written to /u01/app/diag/tnslsnr/bsplinux/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bsplinux)(PORT=1522)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bsplinux)(PORT=1522)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                21-SEP-2012 15:58:05

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/network/admin/listener.ora

Listener Log File         /u01/app/diag/tnslsnr/bsplinux/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bsplinux)(PORT=1522)))

The listener supports no services

The command completed successfully

 

 

等待三分钟或者手工进行注册,都不能让1522端口的监听器注册内容。

 

 

--三分钟和手工注册尝试

[oracle@bsplinux admin]$ lsnrctl status

 

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-SEP-2012 16:01:12

 

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

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bsplinux)(PORT=1522)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                21-SEP-2012 15:58:05

Uptime                    0 days 0 hr. 3 min. 6 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/network/admin/listener.ora

Listener Log File         /u01/app/diag/tnslsnr/bsplinux/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bsplinux)(PORT=1522)))

The listener supports no services

The command completed successfully

 

--手工注册监听器

SQL> conn / as sysdba

Connected.

SQL> alter system register;

System altered.

 

[oracle@bsplinux admin]$ lsnrctl status

 

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-SEP-2012 16:02:42

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

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bsplinux)(PORT=1522)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                21-SEP-2012 15:58:05

Uptime                    0 days 0 hr. 4 min. 37 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/network/admin/listener.ora

Listener Log File         /u01/app/diag/tnslsnr/bsplinux/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bsplinux)(PORT=1522)))

The listener supports no services

The command completed successfully

 

 

上面告诉我们,虽然动态注册有很多优势,但是只能使用1521端口。这就会产生很大的限制。从安全角度看,我们通常要避免使用默认端口,防止恶意的端口扫描。

 

那么,我们很多时候,就要选择静态注册方法。

 

3、静态注册

 

静态注册是一种古老的注册手段。简单的说,就是监听器的实例注册信息是直接写在listener.ora文件里的。当监听器启动之后,Oracle会根据配置的listener.ora定义的服务去进行连接匹配。

 

这个过程中,一个重点在于:Oracle的注册信息是写死在文件里面的。监听器并不能像动态注册那样切实知道Oracle实例的情况,所以静态注册的状态取值通常是UNKNOW

 

配置监听器静态注册:

 

 

[oracle@bsplinux admin]$ cat listener.ora

# listener.ora Network Configuration File: /u01/app/oracle/network/admin/listener.ora

# Generated by Oracle configuration tools.

 

SID_LIST_LISTENER =

 (SID_LIST =

   (SID_DESC =

     (GLOBAL_DBNAME = ora11g)

     (ORACLE_HOME = /u01/app/oracle)

     (SID_NAME = ora11g)

   )

 )

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = bsplinux)(PORT = 1522))

    )

  )

 

 

启动监听器:

 

 

[oracle@bsplinux admin]$ lsnrctl start

 

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-SEP-2012 16:38:59

 

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

 

Starting /u01/app/oracle/bin/tnslsnr: please wait...

(篇幅原因,省略……)

Listener Parameter File   /u01/app/oracle/network/admin/listener.ora

Listener Log File         /u01/app/diag/tnslsnr/bsplinux/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bsplinux)(PORT=1522)))

Services Summary...

Service "ora11g" has 1 instance(s).

  Instance "ora11g", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

 

--连接

SQL> conn scott/tiger@ora11g;

Connected.

 

 

静态注册的一个问题,在于监听程序是不知道Oracle实例的真实生存情况。即使实例已经崩溃、关闭,监听器也不能知道这个信息。

 

 

--关闭Oracle服务器

[oracle@bsplinux admin]$ sqlplus /nolog

 

SQL*Plus: Release 11.2.0.1.0 Production on Fri Sep 21 16:48:40 2012

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

 

SQL> conn / as sysdba

Connected.

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL>

 

--监听器依然提供实例信息;

[oracle@bsplinux admin]$ lsnrctl status

 

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-SEP-2012 16:50:19

 

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

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bsplinux)(PORT=1522)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                21-SEP-2012 16:38:59

Uptime                    0 days 0 hr. 11 min. 20 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/network/admin/listener.ora

Listener Log File         /u01/app/diag/tnslsnr/bsplinux/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bsplinux)(PORT=1522)))

Services Summary...

Service "ora11g" has 1 instance(s).

  Instance "ora11g", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

 

 

 

4、静态注册与远程服务器启动

 

静态注册帮助我们解决了一个问题,就是我们如何在Oracle服务器停机的时候,还能够远程通过Oracle Net连接到Oracle,并启动服务器。

 

在动态注册时,我们远程连接到监听器时,监听器是不能识别请求连接的名称的。这就造成我们不能远程登录。使用静态注册,恰恰可能帮助我们实现这个需求。

 

 

C:\Users\Tomas>tnsping ora11gp

 

TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 21-9 -

2012 09:38:25

 

Copyright (c) 1997, 2010, Oracle.  All rights reserved.

 

已使用的参数文件:

D:\oracle\product\11.2.0\client_1\network\admin\sqlnet.ora

 

已使用 TNSNAMES 适配器来解析别名

尝试连接 (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.39.69)(PORT = 1522))) (CONNECT_DATA = (SERVICE_NAME = ora11g)))

OK (0 毫秒)

 

 

使用sqlplus进行连接。

 

 

C:\Users\Tomas>sqlplus /nolog

 

SQL*Plus: Release 11.2.0.1.0 Production on 星期五 9 21 09:38:39 2012

 

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

 

SQL> conn sys/oracle@ora11gp as sysdba

已连接到空闲例程。

SQL> startup

ORACLE 例程已经启动。

 

Total System Global Area  422670336 bytes

Fixed Size                  1336960 bytes

Variable Size             318769536 bytes

Database Buffers           96468992 bytes

Redo Buffers                6094848 bytes

数据库装载完毕。

数据库已经打开。

SQL>

 

 

确定服务器启动。

 

 

[oracle@bsplinux ~]$ ps -ef | grep pmon

oracle   11002     1  0 16:55 ?        00:00:00 ora_pmon_ora11g

oracle   11147 10784  0 17:02 pts/1    00:00:00 grep pmon

 

 

5、结论

 

无论是动态注册,还是静态注册,都是Oracle应对不同场景的解决方案。我们可以针对不同的情况,进行个性化选择。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17203031/viewspace-744876/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
求道~

注册时间:2010-11-30

  • 博文量
    545
  • 访问量
    7814737