千家信息网

修改Oracle默认监听端口

发表于:2025-01-21 作者:千家信息网编辑
千家信息网最后更新 2025年01月21日,我们都知道,Oracle的监听默认端口是1521,但是如果系统上1521已经被占用或业务要求不用默认端口,则需要修改监听的默认端口。修改监听端口只需要修改配置文件listiner.ora,然后重启监听
千家信息网最后更新 2025年01月21日修改Oracle默认监听端口

我们都知道,Oracle的监听默认端口是1521,但是如果系统上1521已经被占用或业务要求不用默认端口,则需要修改监听的默认端口。

修改监听端口只需要修改配置文件listiner.ora,然后重启监听就行了。但是Oracle实例的PMON进程还是会去找监听1521端口的监听进程去注册,所以同时也需要修改数据库的配置。数据库里只需要在线修改LOCAL_LISTINER即可。

下面以11.2.0.4为例测试修改监听端口:

1、修改监听端口

#查看监听状态[oracle@rhel6 ~]$ lsnrctl statusLSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:16:24Copyright (c) 1991, 2013, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))STATUS of the LISTENER------------------------Alias                     LISTENERVersion                   TNSLSNR for Linux: Version 11.2.0.4.0 - ProductionStart Date                07-JAN-2017 20:16:16Uptime                    0 days 0 hr. 0 min. 8 secTrace Level               offSecurity                  ON: Local OS AuthenticationSNMP                      OFFListener Parameter File   /u02/app/oracle/product/11.2.4/db1/network/admin/listener.oraListener Log File         /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xmlListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))Services Summary...Service "orcl" has 1 instance(s).  Instance "orcl", status READY, has 1 handler(s) for this service...The command completed successfully#停止监听[oracle@rhel6 ~]$ lsnrctl stopLSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:17:39Copyright (c) 1991, 2013, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))The command completed successfully#修改配置文件listener.ora,改监听端口为2521LISTENER=  (DESCRIPTION=    (ADDRESS_LIST=      (ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521))      (ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))#启动监听[oracle@rhel6 ~]$ lsnrctl startLSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:19:11Copyright (c) 1991, 2013, Oracle.  All rights reserved.Starting /u02/app/oracle/product/11.2.4/db1/bin/tnslsnr: please wait...TNSLSNR for Linux: Version 11.2.0.4.0 - ProductionSystem parameter file is /u02/app/oracle/product/11.2.4/db1/network/admin/listener.oraLog messages written to /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xmlListening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))STATUS of the LISTENER------------------------Alias                     LISTENERVersion                   TNSLSNR for Linux: Version 11.2.0.4.0 - ProductionStart Date                07-JAN-2017 20:19:11Uptime                    0 days 0 hr. 0 min. 0 secTrace Level               offSecurity                  ON: Local OS AuthenticationSNMP                      OFFListener Parameter File   /u02/app/oracle/product/11.2.4/db1/network/admin/listener.oraListener Log File         /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xmlListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))The listener supports no servicesThe command completed successfully

至此,监听端口已经修改完毕,这时Oracle实例是无法注册到此监听上的。

2、修改LOCAL_LISTINER参数

#修改参数sys@ORCL>alter system set local_listener="(address = (protocol = tcp)(host = rhel6)(port = 2521))";System altered.#查看监听状态[oracle@rhel6 ~]$ lsnrctl statusLSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:23:10Copyright (c) 1991, 2013, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))STATUS of the LISTENER------------------------Alias                     LISTENERVersion                   TNSLSNR for Linux: Version 11.2.0.4.0 - ProductionStart Date                07-JAN-2017 20:19:11Uptime                    0 days 0 hr. 3 min. 59 secTrace Level               offSecurity                  ON: Local OS AuthenticationSNMP                      OFFListener Parameter File   /u02/app/oracle/product/11.2.4/db1/network/admin/listener.oraListener Log File         /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xmlListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))Services Summary...Service "orcl" has 1 instance(s).  Instance "orcl", status READY, has 1 handler(s) for this service...The command completed successfully

修改完后,可以看到数据库实例立即注册到监听器上。

3、使用新端口进行测试连接

[c:\~]$ sqlplus zx/zx@192.168.56.2:2521/orclSQL*Plus: Release 12.1.0.1.0 Production on 星期六 1月 7 20:24:17 2017Copyright (c) 1982, 2013, Oracle.  All rights reserved.连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL>

修改监听端口完成。

4、把Oracle实例的注册端口改回1521

sys@ORCL>alter system set local_listener='';System altered.


官方文档中还提供了另一种配置LOCAL_LISTINER的方法:

