修改Oracle默认监听端口

简介:

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

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

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

1、修改监听端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#查看监听状态
[oracle@rhel6 ~]$ lsnrctl status
 
LSNRCTL  for  Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:16:24
 
Copyright (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                     LISTENER
Version                   TNSLSNR  for  Linux: Version 11.2.0.4.0 - Production
Start Date                07-JAN-2017 20:16:16
Uptime                    0 days 0 hr. 0 min. 8 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File    /u02/app/oracle/product/11 .2.4 /db1/network/admin/listener .ora
Listener Log File          /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log .xml
Listening 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 stop
 
LSNRCTL  for  Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:17:39
 
Copyright (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,改监听端口为2521
LISTENER=
   (DESCRIPTION=
     (ADDRESS_LIST=
       (ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521))
       (ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))
#启动监听
[oracle@rhel6 ~]$ lsnrctl start
 
LSNRCTL  for  Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:19:11
 
Copyright (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 - Production
System parameter  file  is  /u02/app/oracle/product/11 .2.4 /db1/network/admin/listener .ora
Log messages written to  /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log .xml
Listening 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                     LISTENER
Version                   TNSLSNR  for  Linux: Version 11.2.0.4.0 - Production
Start Date                07-JAN-2017 20:19:11
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File    /u02/app/oracle/product/11 .2.4 /db1/network/admin/listener .ora
Listener Log File          /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log .xml
Listening Endpoints Summary...
   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=2521)))
   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))
The listener supports no services
The  command  completed successfully

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

2、修改LOCAL_LISTINER参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#修改参数
sys@ORCL> alter  system  set  local_listener= "(address = (protocol = tcp)(host = rhel6)(port = 2521))" ;
 
System altered.
#查看监听状态
[oracle@rhel6 ~]$ lsnrctl status
 
LSNRCTL  for  Linux: Version 11.2.0.4.0 - Production  on  07-JAN-2017 20:23:10
 
