当前位置:  数据库>oracle

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

    来源: 互联网  发布时间:2017-06-20

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

动态注册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参数、监听器设置交织相互作用影响,期间又有网络网卡、域名解析等多因素作用,很容易出现问题故障。多实验、多测试,可以帮助我们抽丝剥茧,逐步深入的了解系统,在日常工作中更加游刃有余。


    
 
 

您可能感兴趣的文章:

  • Linux下的Socket通信如何断开连接的端口从而实现重复使用该端口
  • windows 下的PortTunnel 在linux下怎么实现?或者相应的已经实现的软件?端口映射
  • 求教用一个端口能否实现3G视频传输
  • 在linux下能实现多端口映射吗?
  • 怎样编程实现I/O端口的读写?
  • 怎样在TURBO LINUX下实现静态端口映射
  • bind9架设内部dns+硬件防火墙端口映射,不能实现域名解析
  • 在一个socket守护服务进程中,如何实现同时监听两个端口?
  • python判断端口是否打开的实现代码
  • 一般的tcpip实现都会提供ftp,telnet,daytime,以及time等基本服务,linux上提供13端口的daytime服务吗?
  • 我想在服务器端口获得连结上来机子的IP,不知道有什么方法可以实现!!!?
  • 使用python实现扫描端口示例
  • 求助!如何使用同一个套接字和端口实现反复下载
  • 关于使用iptables实现udp端口的nat的问题
  • shell脚本结合iptables防端口扫描的实现
  • Python实现根据指定端口探测服务器/模块部署的方法
  • python实现数通设备端口监控示例
  • 非阻塞connect实现端口扫描的问题-connect提前返回怎么处理?
  • Python实现端口复用实例代码
  • C实现的非阻塞方式命令行端口扫描器源码
  • C++标准库实现 libc++
  • LINUX下用标准C开发,实现拨号上网?
  • 如何用标准c 实现时时的键盘输入
  • 标准C下没有字符处理函数,怎样写一个实现下面功能的函数?
  • C++中用两个标准容器stack,实现一个队列的方法详解
  • java swing标准对话框具体实现
  • 用标准c++实现string与各种类型之间的转换
  • C标准库<assert.h>的实现详解
  •  
    本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
    本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 通过javascript实现DIV居中,兼容各浏览器版本
  • socket实现多文件并发传输,求助多线程实现问题?
  • Python GUI编程:tkinter实现一个窗口并居中代码
  • interface 到底有什么用???实现接口,怎么实现??
  • 通过javascript库JQuery实现页面跳转功能代码
  • 怎么用Jsp实现在页面实现树型结构?
  • sharepoint 2010 使用STSNavigate函数实现文件下载举例
  • 网站重定向用C语言实现iptables,ACL实现
  • php实现socket实现客户端和服务端数据通信源代码
  • 在linux下如何编程实现nslookup命令实现的IP地址和域名互相转换的功能?
  • flash AS3反射实现(describeType和getDefinitionByName)
  • 求在freebsd+Squid下实现pc上网的透明代理的实现方法!给出具体配置方法的高分谢!
  • boost unordered_map和std::list相结合的实现LRU算法
  • linux下如实现与window下的驱动器实现文件共享??
  • c#通过委托delegate与Dictionary实现action选择器代码举例
  • qt如何实现:操作键盘实现数据的滚动?
  • 使用java jdk中的LinkedHashMap实现简单的LRU算法
  • 我想用APPLET实现读取客户端的图片文件,该如何实现?
  • iphone cocos2d 精灵的动画效果(图片,纹理,帧)CCAnimation实现
  • PING是用TCP,还是用UDP来实现的?或是采用其它协议实现的?
  • c语言判断某一年是否为闰年的各种实现程序代码
  • ejb-ql只能 like '?%' 么?我想实现模糊查寻,想实现 like'%?%' 怎么办??


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3