ORACLE RAC 监听配置 (listener.ora tnsnames.ora)

时间:2021-09-01 20:03:03

    Oracle RAC 监听器的配置与单实例稍有不同,但原理和实现方法基本上是相同的。在Oracle中 tns进程用于为指定网络地址上的一个或多个Oracle 实例提供服务注册,并响应来自客户端对该服务提出的连接请求。一旦连接请求到达,并派生出一个服务器进程建立服务器与用户端之间的连接(专有服务器dedicated server)或转发服务请求(共享服务器模式shared server)。如果监听器知道多于一个实例提供所请求的服务,则可能会根据客户端与服务器端相关配置将请求定位到较低负载的实例为其提供服务。因此合理正确配置监听器以及tnsnames是Oracle RAC实现负载均衡以及failover的前提,本文将描述基于 suse linux 10 + Oracle 10g RAC 下监听器的配置。

 

有关Oracle 网络配置相关基础请参考:
   配置ORACLE 客户端连接到数据库
   配置非默认端口的动态服务注册
   配置sqlnet.ora限制IP访问Oracle
   Oracle 监听器日志配置与管理
   设置 Oracle 监听器密码(LISTENER)

   配置RAC负载均衡与故障转移 
  
一、节点上监听信息

1、两个节点及主机配置信息(bo2dbp,bo2dbs)
oracle@bo2dbp:/u01/oracle/db/network/admin> cat /etc/hosts

127.0.0.1 localhost.2gotrade.com localhost
# Public
192.168.7.51 bo2dbp.2gotrade.com bo2dbp
192.168.7.52 bo2dbs.2gotrade.com bo2dbs
#Private
10.10.7.51 bo2dbp-priv.2gotrade.com bo2dbp-priv
10.10.7.52 bo2dbs-priv.2gotrade.com bo2dbs-priv
#Virtual
192.168.7.61 bo2dbp-vip.2gotrade.com bo2dbp-vip
192.168.7.62 bo2dbs-vip.2gotrade.com bo2dbs-vip

2、节点bo2dbp上的listener.ora
oracle@bo2dbp:/u01/oracle/db/network/admin> more listener.ora
# listener.ora.bo2dbp Network Configuration File: /u01/oracle/db/network/admin/listener.ora.bo2dbp
# Generated by Oracle configuration tools.

LISTENER_BO2DBP =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbp-vip.2gotrade.com)(PORT = 1521)(IP = FIRST))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.51)(PORT = 1521)(IP = FIRST))
)
)

SID_LIST_LISTENER_BO2DBP =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/oracle/db)
(PROGRAM = extproc)
)
)

3、节点bo2dbp上的tnsnames.ora
oracle@bo2dbp:/u01/oracle/db/network/admin> more tnsnames.ora
#对于连接字符串GOBO1A,GOBO1B,GOBO1在此处可以省略
#这些字符串通常用于客户端连接到数据库
GOBO1B =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.62)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = GOBO1)
(INSTANCE_NAME = GOBO1B)
)
)

GOBO1A =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.61)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = GOBO1)
(INSTANCE_NAME = GOBO1A)
)
)

GOBO1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.61)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.62)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = GOBO1)
)
)

#下面是几个重要的用于设置local_listener 以及remote_listener参数的定义信息
LISTENER_BO2DB =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.61)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.62)(PORT = 1521))
)

LISTENER_BO2DBP =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.61)(PORT = 1521))
)

LISTENER_BO2DBS =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.62)(PORT = 1521))
)
#Author: Robinson cheng
#Blog : http://blog.csdn.net/robinson_0612

4、节点bo2dbp上监听器的信息
#可以看出只有实例 GOBO1A 注册到监听器 LISTENER_BO2DBP
oracle@bo2dbp:/u01/oracle/db/network/admin> lsnrctl status LISTENER_BO2DBP

LSNRCTL for Linux: Version 10.2.0.3.0 - Production on 25-SEP-2012 17:12:04

