修改Oracle默认监听端口

前端之家收集整理的这篇文章主要介绍了修改Oracle默认监听端口前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

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

1、修改监听端口

#查看监听状态
[oracle@rhel6~]$lsnrctlstatus

LSNRCTLforLinux:Version11.2.0.4.0-Productionon07-JAN-201720:16:24

Copyright(c)1991,2013,Oracle.Allrightsreserved.

Connectingto(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
STATUSoftheLISTENER
------------------------
AliasLISTENER
VersionTNSLSNRforLinux:Version11.2.0.4.0-Production
StartDate07-JAN-201720:16:16
Uptime0days0hr.0min.8sec
TraceLeveloff
SecurityON:LocalOSAuthentication
SNMPOFF
ListenerParameterFile/u02/app/oracle/product/11.2.4/db1/network/admin/listener.ora
ListenerLogFile/u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xml
ListeningEndpointsSummary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))
ServicesSummary...
Service"orcl"has1instance(s).
Instance"orcl",statusREADY,has1handler(s)forthisservice...
Thecommandcompletedsuccessfully
#停止监听
[oracle@rhel6~]$lsnrctlstop

LSNRCTLforLinux:Version11.2.0.4.0-Productionon07-JAN-201720:17:39

Copyright(c)1991,Oracle.Allrightsreserved.

Connectingto(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Thecommandcompletedsuccessfully
#修改配置文件listener.ora,改监听端口为2521
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521))
(ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))
#启动监听
[oracle@rhel6~]$lsnrctlstart

LSNRCTLforLinux:Version11.2.0.4.0-Productionon07-JAN-201720:19:11

Copyright(c)1991,Oracle.Allrightsreserved.

Starting/u02/app/oracle/product/11.2.4/db1/bin/tnslsnr:pleasewait...

TNSLSNRforLinux:Version11.2.0.4.0-Production
Systemparameterfileis/u02/app/oracle/product/11.2.4/db1/network/admin/listener.ora
Logmessageswrittento/u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xml
Listeningon:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
Listeningon:(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))

Connectingto(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
STATUSoftheLISTENER
------------------------
AliasLISTENER
VersionTNSLSNRforLinux:Version11.2.0.4.0-Production
StartDate07-JAN-201720:19:11
Uptime0days0hr.0min.0sec
TraceLeveloff
SecurityON:LocalOSAuthentication
SNMPOFF
ListenerParameterFile/u02/app/oracle/product/11.2.4/db1/network/admin/listener.ora
ListenerLogFile/u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xml
ListeningEndpointsSummary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))
Thelistenersupportsnoservices
Thecommandcompletedsuccessfully

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

2、修改LOCAL_LISTINER参数

#修改参数
sys@ORCL>altersystemsetlocal_listener="(address=(protocol=tcp)(host=rhel6)(port=2521))";

Systemaltered.
#查看监听状态
[oracle@rhel6~]$lsnrctlstatus

LSNRCTLforLinux:Version11.2.0.4.0-Productionon07-JAN-201720:23:10

Copyright(c)1991,Oracle.Allrightsreserved.

Connectingto(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
STATUSoftheLISTENER
------------------------
AliasLISTENER
VersionTNSLSNRforLinux:Version11.2.0.4.0-Production
StartDate07-JAN-201720:19:11
Uptime0days0hr.3min.59sec
TraceLeveloff
SecurityON:LocalOSAuthentication
SNMPOFF
ListenerParameterFile/u02/app/oracle/product/11.2.4/db1/network/admin/listener.ora
ListenerLogFile/u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xml
ListeningEndpointsSummary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))
ServicesSummary...
Service"orcl"has1instance(s).
Instance"orcl",has1handler(s)forthisservice...
Thecommandcompletedsuccessfully

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

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

[c:\~]$sqlpluszx/zx@192.168.56.2:2521/orcl

sql*Plus:Release12.1.0.1.0Productionon星期六1月720:24:172017

Copyright(c)1982,Oracle.Allrightsreserved.


连接到:
OracleDatabase11gEnterpriseEditionRelease11.2.0.4.0-64bitProduction
WiththePartitioning,OLAP,DataMiningandRealApplicationTestingoptions

sql>

修改监听端口完成。

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

sys@ORCL>altersystemsetlocal_listener='';

Systemaltered.


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

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

#配置tnsnames.ora
[oracle@rhel6admin]$vitnsnames.ora
listener1=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.2)(PORT=2521))
#修改LOCAL_LISTINER参数
sys@ORCL>altersystemsetlocal_listener=listener1;

Systemaltered.
#查看监听状态
[oracle@rhel6~]$lsnrctlstatus

LSNRCTLforLinux:Version11.2.0.4.0-Productionon07-JAN-201720:34:01

Copyright(c)1991,Oracle.Allrightsreserved.

Connectingto(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
STATUSoftheLISTENER
------------------------
AliasLISTENER
VersionTNSLSNRforLinux:Version11.2.0.4.0-Production
StartDate07-JAN-201720:31:28
Uptime0days0hr.2min.33sec
TraceLeveloff
SecurityON:LocalOSAuthentication
SNMPOFF
ListenerParameterFile/u02/app/oracle/product/11.2.4/db1/network/admin/listener.ora
ListenerLogFile/u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xml
ListeningEndpointsSummary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))
ServicesSummary...
Service"orcl"has1instance(s).
Instance"orcl",has1handler(s)forthisservice...
Thecommandcompletedsuccessfully


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

sys@ORCL>showparameterlocal_listener

NAME				TYPE			VALUE
---------------------------------------------------------------------------------------------------
local_listener			string
#修改监听为静态监听
[oracle@rhel6admin]$vilistener.ora
LISTENER=
(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~]$lsnrctlstop

LSNRCTLforLinux:Version11.2.0.4.0-Productionon07-JAN-201720:38:45

Copyright(c)1991,Oracle.Allrightsreserved.

Connectingto(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
Thecommandcompletedsuccessfully
[oracle@rhel6~]$lsnrctlstart

LSNRCTLforLinux:Version11.2.0.4.0-Productionon07-JAN-201720:38:51

Copyright(c)1991,Oracle.Allrightsreserved.

Starting/u02/app/oracle/product/11.2.4/db1/bin/tnslsnr:pleasewait...

TNSLSNRforLinux:Version11.2.0.4.0-Production
Systemparameterfileis/u02/app/oracle/product/11.2.4/db1/network/admin/listener.ora
Logmessageswrittento/u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xml
Listeningon:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
Listeningon:(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))

Connectingto(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
STATUSoftheLISTENER
------------------------
AliasLISTENER
VersionTNSLSNRforLinux:Version11.2.0.4.0-Production
StartDate07-JAN-201720:38:52
Uptime0days0hr.0min.0sec
TraceLeveloff
SecurityON:LocalOSAuthentication
SNMPOFF
ListenerParameterFile/u02/app/oracle/product/11.2.4/db1/network/admin/listener.ora
ListenerLogFile/u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xml
ListeningEndpointsSummary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))
ServicesSummary...
Service"orcl"has1instance(s).
Instance"orcl",statusUNKNOWN,has1handler(s)forthisservice...
Thecommandcompletedsuccessfully

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

[c:\~]$sqlpluszx/zx@192.168.56.2:2521/orcl

sql*Plus:Release12.1.0.1.0Productionon星期六1月720:40:032017

Copyright(c)1982,DataMiningandRealApplicationTestingoptions

sql>


官方文档:

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

猜你在找的Oracle相关文章