Copyright (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                     LISTENER
Version                   TNSLSNR  for  Linux: Version 11.2.0.4.0 - Production
Start  Date                 07-JAN-2017 20:19:11
Uptime                    0 days 0 hr. 3  min . 59 sec
Trace  Level                off
Security                   ON Local  OS Authentication
SNMP                       OFF
Listener Parameter File   /u02/app/oracle/product/11.2.4/db1/network/admin/listener.ora
Listener Log File         /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log.xml
Listening 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、使用新端口进行测试连接

1
2
3
4
5
6
7
8
9
10
11
12
[c:\~]$ sqlplus zx /zx @192.168.56.2:2521 /orcl
 
SQL*Plus: Release 12.1.0.1.0 Production on 星期六 1月 7 20:24:17 2017
 
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
 
 
连接到: 
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL>

修改监听端口完成。

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

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


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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#配置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 status
 
LSNRCTL  for  Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:34:01
 
Copyright (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                     LISTENER
Version                   TNSLSNR  for  Linux: Version 11.2.0.4.0 - Production
Start Date                07-JAN-2017 20:31:28
Uptime                    0 days 0 hr. 2 min. 33 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File    /u02/app/oracle/product/11 .2.4 /db1/network/admin/listener .ora
Listener Log File          /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log .xml
Listening 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实例不是“主动”注册到监听器上的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
sys@ORCL>show parameter local_listener
 
NAME                     TYPE                 VALUE
------------------------------------ --------------------------------- ------------------------------
local_listener               string
#修改监听为静态监听
[oracle@rhel6 admin]$  vi  listener.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 ~]$ lsnrctl stop
 
LSNRCTL  for  Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:38:45
 
Copyright (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 start
 
LSNRCTL  for  Linux: Version 11.2.0.4.0 - Production on 07-JAN-2017 20:38:51
 
Copyright (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 - Production
System parameter  file  is  /u02/app/oracle/product/11 .2.4 /db1/network/admin/listener .ora
Log messages written to  /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log .xml
Listening 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                     LISTENER
Version                   TNSLSNR  for  Linux: Version 11.2.0.4.0 - Production
Start Date                07-JAN-2017 20:38:52
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File    /u02/app/oracle/product/11 .2.4 /db1/network/admin/listener .ora
Listener Log File          /u02/app/oracle/diag/tnslsnr/rhel6/listener/alert/log .xml
Listening 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,测试连接成功

1
2
3
4
5
6
7
8
9
10
11
12
[c:\~]$ sqlplus zx /zx @192.168.56.2:2521 /orcl
 
SQL*Plus: Release 12.1.0.1.0 Production on 星期六 1月 7 20:40:03 2017
 
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
 
 
连接到: 
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
 
SQL>


官方文档:

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






     本文转自hbxztc 51CTO博客,原文链接:http://blog.51cto.com/hbxztc/1890055,如需转载请自行联系原作者


相关文章
|
网络协议 Linux
Linux查看端口监听情况,以及Linux查看某个端口对应的进程号和程序
Linux查看端口监听情况,以及Linux查看某个端口对应的进程号和程序
1354 2
|
10月前
|
网络协议 Unix 应用服务中间件
|
人工智能 Serverless API
函数计算产品使用问题之如何在一个Docker容器内运行一个持续监听特定端口的应用程序
函数计算产品作为一种事件驱动的全托管计算服务,让用户能够专注于业务逻辑的编写,而无需关心底层服务器的管理与运维。你可以有效地利用函数计算产品来支撑各类应用场景,从简单的数据处理到复杂的业务逻辑,实现快速、高效、低成本的云上部署与运维。以下是一些关于使用函数计算产品的合集和要点,帮助你更好地理解和应用这一服务。
193 1
|
Java Android开发
Java Socket编程示例:服务器开启在8080端口监听,接收客户端连接并打印消息。
【6月更文挑战第23天】 Java Socket编程示例:服务器开启在8080端口监听,接收客户端连接并打印消息。客户端连接服务器,发送"Hello, Server!"后关闭。注意Android中需避免主线程进行网络操作。
308 4
|
开发框架 .NET Linux
【Azure 应用服务】 部署到App Service for Linux 服务的Docker 镜像,如何配置监听端口呢?
【Azure 应用服务】 部署到App Service for Linux 服务的Docker 镜像,如何配置监听端口呢?
200 0
|
网络协议
【qt】TCP的监听 (设置服务器IP地址和端口号)
【qt】TCP的监听 (设置服务器IP地址和端口号)
804 0
|
Linux Windows
Windows查找监听端口对应的进程及其路径
Windows查找监听端口对应的进程及其路径
372 0
|
3月前
|
Oracle 关系型数据库 Linux
【赵渝强老师】Oracle数据库配置助手:DBCA
Oracle数据库配置助手(DBCA)是用于创建和配置Oracle数据库的工具,支持图形界面和静默执行模式。本文介绍了使用DBCA在Linux环境下创建数据库的完整步骤,包括选择数据库操作类型、配置存储与网络选项、设置管理密码等,并提供了界面截图与视频讲解,帮助用户快速掌握数据库创建流程。
365 93
|
2月前
|
Oracle 关系型数据库 Linux
【赵渝强老师】使用NetManager创建Oracle数据库的监听器
Oracle NetManager是数据库网络配置工具,用于创建监听器、配置服务命名与网络连接,支持多数据库共享监听,确保客户端与服务器通信顺畅。
204 0
|
5月前
|
存储 Oracle 关系型数据库
服务器数据恢复—光纤存储上oracle数据库数据恢复案例
一台光纤服务器存储上有16块FC硬盘,上层部署了Oracle数据库。服务器存储前面板2个硬盘指示灯显示异常,存储映射到linux操作系统上的卷挂载不上,业务中断。 通过storage manager查看存储状态,发现逻辑卷状态失败。再查看物理磁盘状态,发现其中一块盘报告“警告”,硬盘指示灯显示异常的2块盘报告“失败”。 将当前存储的完整日志状态备份下来,解析备份出来的存储日志并获得了关于逻辑卷结构的部分信息。