Copyright (c) 1991, 2006, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bo2dbp-vip.2gotrade.com)(PORT=1521)(IP=FIRST)))
STATUS of the LISTENER
------------------------
..............
Listener Parameter File /u01/oracle/db/network/admin/listener.ora
Listener Log File /u01/oracle/db/network/log/listener_bo2dbp.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.61)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.51)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service...
Service "+ASM_XPT" has 1 instance(s).
Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service...
Service "GOBO1" has 1 instance(s).
Instance "GOBO1A", status READY, has 1 handler(s) for this service...
Service "GOBO1XDB" has 1 instance(s).
Instance "GOBO1A", status READY, has 1 handler(s) for this service...
Service "GOBO1_XPT" has 1 instance(s).
Instance "GOBO1A", 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...
The command completed successfully

5、节点bo2dbs上的listener.ora
oracle@bo2dbs:/u01/oracle/db/network/admin> more listener.ora
# listener.ora.bo2dbs Network Configuration File: /u01/oracle/db/network/admin/listener.ora.bo2dbs
# Generated by Oracle configuration tools.

LISTENER_BO2DBS =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbs-vip.2gotrade.com)(PORT = 1521)(IP = FIRST))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.52)(PORT = 1521)(IP = FIRST))
)
)

SID_LIST_LISTENER_BO2DBS =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/oracle/db)
(PROGRAM = extproc)
)
)
#由于节点bo2dbs上的tnsnames.ora与节点bo2dbp内容相同,不再列出

6、节点bo2dbs上的监听器状态
#同样可以看到只有一个 instance,即GOBO1B注册到了监听器 LISTENER_BO2DBS
oracle@bo2dbs:/u01/oracle/db/network/admin> lsnrctl status LISTENER_BO2DBS

LSNRCTL for Linux: Version 10.2.0.3.0 - Production on 25-SEP-2012 17:12:31

Copyright (c) 1991, 2006, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bo2dbs-vip.2gotrade.com)(PORT=1521)(IP=FIRST)))
STATUS of the LISTENER
------------------------
.......................
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.62)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.52)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM2", status BLOCKED, has 1 handler(s) for this service...
Service "+ASM_XPT" has 1 instance(s).
Instance "+ASM2", status BLOCKED, has 1 handler(s) for this service...
Service "GOBO1" has 1 instance(s).
Instance "GOBO1B", status READY, has 1 handler(s) for this service...
Service "GOBO1XDB" has 1 instance(s).
Instance "GOBO1B", status READY, has 1 handler(s) for this service...
Service "GOBO1_XPT" has 1 instance(s).
Instance "GOBO1B", 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...
The command completed successfully

#通过上面的观察可知,当前的两个实例都是在各自所在主机上的监听器进行了注册。


二、设置remote_listener参数

