Oracle 19c 修改监听端口
作者 | JiekeXu
来源 |公众号 JiekeXu DBA之路(ID: JiekeXu_IT)
如需转载请联系授权 | (个人微信 ID:JiekeXu_DBA)
大家好,我是 JiekeXu,很高兴又和大家见面了,今天和大家一起来学习 Oracle 19c 修改监听端口,欢迎点击上方蓝字“JiekeXu DBA之路”关注我的公众号,标星或置顶,更多干货第一时间到达!
有些时候,由于数据库安装较早规划不合理直接使用了默认的数据库端口号,出于安全考虑,不管是服务器还是各种数据库尽量少用默认端口,默认账号密码等,近期就遇到了这样的要求,由于一套
Oracle 19c RAC 数据库安装使用了默认的端口号 1521 ,这里需要将其修改为 11521,下面一起来看看仅修改端口号该如何操作。
目 录
一、RAC 环境说明
1.查看当前的监听配置
2.修改端口
3.修改 SCAN 端口号
4.监听检查状态
5.检查 asm 参数
6.如若有数据库检查数据库参数
7.修改 tnsnames.ora 配置文件
二、修改 asm 网络端口(可选)
1.查看端口
2.修改端口
3.如有必要重新启动(不需要)
三、单机环境修改监听端口
1.检查监听状态
2.修改监听配置文件
3.修改 tnsnames 配置文件
4.进入数据库修改监听参数
5.检查监听状态
一、RAC 环境说明
DB:19.15.0.0 两节点 RAC
OS:RHEL7/Centos 7
hosts 文件 IP 映射关系如下。
$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.75.71 rac01
192.168.75.72 rac02
10.10.10.71 rac01-priv
10.10.10.72 rac02-priv
192.168.75.73 rac01-vip
192.168.75.74 rac02-vip
192.168.75.75 rac-cls-scan
注意:安装一套 RAC 至少需要 7 个 IP 两块网卡,公网、私网各一块,且网络地址不能在同一地址段。另外,SCAN 监听端口可以和 VIP 监听端口相同也可以不同,这里统一将其修改为 11521;还有一点要说明的是应用系统网络访问关系这块,如果某个应用要通过 SCAN IP 访问 RAC DB,但是在开通网络访问关系时除了开通 SCAN IP 端口外,还需要开通各个 VIP 监听端口,主要是因为 SCAN IP 是把连接请求发送转发给 local listener,所以后续应用和 local listener 之间通讯的过程,需要通过 VIP 来访问故也需要开通 VIP 监听端口,连接建立完成后,和 SCAN IP 就没有关系了,数据交互通过 VIP 监听端口来进行。可以把 SCAN 监听和 SCAN 停止后,已有连接可以继续正常操作数据库,新的连接无法通过 SCAN 监听连接。
1.查看当前的监听配置
在其中一个节点上执行,我这里是在节点 1 上执行。
[grid@rac01 ~]$ srvctl config listener -l listener
Name: LISTENER
Type: Database Listener
Network: 1, Owner: grid
Home: <CRS home>
End points: TCP:1521
Listener is enabled.
Listener is individually enabled on nodes:
Listener is individually disabled on nodes:
2.修改端口
仅在其中一个节点上执行,我这里是在节点 1 上执行。
[grid@rac01 ]$ srvctl modify listener -l LISTENER -p "TCP:11521"
[grid@rac01 ]$ srvctl config listener -l listener
Name: LISTENER
Type: Database Listener
Network: 1, Owner: grid
Home: <CRS home>
End points: TCP:11521
Listener is enabled.
Listener is individually enabled on nodes:
Listener is individually disabled on nodes:
3.修改 SCAN 端口号
仅在其中一个节点上执行,我这里是在节点 1 上执行。
[grid@rac01 ]$ lsnrctl status LISTENER_SCAN1
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 13-SEP-2022 14:49:30
Copyright (c) 1991, 2022, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))
STATUS of the LISTENER
------------------------
Alias LISTENER_SCAN1
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 20-JUN-2022 11:33:46
Uptime 85 days 3 hr. 15 min. 44 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/19.0.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/rac01/listener_scan1/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.75.75)(PORT=1522)))
----修改 SCAN 监听端口号为 11521
[grid@rac01 ]$ srvctl modify scan_listener -p 11521
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 13-SEP-2022 14:59:38
Copyright (c) 1991, 2022, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))
STATUS of the LISTENER
------------------------
Alias LISTENER_SCAN1
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 20-JUN-2022 11:33:46
Uptime 85 days 3 hr. 25 min. 52 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/19.0.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/rac01/listener_scan1/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.75.75)(PORT=11521)
[grid@rac01 ]$ lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 13-SEP-2022 15:06:00
Copyright (c) 1991, 2022, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 20-JUN-2022 11:33:45
Uptime 85 days 3 hr. 32 min. 14 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/19.0.0/grid/network/admin/listener.ora
Listener Log File /u01/app/19.0.0/grid/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.75.71)(PORT=11521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.75.73)(PORT=11521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_ARCH" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_DATA" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_OCR" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "SYS$SYS.SCHEDULER$_EVENT_QUEUE.Jiekedb" has 1 instance(s).
Instance "Jiekedb1", status READY, has 1 handler(s) for this service...
Service "Jiekedb" has 2 instance(s).
Instance "Jiekedb1", status UNKNOWN, has 1 handler(s) for this service...
Instance "Jiekedb1", status READY, has 1 handler(s) for this service...
Service "JiekedbXDB" has 1 instance(s).
Instance "Jiekedb1", status READY, has 1 handler(s) for this service...
The command completed successfully
检查发现监听已经正常启动,端口号也改变为正确的端口,无需单独重启。
如有需要重启动监听,(正常情况下不需要重启,数据库会自动应用新的端口)
仅在节点 1 上执行。
[grid@rac01 ]$ srvctl stop listener -l listener
[grid@rac01 ]$ srvctl stop scan_listener
[grid@rac01 ]$ srvctl start listener -l listener
[grid@rac01 ]$ srvctl start scan_listener
4.监听检查状态
在 scan 所在的节点执行
[grid@rac02 ~]$ lsnrctl status LISTENER_SCAN1
节点 1 和节点 2 都检查执行
[grid@rac02 ~]$ lsnrctl status
5.检查 asm 参数
系统自动检查,自动修改的,一般情况下无需手动修改。
节点 1:
su - grid
sqlplus / as sysasm
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Sep 13 15:24:45 2022
Version 19.15.0.0.0
Copyright (c) 1982, 2022, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.15.0.0.0
SQL> set linesize 1000;
SQL> show parameters local_listener
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
local_listener string (ADDRESS=(PROTOCOL=TCP)(HOST=192.168.75.73)(PORT=11521))
--节点 2:
SQL> show parameters local_listener;
NAME TYPE VALUE
------------------------------------ ---------------------- ------------------------------
local_listener string (ADDRESS=(PROTOCOL=TCP)(HOST=192.168.75.74)(PORT=11521))
数据库自动会应用新的端口,无需修改。
SQL> show parameters listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
forward_listener string
listener_networks string
local_listener string (ADDRESS=(PROTOCOL=TCP)(HOST=192.168.75.74)(PORT=11521))
remote_listener string rac-cls-scan:11521
alter system set remote_listener='rac-cls-scan:11521' scope=both;
修改 LOCAL_LISTENER 仅仅在一个主机上执行。
alter system set local_listener = '(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.74.73)(PORT = 11521))' scope=both sid='Jiekedb1';
alter system set local_listener = '(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.75.74)(PORT = 11521))' scope=both sid='Jiekedb2';
记得修改各个客户端以及 tnsnames.ora 配置文件中监听端口的配置。
vim /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/tnsnames.ora
二、修改 asm 网络端口(可选)
1.查看端口
在其中一个节点上执行,我这里是在节点 1 上执行。
[grid@rac01 ]$ srvctl config listener -listener ASMNET1LSNR_ASM
Name: ASMNET1LSNR_ASM
Type: ASM Listener
Owner: grid
Subnet: 10.10.10.0
Home: <CRS home>
End points: TCP:1525
Listener is enabled.
Listener is individually enabled on nodes:
Listener is individually disabled on nodes:
2.修改端口
grid 用户在其中一个节点上执行,我这里是在节点 1 上执行。
[grid@rac01 ]$ ss -nlp|grep 1525
tcp LISTEN 0 128 192.168.10.71:1525 *:* users:(("tnslsnr",pid=23479,fd=14))
[grid@rac01 ]$ srvctl modify listener -l ASMNET1LSNR_ASM -endpoints "TCP:11526"
修改完成后系统自动修改端口号,不需要下面的重启步骤。
[grid@rac01 ]$ ss -nlp|grep 11526
tcp LISTEN 0 128 192.168.10.71:11526 *:* users:(("tnslsnr",pid=23479,fd=15))
[grid@rac02 ~]$ ss -nlp|grep 11526
tcp LISTEN 0 128 192.168.10.72:11526 *:* users:(("tnslsnr",pid=24999,fd=15))
srvctl start listener -l ASMNET1LSNR_ASM
[grid@rac01 ]$ srvctl config listener -listener ASMNET1LSNR_ASM
Name: ASMNET1LSNR_ASM
Type: ASM Listener
Owner: grid
Subnet: 10.10.10.0
Home: <CRS home>
End points: TCP:11526
Listener is enabled.
Listener is individually enabled on nodes:
Listener is individually disabled on nodes:
三、单机环境修改监听端口
1.检查监听状态
lsnrctl status
more $ORACLE_HOME/network/admin/listener.ora
2.修改监听配置文件
vi /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle19c)(PORT = 11521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC11521))
)
)
DIAG_ADR_ENABLED_LISTENER = OFF
SAVE_CONFIG_ON_STOP_LISTENER = ON
3.修改 tnsnames 配置文件
添加以下行,“LISTENER_TEST” 代指等号右边的连接串
LISTENER_TEST =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle19c)(PORT = 11521))
4.进入数据库修改监听参数
sqlplus / as sysdba
show parameter local_listener
alter system set local_listener='LISTENER_TEST' scope=both sid-'*';
Alter system register;
5.检查监听状态
lsnrctl status
全文完,希望可以帮到正在阅读的你,如果觉得有帮助,可以分享给你身边的朋友,同事,你关心谁就分享给谁,一起学习共同进步~~~
❤️ 欢迎关注我的公众号【JiekeXu DBA之路】,一起学习新知识!
————————————————————————————
公众号:JiekeXu DBA之路
CSDN :https://blog.csdn.net/JiekeXu
墨天轮:https://www.modb.pro/u/4347
腾讯云:https://cloud.tencent.com/developer/user/5645107
————————————————————————————