实现Oracle非1521标准端口动态注册


动态注册dynamic registry和静态注册是Oracle实例和监听器之间建立联系的重要方式。从现在趋势看,默认监听器+动态注册已经成为默认Oracle标准配置。在一些场景下,处于安全的原因可能需要修改标准监听配置和注册方式。本篇主要介绍如何实现非1521端口进行动态注册方法。

1、默认监听与1521端口

Oracle Net Service核心三个配置文件:listener.ora、tnsnames.ora和sqlnet.ora。其中,listener.ora文件为监听器相关信息的配置文件。关于监听器个性化参数内容,均在该文件中设置。

在默认安装情况下,我们一般在$ORACLE_HOME/network/admin目录中是可以没有listener.ora文件的。

[oracle@aaalife admin]$ ls -l

-rw-r-----. 1 oracle oinstall  332 Aug  7 01:44 tnsnames.ora

此时,Oracle会在1521默认端口,支持一个默认配置文件的监听器程序。并且,该程序支持动态注册功能。

[oracle@aaalife admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-SEP-2015 01:08:10

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

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

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

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

STATUS of the LISTENER

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

Alias                    LISTENER

Version                  TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                07-SEP-2015 01:08:10

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level              off

Security                  ON: Local OS Authentication

SNMP                      OFF

--此处没有说明监听器配置文件路径。

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

Listening Endpoints Summary...

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

The listener supports no services

The command completed successfully

对注册行为另一端的Oracle实例而言,默认情况下Oracle实例会进行动态注册动作,会向1521端口监听的监听程序进行注册动作。

[oracle@aaalife admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-SEP-2015 01:14:54

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

Start Date                07-SEP-2015 01:08:10

Uptime                    0 days 0 hr. 6 min. 43 sec

Trace Level              off

Security                  ON: Local OS Authentication

SNMP                      OFF

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

Listening Endpoints Summary...

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

Services Summary...

Service "aaadb" has 1 instance(s).

Instance "aaadb", status READY, has 1 handler(s) for this service...

Service "aaadbXDB" has 1 instance(s).

Instance "aaadb", status READY, has 1 handler(s) for this service...

The command completed successfully

2、非默认端口监听器

在一些安全需求场景下,我们会被要求修改监听端口到非1521端口,从而避免被扫描入侵。其实,这对于攻击扫描程序来讲,意义不大,因为一般黑客攻击都会扫描所有端口。

如果我们需要修改端口号,就必须创建专门的listener.ora文件内容来进行配置。下面内容可以配置一个非标准监听器程序。

[oracle@aaalife 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.

MY_LISTENER =

(DESCRIPTION_LIST =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1531))

(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1531))

)

)

ADR_BASE_LISTENER = /u01/app/oracle

配置文件中,包括一个1531端口的监听程序。下面查看监听器情况。

[oracle@aaalife admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-SEP-2015 01:27:53

Copyright (c) 1991, 2013, 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.4.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/aaalife/listener/alert/log.xml

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

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

STATUS of the LISTENER

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

Alias                    LISTENER

Version                  TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                07-SEP-2015 01:27:53

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/aaalife/listener/alert/log.xml

Listening Endpoints Summary...

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

The listener supports no services

The command completed successfully

默认显示的还有1521端口监听程序。同时,发现其实当前服务器上是由两个监听器运行的。

[oracle@aaalife admin]$ lsnrctl status listener

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-SEP-2015 01:30:13

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

Start Date                07-SEP-2015 01:27:53

Uptime                    0 days 0 hr. 2 min. 19 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/aaalife/listener/alert/log.xml

Listening Endpoints Summary...

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

Services Summary...

Service "aaadb" has 1 instance(s).

Instance "aaadb", status READY, has 1 handler(s) for this service...

Service "aaadbXDB" has 1 instance(s).

Instance "aaadb", status READY, has 1 handler(s) for this service...

The command completed successfully

[oracle@aaalife admin]$

[oracle@aaalife admin]$ lsnrctl status my_listener

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-SEP-2015 01:30:29

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1531)))

STATUS of the LISTENER

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

Alias                    LISTENER

Version                  TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                07-SEP-2015 01:17:52

Uptime                    0 days 0 hr. 12 min. 37 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/aaalife/listener/alert/log.xml

Listening Endpoints Summary...

(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1531)))

(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1531)))

The listener supports no services

The command completed successfully

上面信息显示出几个细节:

ü  我们在listener.ora文件中配置了一个自定义监听器my_listener,监听1531端口。但是系统当前默认监听器依然存在,并且可运行,在1521端口。my_listener监听器运行在1531端口;

ü  Oracle实例动态注册动作是在1521端口的监听程序上进行的,1531端口并没有被注册;

默认监听器的问题好解决,只要我们只保留一个监听即可。那么,如何让Oracle实例在1531端口进行注册,不在1521端口进行注册呢?

解决的方法就是使用local_listener配置参数。默认情况下,该参数为空。

SQL> show parameter listener;

NAME                                TYPE        VALUE

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

listener_networks                    string

local_listener                      string

remote_listener                      string

该参数用于明确指定Oracle实例向哪一个监听器上进行注册动作。通常对于非标准端口注册,都需要将注册监听信息修改参数。

SQL> show parameter local

NAME                                TYPE        VALUE

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

local_listener    string      (ADDRESS_LIST=(Address=(Protoc                                                ol=tcp)(HOST=AAALIFE)(Port=1531)))

