非默认端口添加监听静态注册服务
网上一大堆博客说如何在RAC环境中添加非默认1521端口监听的,并且静态注册服务,眼花缭乱,而且好多不靠谱,最近工作当中要求为生产库上面的一套RAC添加监听,端口为1522,即非默认1521端口,并且使用静态注册服务到监听当中。
由于我在生产环境上添加监听了,并且使用pl/sql工具测试了是可以正常连接的,下面是自己虚拟机上面还原这个过程,其实和生产环境没多大区别。
11GR2版本的RAC,监听默认是在grid用户下面,监听启停管理都是以grid用户身份而不是使用oracle用户。
[grid@RAC1 admin]$ cd $ORACLE_HOME/network/admin --这个位置是监听配置文件的位置
[grid@RAC1 admin]$ pwd
/u01/app/11.2.0/grid/network/admin
[grid@RAC1 admin]$ ls
endpoints_listener.ora listener1809122PM5417.bak shrept.lst sqlnet.ora
endpoints_listener.ora.bak.rac1 listener.ora sqlnet1809121PM3806.bak tnsnames.ora
listener1809121PM3806.bak listener.ora.bak.rac1 sqlnet1809121PM5137.bak
listener1809121PM5137.bak samples sqlnet1809122PM5417.bak
[grid@RAC1 admin]$ cat listener.ora --下面红色和蓝色是我在监听文件当中添加的内容,其余的是默认监听自带的,虽然是虚拟机其实和生产环境没多大区别。
# listener.ora Network Configuration File: /u01/app/11.2.0/grid/network/admin/listener.ora
# Generated by Oracle configuration tools.
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_SCAN1 = ON
LISTENER =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER))
)
)
--这部分是添加的监听,监名可以随便取,但是下蓝色列表名不可以随便取,监听里面制定了节点1的VIP地址和端口号。(一般使用VIP,这样一节点宕机了,由于业务连接串配置failover机制,业务的连接会转移到2节点,因为一节点即故障节点VIP会转移到2节点,这样实现了高可用)
LISTENER_ORA=
(DESCRIPTION_LIST=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1522))
)
)
)
--这部分是服务名列表,要静态注册那些服务。SID_NAME是你想要静态注册的服务名,可以自己取名。
SID_LIST_LISTENER_ORA=
(SID_LIST=
(SID_DESC =
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = PLSExtProc)
)
)
这里要注意了:LISTENER_ORA监听名,SID_LIST_LISTENER_ORA是注册表,这里注册表的名字不能乱取名字,否者配置静态监听不会成功,会出现下面信息(The listener supports no services The command completed successfully),服务列表名字是:SID_LIST_加上监听名字,这样才正确的。
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER = ON
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER_TWO = ON
LISTENER_SCAN1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = LISTENER_SCAN1))
)
)
[grid@RAC1 admin]$ lsnrctl start LISTENER_ORA --上面修改了listener.ora里面的内容即添加监听和静态注册,将该监听启动。
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 14-SEP-2018 10:50:57
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Starting /u01/app/11.2.0/grid/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/11.2.0/grid/network/admin/listener.ora
Log messages written to /u01/app/grid/diag/tnslsnr/RAC1/listener_ora/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.11)(PORT=1522)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.11)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias LISTENER_ORA
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 14-SEP-2018 10:50:57
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/RAC1/listener_ora/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.11)(PORT=1522)))
Services Summary...
Service "oradb1" has 1 instance(s).
Instance "oradb1", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
可以看到新添加的1522端口非默认监听已经添加成功,并且服务oradb1静态注册了。
如果要静态注册多个服务在列表里面添加多个SID_DESC即可。
(SID_DESC =
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = oradb2)
)
SID_LIST_LISTENER_ORA =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = oradb1)
)
(SID_DESC =
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = oradb2)
)
)
[grid@RAC1 admin]$ lsnrctl start LISTENER_ORA
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 14-SEP-2018 10:58:25
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Starting /u01/app/11.2.0/grid/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/11.2.0/grid/network/admin/listener.ora
Log messages written to /u01/app/grid/diag/tnslsnr/RAC1/listener_ora/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.11)(PORT=1522)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.11)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias LISTENER_ORA
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 14-SEP-2018 10:58:25
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/RAC1/listener_ora/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.11)(PORT=1522)))
Services Summary...
Service "oradb1" has 1 instance(s).
Instance "oradb1", status UNKNOWN, has 1 handler(s) for this service...
Service "oradb2" has 1 instance(s).
Instance "oradb2", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
可以看到多个服务都注册到了1522端口上面的监听上了。到此如何添加非1521默认端口以及如何静态注册多个服务也成功完成,注意这只是在第一个节点添加的监听,第二个节点按照上面照葫芦画瓢即可。
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.4.41)(PORT = 1521)(IP = FIRST))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.4.40)(PORT = 1521)(IP = FIRST))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /home/u01/app/11.2.0/grid)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = +ASM)
(SID_NAME = +ASM2)
(ORACLE_HOME = /home/u01/app/11.2.0/grid)
)
)