在tnsnames.ora中添加配置,然后配置LOCAL_LISTINER为tnsnames.ora中的名字即可

#配置tnsnames.ora[oracle@rhel6 admin]$ vi tnsnames.ora listener1=(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.56.2 )(PORT = 2521))#修改LOCAL_LISTINER参数sys@ORCL>alter system set local_listener=listener1;System altered.#查看监听状态[oracle@rhel6 ~]$ lsnrctl statusLSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:34:01Copyright (c) 1991, 2013, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))STATUS of the LISTENER------------------------Alias                     LISTENERVersion                   TNSLSNR for Linux: Version 11.2.0.4.0 - ProductionStart Date                07-JAN-2017 20:31:28Uptime                    0 days 0 hr. 2 min. 33 secTrace Level               offSecurity                  ON: Local OS AuthenticationSNMP                      OFFListener Parameter File   /u02/app/oracle/product/11.2.4/db1/network/admin/listener.oraListener Log File         /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xmlListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))Services Summary...Service "orcl" has 1 instance(s).  Instance "orcl", status READY, has 1 handler(s) for this service...The command completed successfully


另外还可以使用静态监听的方法来修改监听的端口,但是Oracle实例不是"主动"注册到监听器上的。

sys@ORCL>show parameter local_listenerNAME                                 TYPE                             VALUE------------------------------------ --------------------------------- ------------------------------local_listener                       string#修改监听为静态监听[oracle@rhel6 admin]$ vi listener.oraLISTENER=  (DESCRIPTION=    (ADDRESS_LIST=      (ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521))      (ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))SID_LIST_LISTENER=  (SID_LIST=    (SID_DESC=      (GLOBAL_DBNAME=orcl)      (ORACLE_HOME=/u02/app/oracle/product/11.2.4/db1)      (SID_NAME=orcl))#重启监听[oracle@rhel6 ~]$ lsnrctl stopLSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:38:45Copyright (c) 1991, 2013, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))The command completed successfully[oracle@rhel6 ~]$ lsnrctl startLSNRCTL for Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:38:51Copyright (c) 1991, 2013, Oracle.  All rights reserved.Starting /u02/app/oracle/product/11.2.4/db1/bin/tnslsnr: please wait...TNSLSNR for Linux: Version 11.2.0.4.0 - ProductionSystem parameter file is /u02/app/oracle/product/11.2.4/db1/network/admin/listener.oraLog messages written to /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xmlListening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))STATUS of the LISTENER------------------------Alias                     LISTENERVersion                   TNSLSNR for Linux: Version 11.2.0.4.0 - ProductionStart Date                07-JAN-2017 20:38:52Uptime                    0 days 0 hr. 0 min. 0 secTrace Level               offSecurity                  ON: Local OS AuthenticationSNMP                      OFFListener Parameter File   /u02/app/oracle/product/11.2.4/db1/network/admin/listener.oraListener Log File         /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xmlListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))Services Summary...Service "orcl" has 1 instance(s).  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...The command completed successfully

静态监听实例的状态为UNKNOWN,测试连接成功

[c:\~]$ sqlplus zx/zx@192.168.56.2:2521/orclSQL*Plus: Release 12.1.0.1.0 Production on 星期六 1月 7 20:40:03 2017Copyright (c) 1982, 2013, Oracle.  All rights reserved.连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL>


官方文档:

http://docs.oracle.com/cd/E11882_01/network.112/e41945/listenercfg.htm#NETAG1154


监听 端口 配置 实例 状态 参数 数据 数据库 静态 测试 官方 文件 文档 方法 星期 监听器 进程 主动 成功 不用 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 前后端数据库同一台服务器 局域网服务器账号密码哪里查询 辽宁专业软件开发价格 珍橙网络技术有限公司招聘 服务器启动失败 当前主流的数据库都有哪些 单招网络技术考试题库 结构化的软件开发特点 数据库查询重复5次以上数据 南开学子获国家网络安全奖学金 衡水有容软件开发有限公司 数据库若要得到著作权法的保护 人社局网络安全管理方案 人工智能会取代软件开发吗 因为与服务器无法安全连接 网吧服务器不自动重启 服务器ip是干嘛的 交通银行软件开发有限公司 言语软件开发 网络安全维保方案规定 dnf架设用什么服务器好 网络安全在身边400字作文 ip差服务器地址 慕课网络技术与应用课后答案 全国气温数据库排名 软件开发项目总结1000字 网络安全防护领导机构 服务器工业级固态硬盘有多大 有关数据库的专业 在数据库中创建表的关键字是
0