如果在Oracle 11g RAC环境下使用dbca创建单实例数据库后,Oracle会自动将其注册到缺省的1521端口及监听器。大多数情况下我们使用的为非缺省监听器以及非缺省的监听端口。而且在Oracle 11g RAC环境中,对于集群监听器的配置由grid用户来接管了。基于这种情形的单实例非缺省监听及端口该如何配置呢?本文给出了解决方案,并且使用了静态及动态两种注册方法。
关于单实例下非缺省监听及端口的配置可以参考下面的文章。实际上参照下列文章依旧可以完成RAC 环境下单实例非缺省监听及端口的配置,但RAC环境下较之前的单实例环境有些不同,所以记录下了这些个细小的差异。
配置非默认端口的动态服务注册
配置sqlnet.ora限制IP访问Oracle
Oracle 监听器日志配置与管理
设置 Oracle 监听器密码(LISTENER)
配置Oracle 客户端连接到数据库
1、dbca创建单实例数据库后监听器的情形
--环境
[grid@linux1 ~]$ cat /etc/issue
Enterprise Linux Enterprise Linux Server release 5.5 (Carthage)
Kernel r on an m
[grid@linux1 ~]$ crsctl query crs activeversion
Oracle Clusterware active version on the cluster is [11.2.0.1.0]
--实例cnbo为RAC环境下使用dbca创建,当前处于offline状态
[oracle@linux1 ~]$ crsstat | grep cnbo
ora.cnbo.db database C OFFLINE OFFLINE (linux1) 0 Instance Shutdown
--缺省的listener处于offline状态
[oracle@linux1 ~]$ crsstat | grep Listener | grep OFFLINE
ora.LISTENER.lsnr Listener L OFFLINE OFFLINE (linux1) 0
--启动实例及监听
[oracle@linux1 ~]$ srvctl start database -d cnbo
[oracle@linux1 ~]$ srvctl start listener -l LISTENER
PRCC-1014 : LISTENER was already running
[oracle@linux1 ~]$ export ORACLE_SID=cnbo
[oracle@linux1 ~]$ sqlplus / as sysdba
SQL> set linesize 190
SQL> show parameter cluster_d --->此实例为RAC环境下的单实例
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
cluster_database boolean FALSE
cluster_database_instances integer 1
--下面的lsnrctl status可以看到实例被注册到1521的默认端口,dbca创建完实例cnbo后并没有为其配置监听
--而实例确确实实的被注册到了缺省的监听器,应该来说这个是dbca是自动添加的
--注:从Oracle 11g RAC开始,集群监听器的配置由grid用户来接管,因此可以在$ORA_CRS_HOME/network/admin/目录下找到对应的listener.ora文件
[grid@linux1 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-AUG-2013 12:35:43
.............
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.21)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.31)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "cnbo.orasrv.com" has 1 instance(s). --->该服务即是单实例cnbo提供的
Instance "cnbo", status READY, has 1 handler(s) for this service...
Service "cnboXDB.orasrv.com" has 1 instance(s).
Instance "cnbo", status READY, has 1 handler(s) for this service...
The command completed successfully
2、配置非缺省的监听器并实现动态注册
--切换到Oracle用户下,并清空其下的listener.ora与tnsnames.ora
[oracle@linux1 ~]$ cat /dev/null>$ORACLE_HOME/network/admin/listener.ora
[oracle@linux1 ~]$ cat /dev/null>$ORACLE_HOME/network/admin/tnsnames.ora
--下面通过netca来为其配置监听器及tnsnames.ora
[oracle@linux1 ~]$ export DISPLAY=192.168.7.133:0.0
[oracle@linux1 ~]$ netca
-- Author : Robinson Cheng
-- Blog : http://www.linuxidc.com
-->下面是使用netca配置后的结果,包括listener.ora以及tnsnames.ora
[oracle@linux1 ~]$ more $ORACLE_HOME/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
ADR_BASE_LISTENER_CNBO = /u01/app/oracle
LISTENER_CNBO = #--监听器的名字为LISTENER_CNBO,端口为1522
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.21)(PORT = 1522))
)
)
[oracle@linux1 ~]$ more $ORACLE_HOME/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
CNBO =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.21)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = cnbo.orasrv.com)
)
)
--提示没有找到监听器,无法ping通,因为我们配置的监听器并没有启动
--尽管服务在缺省的监听器注册,但无法ping,即此路不通
[oracle@linux1 ~]$ tnsping cnbo
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 16-AUG-2013 14:28:47
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.21)(PORT = 1522)))
(CONNECT_DATA = (SERVICE_NAME = cnbo.orasrv.com)))
TNS-12541: TNS:no listener
--下面我们启动非缺省的监听器
[oracle@linux1 ~]$ lsnrctl start LISTENER_CNBO
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-AUG-2013 14:29:14
..............
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=linux1.orasrv.com)(PORT=1522)))
The listener supports no services
The command completed successfully
[oracle@linux1 ~]$ lsnrctl status LISTENER_CNBO
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-AUG-2013 14:30:20
.............
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=linux1.orasrv.com)(PORT=1522)))
The listener supports no services -->没有任何服务及实例注册到监听器,等N久也不会有实例注册
The command completed successfully -->因为这个是非缺省的,而且我们还没有配置动态注册
--下面我们来设置动态注册
--查看参数local_listener,此时已经被设置了,而且端口是1521,IP用的是虚IP
--这就是为什么实例创建后,会被自动注册到grid用户下缺省监听器的缘故
SQL> show parameter local_lis
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
local_listener string (DESCRIPTION=(ADDRESS_LIST=(AD
DRESS=(PROTOCOL=TCP)(HOST=linu
x1-vip)(PORT=1521))))
--设置动态注册,收到了错误消息
SQL> alter system set local_listener='LISTENER_CNBO';
alter system set local_listener='LISTENER_CNBO'
*
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-00119: invalid specification for system parameter LOCAL_LISTENER
ORA-00132: syntax error or unresolved network name 'LISTENER_CNBO'
--对于前面出现的错误,给出两种解决方案,
--一是按照前面local_listener参数值的格式设置新的ip及端口,或者将这个描述信息添加到tnsnames.ora文件中
--下面我们选用了第二种解决方案
[oracle@linux1 ~]$ echo "
> LISTENER_CNBO =
> (ADDRESS_LIST =
> (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.21)(PORT = 1522))
> )">>$ORACLE_HOME/network/admin/tnsnames.ora
--再次设置参数local_listener
SQL> alter system set local_listener='LISTENER_CNBO';
System altered.
--下面可以看到实例及服务已经自动注册到监听器LISTENER_CNBO
[oracle@linux1 ~]$ lsnrctl status LISTENER_CNBO
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-AUG-2013 14:35:04
...................
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=linux1.orasrv.com)(PORT=1522)))
Services Summary...
Service "cnbo.orasrv.com" has 1 instance(s).
Instance "cnbo", status READY, has 1 handler(s) for this service...
Service "cnboXDB.orasrv.com" has 1 instance(s).
Instance "cnbo", status READY, has 1 handler(s) for this service...
The command completed successfully
--下面查看grid用户下原来的服务cnbo.orasrv.com及实例cnbo也不复存在
[grid@linux1 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 16-AUG-2013 14:37:46
.....
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.21)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.31)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
The command completed successfully