1、在节点bo2dbp上执行下列的命令SQL> show parameter instance_nameNAME                                 TYPE        VALUE------------------------------------ ----------- ------------------------------instance_name                        string      GOBO1A-->为节点bo2dbp设置远程监听器-->这意味着可以将实例GOBO1A上提供的服务可以注册到LISTENER_BO2DBS定义的监听器中SQL> alter system set remote_listener='LISTENER_BO2DBS' sid='GOBO1A';System altered.-->执行 register 实现注册SQL> alter system register;System altered.#再次查看节点bo2dbs监听器状态,实例GOBO1A已经注册到bo2dbs节点oracle@bo2dbs:/u01/oracle/db/network/admin> lsnrctl status LISTENER_BO2DBSLSNRCTL for Linux: Version 10.2.0.3.0 - Production on 25-SEP-2012 17:23:03Copyright (c) 1991, 2006, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bo2dbs-vip.2gotrade.com)(PORT=1521)(IP=FIRST)))STATUS of the LISTENER------------------------..............Listener Parameter File   /u01/oracle/db/network/admin/listener.oraListener Log File         /u01/oracle/db/network/log/listener_bo2dbs.logListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.62)(PORT=1521)))  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.52)(PORT=1521)))Services Summary...Service "+ASM" has 1 instance(s).  Instance "+ASM2", status BLOCKED, has 1 handler(s) for this service...Service "+ASM_XPT" has 1 instance(s).  Instance "+ASM2", status BLOCKED, has 1 handler(s) for this service...Service "GOBO1" has 2 instance(s).  Instance "GOBO1A", status READY, has 1 handler(s) for this service...  Instance "GOBO1B", status READY, has 1 handler(s) for this service...Service "GOBO1XDB" has 2 instance(s).  Instance "GOBO1A", status READY, has 1 handler(s) for this service...  Instance "GOBO1B", status READY, has 1 handler(s) for this service...Service "GOBO1_XPT" has 2 instance(s).  Instance "GOBO1A", status READY, has 1 handler(s) for this service...  Instance "GOBO1B", 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...The command completed successfully2、节点bo2dbs上设置local_listener,remote_listenerSQL> select instance_name from v$instance;INSTANCE_NAME----------------GOBO1BSQL> show parameter listenerNAME                                 TYPE        VALUE------------------------------------ ----------- ------------------------------local_listener                       stringremote_listener                      string-->按照节点bo2dbp上的操作方式将节点bo2dbs上的remote_listener只向节点bo2dbpSQL> alter system set remote_listener='LISTENER_BO2DBP' sid='GOBO1B';System altered.SQL> alter system register;System altered.-->在bo2dbp节点上也可以看到实例GOBO1B也注册到了第一个节点上oracle@bo2dbp:/u01/oracle/db/network/admin> lsnrctl status LISTENER_BO2DBPLSNRCTL for Linux: Version 10.2.0.3.0 - Production on 25-SEP-2012 17:32:19Copyright (c) 1991, 2006, Oracle.  All rights reserved.Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bo2dbp-vip.2gotrade.com)(PORT=1521)(IP=FIRST)))STATUS of the LISTENER------------------------............Listener Parameter File   /u01/oracle/db/network/admin/listener.oraListener Log File         /u01/oracle/db/network/log/listener_bo2dbp.logListening Endpoints Summary...  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.61)(PORT=1521)))  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.51)(PORT=1521)))Services Summary...Service "+ASM" has 1 instance(s).  Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service...Service "+ASM_XPT" has 1 instance(s).  Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service...Service "GOBO1" has 2 instance(s).  Instance "GOBO1A", status READY, has 1 handler(s) for this service...  Instance "GOBO1B", status READY, has 1 handler(s) for this service...Service "GOBO1XDB" has 2 instance(s).  Instance "GOBO1A", status READY, has 1 handler(s) for this service...  Instance "GOBO1B", status READY, has 1 handler(s) for this service...Service "GOBO1_XPT" has 2 instance(s).  Instance "GOBO1A", status READY, has 1 handler(s) for this service...  Instance "GOBO1B", 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...The command completed successfully


三、总结(缺省1521端口)
1、RAC 监听的配置当使用缺省的监听器时则监听器名字为 LISTENER_${NODE}
2、如未设置remote_listener,本地实例只在本地的监听器注册。而当设置了正确的remote_listener,则本地实例可以实现远程注册
3、缺省情况下,PMON进程自动将instance_name和service_names等信息注册到已启动的缺省侦听器
4、可以使用alter system register 实现快速注册

Important:

Do not set the GLOBAL_DBNAME parameter in the SID_LIST_listener_name section of the listener.ora.
A statically configured global database name disables connect-time failover.

 

四、更多参考

基于用管理的备份备份请参

    Oracle 冷备份

    Oracle 热备份

    Oracle 备份恢复概念

    Oracle 实例恢复

    Oracle 基于用户管理恢复的处理(详细描述了介及其)

    SYSTEM 表空间管理及备份恢复

    SYSAUX表空间管理及恢复

   Oracle 基于备份控制文件的恢复(unsing backup controlfile)

 

RMAN的备份复与管理请参

    RMAN 概述及其体系结构

    RMAN 配置、监控与管理

    RMAN 备份详解

    RMAN 还原与恢复

    RMAN catalog 的创建和使用

    基于catalog 创建RMAN存储脚本

    基于catalog 的RMAN 备份与恢复

    RMAN 备份困惑(使用plus archivelog)

 

ORACLE体系结构请参

    Oracle 表空间与数据文件

    Oracle 密码文件

    Oracle 参数文件

    Oracle 联机重做日志文件(ONLINE LOG FILE)

    Oracle 控制文件(CONTROLFILE)

    Oracle 归档日志

    Oracle 回滚(ROLLBACK)和撤销(UNDO)

    Oracle 数据库实例启动关闭过程

    Oracle 10g SGA 的自动化管理

    Oracle 实例和Oracle数据库(Oracle体系结构)