log_archive_local_first              boolean    TRUE

parallel_force_local                boolean    FALSE

注意:该参数local_listener修改范围支持both方式,立即生效不需要重新启动实例。

此时,监听器状态如下:

[oracle@aaalife dbs]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-SEP-2015 02:32:25

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

Start Date                07-SEP-2015 01:27:53

Uptime                    0 days 1 hr. 4 min. 32 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/aaalife/listener/alert/log.xml

Listening Endpoints Summary...

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

The listener supports no services

The command completed successfully

[oracle@aaalife dbs]$ lsnrctl status my_listener

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-SEP-2015 02:32:33

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1531)))

STATUS of the LISTENER

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

Alias                    LISTENER

Version                  TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                07-SEP-2015 01:17:52

Uptime                    0 days 1 hr. 14 min. 41 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/aaalife/listener/alert/log.xml

Listening Endpoints Summary...

(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1531)))

(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1531)))

Services Summary...

Service "aaadb" has 1 instance(s).

Instance "aaadb", status READY, has 1 handler(s) for this service...

Service "aaadbXDB" has 1 instance(s).

Instance "aaadb", status READY, has 1 handler(s) for this service...

The command completed successfully

实例向1531端口进行动态注册了,原有1521默认监听器没有注册信息。

那么,还有一个问题,就是local_listener设置值。该值采用括号表达式进行书写,是Oracle Net Service内部使用的一种方式。从管理角度看,这种策略不是很好的方法。我们直接将端口编号书写在数据库参数中,不但容易泄露部署信息,而且在发生迁移、变更动作的时候,这种方式也会有一些问题。

所以,Oracle官方支持监听器别名方法进行配置local_listener。

3、设置监听器别名

一个很有意思的现象是,在local_listener的配置问题上,MOS和网络同仁们的差异是很大的。MOS官方意见是将监听器别名设置上,而网络同仁们无一例外的选择“括号表达式”。

笔者实验的情况是,直接设置监听器别名,Oracle是不认可的。

SQL> alter system set local_listener='my_listener' scope=both;

alter system set local_listener='my_listener' scope=both

*

ERROR at line 1:

ORA-02097: parameter cannot be modified because specified value is invalid

ORA-00119: invalid specification for system parameter LOCAL_LISTENER

ORA-00132: syntax error or unresolved network name 'my_listener'

Oracle不能解析my_listener名称,因为其既不是括号表达式,也不是设置的别名。这里面就比较奇怪,我们分明已经在listener.ora文件中定义了名称。

对00132错误,Oracle官方的解释如下:

[oracle@aaalife admin]$ oerr ora 00132

00132, 00000, "syntax error or unresolved network name '%s'"

// *Cause:  Listener address has syntax error or cannot be resolved.

// *Action: If a network name is specified, check that it corresponds

//          to an entry in TNSNAMES.ORA or other address repository

//          as configured for your system. Make sure that the entry

//          is syntactically correct.

Oracle认为在服务器端的tnsnames.ora文件中,没有能够找到my_listener的对应名称。Tnsnames.ora是我们保存本地连接对应名称的地方,这里是否意味着说此处的别名,是一定在tnsnames.ora文件中进行定义。本地命名别名定义我们是熟悉的。监听器程序别名如何定义?

经过查询Oracle早期文档和治疗,从一个角落找到定义格式和方法。

[oracle@aaalife 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.

MY_LISTENER=

(description=

(address=(protocol=tcp)(host=AAALIFE)(port=1531)))

突发奇想,tnsping命令有解析格式的副作用。是否可以成功呢?

[oracle@aaalife admin]$ tnsping my_listener

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 07-SEP-2015 20:43:58

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

Used parameter files:

Used TNSNAMES adapter to resolve the alias

Attempting to contact (description= (address=(protocol=tcp)(host=AAALIFE)(port=1531)))

OK (0 msec)

解析成功,起码格式上没有大的问题。

SQL> alter system set local_listener='MY_LISTENER' scope=both;

System altered.

SQL> show parameter local;

NAME                                TYPE        VALUE

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

local_listener                      string      MY_LISTENER

log_archive_local_first              boolean    TRUE

parallel_force_local                boolean    FALSE

启动手工注册,查看监听器状态。

SQL> alter system register;

System altered.

[oracle@aaalife admin]$ lsnrctl status my_listener

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-SEP-2015 20:50:47

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1531)))

STATUS of the LISTENER

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

Alias                    my_listener

Version                  TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                07-SEP-2015 19:48:50

Uptime                    0 days 1 hr. 1 min. 59 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/aaalife/my_listener/alert/log.xml

Listening Endpoints Summary...

(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1531)))

(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1531)))

Services Summary...

Service "aaadb" has 1 instance(s).

Instance "aaadb", status READY, has 1 handler(s) for this service...

Service "aaadbXDB" has 1 instance(s).

Instance "aaadb", status READY, has 1 handler(s) for this service...

The command completed successfully

设置成功,监听器状态中my_listener作为别名alias出现在状态信息中。

4、结论

动态注册是我们最常用的注册模式。多个配置文件(Oracle Net Service)、Oracle参数、监听器设置交织相互作用影响,期间又有网络网卡、域名解析等多因素作用,很容易出现问题故障。多实验、多测试,可以帮助我们抽丝剥茧,逐步深入的了解系统,在日常工作中更加游刃有余。

相关内容

    暂无相关文章